std::indirectly_writable
std::indirectly_writable (간접 쓰기 가능 컨셉)
타입·값 카테고리가 T로 인코딩된 값을 반복자 Out이 참조하는 객체에 쓸 수 있다는 요구사항을 명세하는 컨셉이에요. C++20부터 있어요.
출처: cppreference
본문
<iterator> 헤더에 정의돼 있어요.
template< class Out, class T >
concept indirectly_writable =
requires(Out&& o, T&& t) {
*o = std::forward<T>(t);
*std::forward<Out>(o) = std::forward<T>(t);
const_cast<const std::iter_reference_t<Out>&&>(*o) = std::forward<T>(t);
const_cast<const std::iter_reference_t<Out>&&>(*std::forward<Out>(o)) =
std::forward<T>(t);
};
/* 위 네 표현식 중 어느 것도 동등성 보존이 요구되진 않음 */
indirectly_writable<Out, T> 컨셉은 타입·값 카테고리가 T로 인코딩된 값을 반복자 Out이 참조하는 객체에 쓰기 위한 요구사항을 명세해요.
의미 요구사항
decltype((e))가 T인 표현식 e와 역참조 가능한 Out 타입 객체 o가 있을 때, indirectly_writable이 성립한다는 것은 위 대입 표현식들이 잘 형성됨을 의미해요. 출력 반복자와 파괴적 대입(destructive assignment)을 지원해요.
예제
#include <iterator>
#include <vector>
#include <concepts>
int main()
{
static_assert(std::indirectly_writable<std::vector<int>::iterator, int>);
static_assert(std::indirectly_writable<int*, int&>);
}