C++ で型定義を書きたいのですが、実装したいものが合法かどうかわかりません。int または同じ型の別のベクトルを指すブースト バリアント型のベクトルの typedef を実行したいとします。それで、これは合法であり、コンパイラは文句を言うでしょうか?
typedef std::vector<boost::variant<int *, boost::variant<int *, IntBranch*>> IntBranch;
boost::make_recursive_variant
その目的のために使用できます:
#include <boost/variant.hpp>
typedef boost::make_recursive_variant<
int*,
std::vector< boost::recursive_variant_ >
>::type IntBranch;
そして、これはあなたがそれを使用する方法です:
#include <vector>
int main()
{
typedef boost::make_recursive_variant<
int*,
std::vector< boost::recursive_variant_ >
>::type IntBranch;
int x = 42;
IntBranch ib = &x;
std::vector<IntBranch> v;
v.push_back(ib);
IntBranch ib2 = v;
// ...
}
そして、これがライブの例です。