I'm trying to figure out a way to use Boost::MPL to generate a typename which is the concatenation of a template parameter and a string.
I have pairs of classes which are named: X and XProvider. The latter is a factory class which instantiates objects inherited from the former type.
The template class is intended to manage the instantiation of types at runtime: it contains, among other things, an unordered_map and some other misc. members.
What I am ultimately trying to achieve is a metafunction that looks something like this:
Given the class
template <typename T>
class Plugin_Manager{
using Base_Type = T;
std::vector<Get_Provider_Type<Base_Type>::type *> m_provider_collection;
*/ ... /*
};
Where Get_Provider_Type<T> is a metafunction which returns a typename TProvider.
Based on this answer, I think that the metafunction should look something along the lines of this:
template < typename Str1, typename Str2 >
struct concat : boost::mpl::insert_range < Str1, typename boost::mpl::end<Str1>::type, Str2 > {};
template <class T> struct Get_Provider_Type{
typedef typename boost::mpl::string<boost::mpl::c_str<T>::value>::type Base_Name;
typedef boost::mpl::string<'Prov', 'ider'> Suffix;
typedef typename concat<Base_Name, Suffix>::type type;
};
However, I am really not understanding mpl::c_str or mpl::string or their correct usage, and I cannot follow the error messages that I am receiving. The code as written above gives me the error message:
error C2039: 'value_type' : is not a member of 'foo'
(foo here being the template argument -- Plugin_Manager<foo>)
I realize that I can likely make this work if I use a large macro rather than c++ template, but I would really like to avoid that if at all possible.
I'd really appreciate any suggestions.
Thanks- Shmuel
Get_provider_Type<Base_Type>::typeto specify the template argument of a vector all you need is to provide a type. You don't need to generate a name for it at all. - pmrPlugin_Manager<foo>needs to contain astd::vector<fooProvider>-- I'd like to have a metafunctionGet_Provider_Type<foo>::typewhich will return for me the typefooProvider, but I do not know how to write this metafunction (or even if it's possible -- per @MarkRansom's comment above). - Shmuel Levinepublic: typedef fooProvider provider;inside offoo. This way each class can define their own provider type and don't have to follow any particular naming convention. Then you just havetypename T::provideras the provider type. - cdhowie