>Eric Lemings wrote:
> 
>Consider the following little program:
>
>-----------------------------------------------------------
>

[...]
 
>#include <cstddef>
> 
>template <class... TypesT>
>struct tuple_size
>    : integer<std::size_t, sizeof... (TypesT)> { };
> 
>#include <iostream>
> 
>int main ()
>{
>    typedef tuple < > tuple0;
>    std::cout << tuple_size< tuple0 >::value << std::endl;
> 
>    typedef tuple < int > tuple1;
>    std::cout << tuple_size< tuple1 >::value << std::endl;
> 
>    return 0;
>}
>
>-----------------------------------------------------------
>
>Compiling with gcc-4.3 using the -std=gnu++0x option (gcc-4.3.1 was
>just released BTW), I get the following output:
>
>1
>1
>
>The first line should print '0', shouldn't it?  Or no?
>

No. The output is as expected. Your tuple_size template doesn't give the
size of the tuple, it gives the number of arguments in the template
parameter pack named TypesT. In both cases the number of template
arguments provided is exactly 1.

If you want thenumber of elements in the tuple, you need to get at them
through the tuple.

  // this is called if we are not dealing with a tuple
  template <class... _Types>
  struct tuple_size
      : integral_constant<_RWSTD_SIZE_T, 0>
  {
  };

  template <class... _Types>
  struct tuple_size< tuple<_Types...> >
      : integral_constant<_RWSTD_SIZE_T, sizeof... (_Types)>
  {
    // this is used when the template parameter is a tuple.
    // it strips the tuple away and accesses the template
    // parameter pack.
  };


>Brad.
>

Reply via email to