#include <iostream>
#include <tuple>
#include <type_traits>
template<std::size_t I = 0, typename... Tp>
typename std::enable_if<I == sizeof...(Tp), int>::type
elements_size(std::tuple<Tp...>&) { return 0; }
template<std::size_t I = 0, typename... Tp>
typename std::enable_if<I < sizeof...(Tp) && std::is_pod<typename std::tuple_element<I, std::tuple<Tp...>>::type>::value, int>::type
elements_size(std::tuple<Tp...>& t) {
return sizeof(typename std::tuple_element<I, std::tuple<Tp...>>::type) + elements_size<I + 1, Tp...>(t);
}
int main()
{
std::tuple<int, int, char> t;
std::cout << elements_size(t) << std::endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dHVwbGU+CiNpbmNsdWRlIDx0eXBlX3RyYWl0cz4KCnRlbXBsYXRlPHN0ZDo6c2l6ZV90IEkgPSAwLCB0eXBlbmFtZS4uLiBUcD4KdHlwZW5hbWUgc3RkOjplbmFibGVfaWY8SSA9PSBzaXplb2YuLi4oVHApLCBpbnQ+Ojp0eXBlCmVsZW1lbnRzX3NpemUoc3RkOjp0dXBsZTxUcC4uLj4mKSB7IHJldHVybiAwOyB9Cgp0ZW1wbGF0ZTxzdGQ6OnNpemVfdCBJID0gMCwgdHlwZW5hbWUuLi4gVHA+CnR5cGVuYW1lIHN0ZDo6ZW5hYmxlX2lmPEkgPCBzaXplb2YuLi4oVHApICYmIHN0ZDo6aXNfcG9kPHR5cGVuYW1lIHN0ZDo6dHVwbGVfZWxlbWVudDxJLCBzdGQ6OnR1cGxlPFRwLi4uPj46OnR5cGU+Ojp2YWx1ZSwgaW50Pjo6dHlwZQplbGVtZW50c19zaXplKHN0ZDo6dHVwbGU8VHAuLi4+JiB0KSB7CiAgICByZXR1cm4gc2l6ZW9mKHR5cGVuYW1lIHN0ZDo6dHVwbGVfZWxlbWVudDxJLCBzdGQ6OnR1cGxlPFRwLi4uPj46OnR5cGUpICsgZWxlbWVudHNfc2l6ZTxJICsgMSwgVHAuLi4+KHQpOwp9CgppbnQgbWFpbigpCnsKICAgIHN0ZDo6dHVwbGU8aW50LCBpbnQsIGNoYXI+IHQ7CiAgICBzdGQ6OmNvdXQgPDwgZWxlbWVudHNfc2l6ZSh0KSA8PCBzdGQ6OmVuZGw7CgogICAgcmV0dXJuIDA7Cn0KCg==
In file included from prog.cpp:2:0:
/usr/include/c++/5/tuple: In instantiation of 'struct std::tuple_element<1u, std::tuple<char> >':
/usr/include/c++/5/tuple:755:12: recursively required from 'struct std::tuple_element<2u, std::tuple<int, char> >'
/usr/include/c++/5/tuple:755:12: required from 'struct std::tuple_element<3u, std::tuple<int, int, char> >'
prog.cpp:12:105: recursively required from 'typename std::enable_if<((I < sizeof... (Tp)) && std::is_pod<typename std::tuple_element<__i, std::tuple<_Elements ...> >::type>::value), int>::type elements_size(std::tuple<_Elements ...>&) [with unsigned int I = 1u; Tp = {int, int, char}; typename std::enable_if<((I < sizeof... (Tp)) && std::is_pod<typename std::tuple_element<__i, std::tuple<_Elements ...> >::type>::value), int>::type = int]'
prog.cpp:12:105: required from 'typename std::enable_if<((I < sizeof... (Tp)) && std::is_pod<typename std::tuple_element<__i, std::tuple<_Elements ...> >::type>::value), int>::type elements_size(std::tuple<_Elements ...>&) [with unsigned int I = 0u; Tp = {int, int, char}; typename std::enable_if<((I < sizeof... (Tp)) && std::is_pod<typename std::tuple_element<__i, std::tuple<_Elements ...> >::type>::value), int>::type = int]'
prog.cpp:18:33: required from here
/usr/include/c++/5/tuple:755:12: error: invalid use of incomplete type 'struct std::tuple_element<0u, std::tuple<> >'
struct tuple_element<__i, tuple<_Head, _Tail...> >
^
In file included from /usr/include/c++/5/tuple:38:0,
from prog.cpp:2:
/usr/include/c++/5/utility:85:11: note: declaration of 'struct std::tuple_element<0u, std::tuple<> >'
class tuple_element;
^