Boost Variant class has a member type types. Its a Boost MPL Sequence for types used in template parameters. In the recursive cases such as :
typename boost::make_recursive_variant<int, std::vector<boost::recursive_variant_>>::type;
will create a sequence (types member) :
boost::mpl::l_item<boost::mpl::long_<2>,int,boost::mpl::l_item<boost::mpl::long_<1>,std::vector<boost::variant<boost::detail::variant::recursive_flag<int>,std::vector<boost::recursive_variant_,std::allocator<boost::recursive_variant_> >,boost::detail::variant::void_,boost::detail::variant::void_,...........> >,boost::mpl::l_end> >
As you can see std::vector<boost::recursive_variant_,std::allocator<boost::recursive_variant_> >
is not substituted with the original variant type yet.
I found some internal utilities doing this conversion but its undocumented and its hard to follow due macros.
Now I can do it with MPL but it may not match Variant implementation (there are some recursion limits, etc.)
Is there a way to get this type sequences converted with original Variant utilities?
[Edit]
My goal is to get :
boost::mpl::vector<int, std::vector<MyVariantType, std::allocator<MyVariantType>>
[Edit]
This is how I substitute recursively at the moment. My end goal was to write a convenient Boost.Variant wrapper for adding type interfaces (Finished the implementation but not happy for using my own implementation for recursive type substitutions ). (more https://github.com/FictionIO/WrappedVariant )
template<typename PlaceholderT, typename WithT>
struct substitute_placeholder
{
template<typename InputT>
struct apply
{
template<typename T>
struct substitute
{
using type = T;
};
template<template <typename, typename ...> typename T, typename ParamT, typename ... ParamsT>
struct substitute<T<ParamT, ParamsT...>>
{
template<typename ... TypesT>
struct packed_types{};
template<typename Type1T, typename Type2T>
struct pack_types;
template<typename TypeT, typename ... TypesT>
struct pack_types<packed_types<TypesT...>, TypeT>
{
using type = packed_types<TypesT..., TypeT>;
};
template<typename ... TypesT>
struct unpack
{
using type = void;
};
template<typename ... TypesT>
struct unpack<packed_types<TypesT...>>
{
using type = T<TypesT...>;
};
using originals = boost::mpl::vector<ParamT, ParamsT...>;
using func = typename substitute_placeholder<PlaceholderT, WithT>:: template apply<boost::mpl::_1>;
using substitutedTypes = typename boost::mpl::transform<originals, func>::type;
using packed = typename boost::mpl::fold<substitutedTypes, packed_types<>, pack_types<boost::mpl::_1, boost::mpl::_2>>::type;
using type = typename unpack<packed>::type;
};
template<>
struct substitute<PlaceholderT>
{
using type = WithT;
};
using type = typename substitute<InputT>::type;
};
};
template<typename ImplT, typename TypesVecT>
struct to_substitude_types_vec
{
using func = typename substitute_placeholder<boost::recursive_variant_, ImplT>:: template apply<boost::mpl::_1>;
using type = typename boost::mpl::transform<TypesVecT, func>::type;
};
using originalTypes = typename boost::mpl::copy<VariantT::types, boost::mpl::back_inserter<boost::mpl::vector<>>>::type;
using substitutedTypes = typename to_substitude_types_vec<VariantT, originalTypes>::type