I have two structs:
// ----- non-const -----
struct arg_adapter
{
EArgType type; // fmtA, fmtB, ...
union
{
TypeA * valueA;
You can make it accept a metafunction and you can apply any transformation you like
template class F>
struct arg_adapter
{
EArgType type; // fmtA, fmtB, ...
union
{
typename F::type * valueA;
typename F::type * valueB;
// ... more types
};
arg_adapter(typename F::type & value) : type(fmtA), valueA(&value) {}
arg_adapter(typename F::type & value) : type(fmtB), valueB(&value) {}
// ...
};
typename arg_adapter const_adapter;
typename arg_adapter nonconst_adapter;
Or accept a metafunction class to get more flexibility (including the ability to make F
have default arguments not known to your arg_adapter
and such.
template
struct arg_adapter
{
EArgType type; // fmtA, fmtB, ...
union
{
typename apply::type * valueA;
typename apply::type * valueB;
// ... more types
};
arg_adapter(typename apply::type & value) : type(fmtA), valueA(&value) {}
arg_adapter(typename apply::type & value) : type(fmtB), valueB(&value) {}
// ...
};
typename arg_adapter< lambda< boost::add_const<_> >::type > const_adapter;
typename arg_adapter< lambda< boost::mpl::identity<_> >::type > nonconst_adapter;