Namespaces
Variants

std::basic_string<CharT,Traits,Allocator>:: assign_range

From cppreference.net
std::basic_string
template < container-compatible-range < CharT > R >
constexpr std:: basic_string & assign_range ( R && rg ) ;
(C++23부터)

문자열의 내용을 범위 rg 에 있는 값들로 대체합니다.

다음과 동일함

return assign(
    std::basic_string(
        std::from_range,
        std​::​forward<R>(rg),
        get_allocator())
);

목차

매개변수

rg - a container compatible range

반환값

* this

복잡도

크기에 선형적으로 비례하는 rg .

예외

만약 연산으로 인해 size() max_size() 를 초과하게 되면, std::length_error 를 발생시킵니다.

어떤 이유로든 예외가 발생하면, 이 함수는 아무런 효과를 가지지 않습니다( strong exception safety guarantee ).

참고 사항

기능 테스트 매크로 표준 기능
__cpp_lib_containers_ranges 202202L (C++23) 컨테이너 호환 범위 를 허용하는 멤버 함수

예제

#include <cassert>
#include <string>
int main()
{
    const auto source = {'s', 'o', 'u', 'r', 'c', 'e'};
    std::string destination{"destination"};
#ifdef __cpp_lib_containers_ranges
    destination.assign_range(source);
#else
    destination.assign(source.begin(), source.end());
#endif
    assert(destination == "source");
}

참고 항목

문자열에 문자들을 할당
(public member function)
문자열에 값을 할당
(public member function)
basic_string 을 생성
(public member function)