Namespaces
Variants

std::meta::bit_size_of

From cppreference.com
< cpp | meta
 
 
 
Reflection library
 
Reflection types and queries
Reflection queries
Reflection layout queries
Type properties
Type property queries
 
Defined in header <meta>
consteval std::size_t bit_size_of( std::meta::info r );
(since C++26)

Returns the size in bits of the type or (sub)object represented by r.

Parameters

r - a reflection value

Return value

If r represents a bit-field, returns its bit width.

Otherwise, if r represents a data member description whose bit width is not ⊥, returns that bit width.

Otherwise, returns CHAR_BIT * std::meta::size_of(r).

Exceptions

Throws std::meta::exception unless all of the following conditions are met:

  • std::meta::dealias(r) represents one of the following:
  • If std::meta::dealias(r) represents a type, std::meta::is_complete_type(r) is true.

Example

#include <climits>
#include <cstdint>
#include <meta>

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

int main()
{
    constexpr struct S { std::uint32_t m{}; } o;
    static_assert(std::meta::bit_size_of(^^S) == 32);
    static_assert(std::meta::bit_size_of(^^o) == 32);

    struct B { std::uint64_t m : 42{}; };
    static_assert(std::meta::bit_size_of(^^B) == 64);
    static_assert(std::meta::bit_size_of(^^B::m) == 42);
}

See also

returns the alignment of the reflected object or type
(function) [edit]
(C++26)
returns the size in bytes of the reflected object or type
(function) [edit]