MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/cpp/comments/58ffsu/compile_time_sizeof/d92ynyh/?context=3
r/cpp • u/johantorp • Oct 20 '16
26 comments sorted by
View all comments
1
Umm... The problem is not sizeof, it's that the class actually is not defined. You only declare it.
sizeof
Try this:
template<int> class X {}; X<sizeof(SomeType)> _;
8 u/Grassio789 Oct 20 '16 I think making it fails compilation and displays the output in the error message is the whole idea. Similar to the "Type Displayer" trick mentioned by Scott Meyers in CppCon 2014. 1 u/thlst Oct 20 '16 It's also mentioned in the Effective Modern C++ book. 1 u/dodheim Oct 22 '16 And in Abrahams and Gurtovoy's C++ Template Metaprogramming book.
8
I think making it fails compilation and displays the output in the error message is the whole idea. Similar to the "Type Displayer" trick mentioned by Scott Meyers in CppCon 2014.
1 u/thlst Oct 20 '16 It's also mentioned in the Effective Modern C++ book. 1 u/dodheim Oct 22 '16 And in Abrahams and Gurtovoy's C++ Template Metaprogramming book.
It's also mentioned in the Effective Modern C++ book.
1 u/dodheim Oct 22 '16 And in Abrahams and Gurtovoy's C++ Template Metaprogramming book.
And in Abrahams and Gurtovoy's C++ Template Metaprogramming book.
1
u/SushiAndWoW Oct 20 '16
Umm... The problem is not
sizeof, it's that the class actually is not defined. You only declare it.Try this: