, , , , , S, ftype, , , , ... ie
template<int plugin_id, class T>
struct S
{
typedef T (*ftype)(T);
static ftype& instance()
{
static ftype _fp = T::create();
return _fp;
}
};
S<SOME_PLUGIN,double>::fp S<SOME_PLUGIN,double>::instance(). , - S<>::instance(). , ?
EDIT: , , ftype, . factory T, create(), .
EDIT: , , .. , ( ) , . , ... , ...
#include <iostream>
#include <typeinfo>
#include <boost/fusion/include/vector.hpp>
#include <boost/fusion/algorithm.hpp>
using namespace std;
struct instantiate
{
template <typename T>
void operator()(T const& x) const
{
T::instance();
}
};
template<int plugin_id, class T>
struct S
{
typedef T (*ftype)(T);
static ftype& instance()
{
cout << "S: " << typeid(S<plugin_id, T>).name() << endl;
static ftype _fp;
return _fp;
}
};
template <int plugin_id>
struct S_Types
{
static void instance()
{
boost::fusion::vector<
S<plugin_id, double>,
S<plugin_id, int>,
S<plugin_id, char>
> supported_types;
boost::fusion::for_each(supported_types, instantiate());
}
};
struct S_Register
{
S_Register()
{
boost::fusion::vector<
S_Types<0>,
S_Types<1>,
S_Types<2>
> plugins;
boost::fusion::for_each(plugins, instantiate());
}
};
int main(void)
{
S_Register reg;
return 0;
}
The merge vector is mainly used to identify all possible instances that may exist. It will take a bit of work from you and the developers, as I stated in the code ... I hope this gives you an idea ...