c++ - 如何转换boost::fusion::vector的类型?

标签 c++ boost boost-fusion

我需要为指定的类型列表定义两种类型:第一种是 boost::fusion::vector这些类型中的第二个是 boost::fusion::vector其中引用和 const类型列表中的每种类型都被删除。

例如,我有 int , unsigned &long const & .我需要定义 boost::fusion::vector<int, unsigned &, long const &>boost::fusion::vector<int, unsigned, long> .

这是我的代码:

struct RemoveRef
{
    template <class T>
    struct apply
    {
        using type =
            typename std::remove_const<typename std::remove_reference<T>::type>::type;
    };
};

template <typename...Args>
struct BasicDefinition
{
    typedef typename boost::mpl::vector<Args...> Types;
    typedef typename boost::fusion::result_of::as_vector<Types>::type ArgsType;
    typedef typename boost::mpl::transform<Types, RemoveRef>::type ValueTypes;
    typedef typename boost::fusion::result_of::as_vector<ValueTypes>::type ArgValuesType;
};

它有效。我得到这些类型为 BasicDefinition<>::ArgsTypeBasicDefinition<>::ArgValuesType .但我想摆脱 boost::mpl::vector s 并直接从第一个类型构建第二个类型。有没有可能达到这样的效果?

类似于:

template <typename...Args>
struct BasicDefinition
{
    typedef typename boost::fusion::vector<Args...> ArgsType;
    typedef ?????<ArgsTypes, RemoveRef>::type ArgValuesType;
};

最佳答案

您可以使用 std::decay_t

template <typename...Args>
struct BasicDefinition
{
    using ArgsType = boost::fusion::vector<Args...>;
    using ArgValuesType = boost::fusion::vector<std::decay_t<Args>...>;
};

关于c++ - 如何转换boost::fusion::vector的类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50707046/

相关文章:

boost - ptr_map 和指针

具有不同参数的 C++ boost 信号和插槽?

c++ - 在 clock_gettime() 中使用 _COARSE 变体仍然调用 sys_clock_gettime() 系统调用

c++ - 我无法从另一个类调用我的 main 中的函数

c++ - 什么是分配器<T>

c++ - 错误:boost.fusion::for_each() 和从 boost.tuple 派生的结构

c++ - MPL替换而不类型转换聚变容器

c++ - 为什么不能将 std::pair 与 std::initializer_list 进行比较

c++ - gmp_int boost 错误

c++ - 使用 range for on a boost FUSION 序列