Boost hana tuple size
, c++ | boost
Needed a boost::variant visitor to obtain the size of a boost::hana::tuple. You can swap boost::variant for std::variant if you got a C++17 compiler.

Header

#include "boost/variant/static_visitor.hpp"
//include header providing size_t

struct get_size_visitor : public boost::static_visitor< size_t >
{
  template< typename T >
  size_t operator()( T * const element ) const;
};

Source

//include above header file
//include variant types
#include "boost/hana/size.hpp"

// specialize for T == D
template<>
size_t get_size_visitor::operator()( D * const element ) const
{
  return D::base_type::tupleSize;
}

template< typename T >
size_t get_size_visitor::operator()( T * const element ) const
{
  constexpr size_t tupleSize = decltype(
    boost::hana::size( std::declval< typename T::value_type_t >() )
  )::value;

  return tupleSize;
}

// explicit instantiation
template size_t get_size_visitor::operator()< A >( A * const element ) const;
template size_t get_size_visitor::operator()< B >( B * const element ) const;
template size_t get_size_visitor::operator()< C >( C * const element ) const;

Links