4

Related to this question I was wondering if something like this would be achievable in a straightforward way using boost::hana:

#include <boost/hana.hpp>
#include <boost/hana/unpack.hpp>

namespace hana = boost::hana;

template<typename ... T>
struct A {};

int main() {

  auto my_tuple = hana::tuple_t<int, double, float>;

  // Is there any way to unpack my_tuple as template arguments for A?
  // Something like
  using MyStruct = A<hana::unpack_types(my_tuple)...>;

  static_assert(std::is_same<MyStruct, A<int, double, float>>::value, "Ooops!");
}
Community
  • 1
  • 1

3 Answers3

13

Use template_ to lift A into a metafunction, then call unpack:

using MyStruct = decltype(hana::unpack(my_tuple, hana::template_<A>))::type;

Example.

ecatmur
  • 152,476
  • 27
  • 293
  • 366
1

You may do it yourself with:

 template <template <typename...> class C, typename Tuple> struct RebindImpl;

 template <template <typename...> class C, typename ... Ts>
 struct RebindImpl<C, hana::tuple_t<Ts...>>{
     using type = C<Ts...>;
};

 template <template <typename...> class C, typename Tuple> 
 using Rebind = typename RebindImpl<C, Tuple>::type;
Jarod42
  • 203,559
  • 14
  • 181
  • 302
  • This is not going to do what you expect! `hana::tuple_t` is specified as being functionally equivalent to `hana::make_tuple(hana::type{}...)`, except with a potentially different type. So first, you don't know what type you get, and second, even if you assume it to be _exactly the same as_ `hana::make_tuple(hana::type{}...)`, then your solution will instantiate `C...>`, which is not what you want. – Louis Dionne Jun 25 '16 at 15:59
0

A simple way to do it if all you care is about getting a correct type:

template <typename... Args>
constexpr A<Args...> make_A(hana::tuple_t<Args...>) {
    return {};
}
Arunmu
  • 6,837
  • 1
  • 24
  • 46