conversion의 설계 개념
C++의 conversion를 정의할 때, 직교하는 3 요소, value category
, cv-qualification
, data representation
를 설계 개념으로 사용한다. conversion를 설계할 때, 요소 중 하나만을 변형하고, 다른 요소를 변형하지 않는다. 어떤 이유로, 예를 들어 하위 호환성을 위해, 설계 개념을 위반할 때는 스펙 문서는 관련된 특수 조항을 별도로 명시한다.
temporary materialization conversion
value category
요소를 변형하기 위해 설계한 conversion이다. value category
요소만 변경하기 때문에, exact match rank
로 분류해야 하지만, 최근에 추가된 conversion이고, standard conversion sequence에도 포함되지 않은 관계로 별도로 명시한 match rank는 없다. 스펙 문서에서는 필요한 위치마다 별도 조항을 추가하고 있으며, C++23 이후 미묘하게 확장되고 있는 conversion이다.
타입 T의 prvalue category
에서 타입 T의 xvalue category
로 변환한다. 타입 T가 complete type일 때, temporary materialization conversion
를 적용할 수 있다. class 또는 array 타입 T는 accessible하고 non-deleted destructor를 갖고 있을 때, temporary materialization conversion
를 적용할 수 있다
conversion expression의 side effect로 타입 T의 temporary object
가 만들고, conversion expression의 value는 xvalue category
를 갖는다.
struct X { int n; };
int k = X().n; // OK, X() prvalue is converted to xvalue
[[코딩 분석]]X()
를 해석할 시점에 prvalue category
다. n
멤버 변수를 얻어내기 위해서, X()
의 prvalue category
에서 xvalue category
로 변환을 수행하고, 이렇게 만들어진 객체로부터 n
를 얻어낸다. X().n
expression의 value는 xvalue category
를 갖는다.int k
로 할당 연산 과정에서,결과 expression에 glvalue-to-prvalue conversion
를 적용한 prvalue category
로 변환된 후 초기화에 사용된다.
'프로그래밍 언어 > C++' 카테고리의 다른 글
floating-point promotion conversion에 대해 (0) | 2024.02.28 |
---|---|
integral promotion conversion에 대해 (0) | 2024.02.26 |
function-to-pointer conversion에 대해 (1) | 2024.02.24 |
array-to-pointer conversion에 대해 (0) | 2024.02.24 |
glvalue-to-prvalue conversion에 대해 (0) | 2024.02.23 |