C++ 重写类型以使用boost::recursive\u包装而不是boost::make\u recursive variant
我有这种类型的C++ 重写类型以使用boost::recursive\u包装而不是boost::make\u recursive variant,c++,boost,boost-variant,C++,Boost,Boost Variant,我有这种类型的 using expression = boost::make_recursive_variant< number, std::tuple< boost::recursive_variant_, binary_operator, boost::recursive_variant_ > >; 使用expression=boost::生成递归变量< 数字, std::tuple< boos
using expression = boost::make_recursive_variant<
number,
std::tuple<
boost::recursive_variant_,
binary_operator,
boost::recursive_variant_
>
>;
使用expression=boost::生成递归变量<
数字,
std::tuple<
boost::递归变量,
二进制_运算符,
递归变量_
>
>;
不管二进制_运算符是什么,由于这个原因,这种类型不能正常工作
编辑:实际上我不知道为什么它不起作用。事实证明,我链接的问题的答案中提到的pull请求已合并到boost 1.56.0,这意味着问题出在其他地方。下面是一个显示问题的最小程序:
#include <boost/variant.hpp>
#include <boost/variant/recursive_variant.hpp>
#include <tuple>
struct A {};
struct B {};
using working_variant = boost::variant<
A,
B
>;
using not_working_variant = boost::make_recursive_variant<
A,
std::tuple<
boost::recursive_variant_,
B,
boost::recursive_variant_
>
>;
int main() {
working_variant x = A();
not_working_variant y = A();
}
#包括
#包括
#包括
结构A{};
结构B{};
使用工作变量=boost::variant<
A.
B
>;
使用not_working_variant=boost::make_recursive_variant<
A.
std::tuple<
boost::递归变量,
B
递归变量_
>
>;
int main(){
工作变量x=A();
不工作变量y=A();
}
以及编译错误:
$ clang++ -stdlib=libc++ -std=c++14 -isystem ~/soft/boost_1_56_0/ min.cpp
min.cpp:25:25: error: no viable conversion from 'A' to 'not_working_variant' (aka 'make_recursive_variant<A, std::tuple<boost::recursive_variant_, B,
boost::recursive_variant_> >')
not_working_variant y = A();
^ ~~~
/home/crabman/soft/boost_1_56_0/boost/variant/recursive_variant.hpp:176:8: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from
'A' to 'const boost::make_recursive_variant<A, std::__1::tuple<boost::recursive_variant_, B, boost::recursive_variant_>, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_> &' for 1st argument
struct make_recursive_variant
^
/home/crabman/soft/boost_1_56_0/boost/variant/recursive_variant.hpp:176:8: note: candidate constructor (the implicit move constructor) not viable: no known conversion from
'A' to 'boost::make_recursive_variant<A, std::__1::tuple<boost::recursive_variant_, B, boost::recursive_variant_>, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_> &&' for 1st argument
struct make_recursive_variant
^
1 error generated.
$clang++-stdlib=libc++-std=c++14-isystem~/soft/boost\u 1\u 56\u 0/min.cpp
min.cpp:25:25:错误:从“A”到“非工作变量”没有可行的转换(也称为“生成递归变量”)
不工作变量y=A();
^ ~~~
/home/crabman/soft/boost_1_56_0/boost/variant/recursive_variant.hpp:176:8:注意:候选构造函数(隐式复制构造函数)不可行:没有已知的从
“A”到“const boost::使第一个参数成为递归变量&”
结构生成递归变量
^
/home/crabman/soft/boost_1_56_0/boost/variant/recursive_variant.hpp:176:8:注意:候选构造函数(隐式移动构造函数)不可行:没有已知的从
“A”to“boost::使第一个参数成为递归变量&&”
结构生成递归变量
^
生成1个错误。
所以我想我应该重写它,改用boost::recursive\u包装器。但是我该怎么做呢?我不能向前声明一个类型,它将用“using”或“typedef”定义,可以吗?忽略我在问题中写的所有内容。答案是,您需要使用::type来使用boost::make_recursive_variant定义某些类型:
using working_variant = boost::variant<
A,
B
>;
using working_recursive_variant = boost::make_recursive_variant<
A,
B
>::type;
使用工作变量=boost::variant<
A.
B
>;
使用工作递归变量=boost::生成递归变量<
A.
B
>::类型;
即使对于使用实际递归和std::tuple的代码,这一点也同样适用