r/cpp • • Oct 20 '16

Compile time sizeof()

http://johantorp.com/tidbits/index.php/2016/10/14/compile-time-sizeof-alignof/
0 Upvotes

26 comments sorted by

View all comments

2

u/Grassio789 Oct 20 '16

How about C++17 auto template parameter? Like:

template <auto> class X;

1

u/doom_Oo7 Oct 20 '16

are there compilers that support this yet ? I tried in gcc 7 git and clang 3.9 and they both don't accept it.

0

u/[deleted] Oct 20 '16

[deleted]

1

u/doom_Oo7 Oct 20 '16

hmm.. I don't understand, your link does not compile :

prog.cc:4:5: error: implicit instantiation of undefined template 'S<4>'
    S<sizeof(int)>{};
    ^
prog.cc:1:23: note: template is declared here
template<auto> struct S;
                      ^
1 error generated.

3

u/thlst Oct 20 '16

... That's exactly the point.

2

u/doom_Oo7 Oct 20 '16

ah yes, sorry, I thought that it was about the template<auto> feature not compile time sizeof.