Namespaces
Variants

std::meta::size_of

cppreference.net에서
< cpp | meta
 
 
 
리플렉션 라이브러리
 
리플렉션 타입 및 쿼리
리플렉션 쿼리
리플렉션 레이아웃 쿼리
타입 속성
타입 속성 쿼리
 
헤더 <meta>
consteval std::size_t size_of( std::meta::info r );
에 정의됨 (C++26부터)

r이 나타내는 타입 또는 (하위)객체의 크기를 반환합니다.

매개변수

r - 리플렉션 값

반환값

r이 “T에 대한 참조” 타입을 나타내면 sizeof(T*)을 반환합니다.

그렇지 않고, r이 타입 U을 나타내면 sizeof(U)를 반환합니다.

그렇지 않으면 std::meta::size_of(std::meta::type_of(r))와 동일합니다.

예외

다음 조건이 모두 충족되지 않으면 std::meta::exception을 던집니다.

  • std::meta::dealias(r)
  • std::meta::dealias(r)이 타입을 나타내면 std::meta::is_complete_type(r)은(는) true입니다.

참고 사항

이 함수는 “T의 참조”를 “T에 대한 포인터”와 동일하게 취급합니다. 이는 비정적 참조 멤버의 표현과 일치합니다.

r이 직접 기본 클래스 관계를 나타내더라도 빈 기본 클래스의 결과는 0이 아닙니다.

예제

#include <meta>

static_assert(std::meta::size_of(^^int) == sizeof(int));
static_assert(std::meta::size_of(^^int*) == sizeof(int*));

consteval bool test()
{
    struct A; 
    // constexpr auto _ = std::meta::size_of(^^A);
        // error: uncaught exception of type 'std::meta::exception';
        // 'what()': 'reflection with incomplete type in size_of'
    return true;
}
static_assert(test());

struct B { int i, j; };
static_assert(sizeof(B) == std::meta::size_of(^^B));

template<class T>
struct C { T m; };
static_assert(size_of(^^C<char>) == sizeof(char));

struct D { int x : 015; };
static_assert(size_of(^^D) == sizeof(int));

// static_assert(size_of(^^D::x) == sizeof(int));
    // error: uncaught exception of type 'std::meta::exception';
    // 'what()': 'reflection not suitable for size_of'

int main() {}

참조

리플렉션된 객체 또는 타입의 정렬을 반환합니다
(함수)
리플렉션된 객체 또는 타입의 비트 크기를 반환합니다
(함수)