用于可变模板实例化的Boost::hana元组解包
boost::hana tuple unpacking for variadic template instantiation
关于这个问题,我想知道这样的事情是否可以使用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!");
}
使用template_
将A
提升为元函数,然后调用unpack
:
using MyStruct = decltype(hana::unpack(my_tuple, hana::template_<A>))::type;
。
你可以自己做:
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;
如果您只关心获得正确的类型,那么这是一种简单的方法:
template <typename... Args>
constexpr A<Args...> make_A(hana::tuple_t<Args...>) {
return {};
}
相关文章:
- C++:TypeDef使用元组
- Pybind11:将元组列表从Python传递到C++
- 重载元组索引运算符-C++
- 在C++中,如何通过几种类型从元组中选择多个元素
- 将fold表达式与std::一起用于两个元组
- std::ranges::elements_view,用于自定义类似元组的数据
- 将元组的向量转换/构造为堆
- 为什么我在循环提升时得到意外的索引::hana::元组
- Boost.Hana:在 constexpr 上下文中将值元组转换为相应类型的元组
- 在boost::hana中给定一个键元组,如何从映射中获取值元组
- 在 Hana 中满足谓词的元组元素的索引序列
- 使用 hana::transform 在 C++14 中转换元组内的类型
- 从没有预处理器的HANA元组中创建功能签名
- 初始化boost :: hana ::元组用一个参数
- STL 和 Hana 元组之间的转换
- 在增强 hana 中过滤元组
- 如何根据表达式在Boost.Hana中是否有效来过滤类型元组
- 增强元组类型的hana大小
- 创建具有不可移动/不可复制类型的hana元组
- 用于可变模板实例化的Boost::hana元组解包