相关疑难解决方法(0)

在可变参数模板中使用声明

这个问题的灵感来自以下多重继承重载伪歧义的解决方案,这是一个很好的方法来实现此答案中提出的boost :: variant的lambda访问者:

我想做类似以下的事情:

template <typename ReturnType, typename... Lambdas>
struct lambda_visitor : public boost::static_visitor<ReturnType>, public Lambdas... {
    using Lambdas...::operator(); //<--- doesn't seem to work
    lambda_visitor(Lambdas... lambdas) : boost::static_visitor<ReturnType>() , Lambdas(lambdas)... { }
};
Run Code Online (Sandbox Code Playgroud)

我不确定在打包类型列表中添加使用子句的正确语法是什么.该using条款对于阻止编译器抱怨operator()模糊不清是完全不重要的,因为它们具有所有不同的签名.

c++ operator-overloading multiple-inheritance variadic-templates c++11

30
推荐指数
2
解决办法
3729
查看次数

用lambdas进行变异访问的最佳方法

我想用lambdas内联访问变体类型.目前我有以下代码:

struct Foo {
    boost::variant< boost::blank , int , string , vector< int >  > var;

    template <typename T, typename IL , typename SL , typename VL>
    void ApplyOptionals( T& ref, IL&& intOption , SL&& stringOption , VL&& vectorOption ) {
        if (var.which() == 1) {
            intOption( ref , boost::get< int >(var) );
        } else if (var.which() ==2) {
            stringOption( ref , boost::get< string>(var) );
        } else if (var.which() == 3) {
            vectorOption( ref , boost::get< vector< int > >(var) …
Run Code Online (Sandbox Code Playgroud)

c++ lambda visitor boost-variant c++11

27
推荐指数
1
解决办法
7017
查看次数