1

Topic: sizeof (variadic pack...)

Greetings! There is a function which arguments can be only fundamental types. I want to count the total size of all arguments of this function.  the such: #include <iostream> #include <tuple> template <typename... Args> constexpr std:: uint8_t sizeofargs (const Args&...) {#pragma pack (push, 1) struct tt {std:: tuple <typename std:: decay <Args>:: type...> t;}; #pragma pack (pop) return sizeof... (Args)? sizeof (tt): 0;} int main (int argc, char ** argv) {std:: cout <<(int) sizeofargs () <<std:: endl; std:: cout <<(int) sizeofargs (argc) <<std:: endl; std:: cout <<(int) sizeofargs (argc, argv) <<std:: endl;} but as result I receive the such: 0 4 16 where first two are true, and last - are not present. It seems that because of alignment on 8. And #pragma pack (push, 1), in this case, for some reason, does not help... How to win? It is possible to use With ++ 11. (About fold expression I know...)

2

Re: sizeof (variadic pack...)

Hello, niXman, you wrote: X> how to win? It is possible to use With ++ 11. (About fold expression I know...) So a normal template to use, not? constexpr size_t sizeofargs () {return 0;} template <typename Head, typename... Args> constexpr size_t sizeofargs (const Head& h, const Args&... tail) {return sizeof (h) + sizeofargs (tail...);}

3

Re: sizeof (variadic pack...)

Hello, watchmaker, you wrote: W> So a normal template to use, not?  thanks, left to have a rest...

4

Re: sizeof (variadic pack...)

Hello, niXman, you wrote: X> thanks, left to have a rest... The Main thing that did not leave to have a rest on something like Go