std::meta::bit_size_of
From cppreference.com
| 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:
- type
- object
- (scalar) value
- variable of non-reference type
- non-static data member
- unnamed bit-field
- direct base class relationship
- data member description
- If
std::meta::dealias(r)represents a type,std::meta::is_complete_type(r)istrue.
Example
Run this code
#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
(C++26) |
returns the alignment of the reflected object or type (function) |
(C++26) |
returns the size in bytes of the reflected object or type (function) |