strong_type icon indicating copy to clipboard operation
strong_type copied to clipboard

Shouldn't the size of a strong type always match the underling type?

Open stmn-bjaehn opened this issue 11 months ago • 2 comments

If multiple modifiers are used, the size of the strong type seems to be doubled. Tested with Microsoft Visual Studio Professional 2019 Version 16.11.33 C++ x64 compiler Standard: latest working draft (C++ 20)

using Id1 = strong::type<std::size_t, struct id1_tag, strong::equality, strong::formattable, strong::hashable>;
using Id2 = strong::type<std::size_t, struct id2_tag, strong::equality>;
using Id3 = strong::type<std::size_t, struct id3_tag, strong::formattable>;
using Id4 = strong::type<std::size_t, struct id4_tag, strong::hashable>;
using Id5 = strong::type<std::size_t, struct id5_tag, strong::equality, strong::formattable>;

std::cout << sizeof(Id1) << " | " << sizeof(strong::underlying_type_t<Id1>) << std::endl;
std::cout << sizeof(Id2) << " | " << sizeof(strong::underlying_type_t<Id2>) << std::endl;
std::cout << sizeof(Id3) << " | " << sizeof(strong::underlying_type_t<Id3>) << std::endl;
std::cout << sizeof(Id4) << " | " << sizeof(strong::underlying_type_t<Id4>) << std::endl;
std::cout << sizeof(Id5) << " | " << sizeof(strong::underlying_type_t<Id5>) << std::endl;

Output image

stmn-bjaehn avatar Mar 22 '24 10:03 stmn-bjaehn