Open huanncbg opened 7 years ago
As far as I see, it seems to me that there is a precondition to variant::set<T>()
. T
shall be in variant::Types...
. Take a look at mapbox/variant.hpp:{704, 705}
.
You should use T
equals mapbox::util::recursive_wrapper<HPArray>
instead of HPArray
.
struct HPArray;
using HPVariant = mapbox::util::variant<
std::string,
float,
mapbox::util::recursive_wrapper<HPArray>
>;
struct HPArray { /*...*/ };
int main()
{
HPVariant var;
//It should be: var.set<mapbox::util::recursive_wrapper<HPArray>>(...)
var.set<HPArray>(HPArray{});
mapbox::util::apply_visitor([](auto&& o){ /*...*/ }, var);
}
BTW, is there a reason to maintain variant::set<T>()
to 2.0.0?
include
include <mapbox/variant.hpp>
include
using namespace std; using namespace mapbox::util;
// Forward declaration struct HPArray; struct HPTable; using HPVariant = variant<string,float,recursive_wrapper>;
struct HPArray{ template <typename ...Args> HPArray(Args ...args){ values.emplace(std::forward(args)...);
}
unordered_map<int,HPVariant> values;
};
struct Visitor{
};
int main() { HPArray ar; ar.values[0] = HPVariant("String"); ar.values[1] = 2.0f;
}