-
Notifications
You must be signed in to change notification settings - Fork 12
4.1 Utility: struct_cast & tuple_cast
DK edited this page Sep 20, 2023
·
2 revisions
compile time conversion for same aligned struct/tuple
struct AggregateType
{
int i;
std::string s;
char c;
bool b;
};
auto tv = dku::model::tuple_cast(AggregateType{});
static_assert(std::is_same_v<decltype(tv), std::tuple<int, std::string, char, bool>>);
auto sv = dku::model::struct_cast<AggregateType>(tv);
static_assert(std::is_same_v<decltype(sv), AggregateType>);
get compile time count of struct members, size of tuple, size of trivial/standard layout/pod types.
static_assert(dku::model::number_of_bindables<AggregateType>() == 4);
static_assert(dku::model::number_of_bindables<decltype(tv)>() == 4);
static_assert(dku::model::number_of_bindables<decltype(av)>() == 4);