I want to call a functor for each type in a type list. Consider the
following program.
#include <iostream>
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
template
class functor_list_member
{
public:
functor_list_member()
{
Functor f;
f.template operator()<T>();
}
};
template
class functor_list:
private boost::mpl::fold<
Sequence,
boost::mpl::empty_base,
boost::mpl::inherit<
boost::mpl::_1,
functor_list_member
>
::type
{};
::type
{
typedef boost::mpl::vector
types;
struct functor
{
template <typename T>
void operator()()
{
std::cout << __PRETTY_FUNCTION__ << std::endl;
}
};
typedef functor_list my_functor_list;
int main(int argc, char* argv)
{
my_functor_list();
}
The program outputs
void functor::operator()() [with T = bool]
void functor::operator()() [with T = char]
void functor::operator()() [with T = short int]
void functor::operator()() [with T = int]
void functor::operator()() [with T = long int]
void functor::operator()() [with T = float]
void functor::operator()() [with T = double]
However, I want to create a functor object first, and pass it to each
functor_list_member, like this:
template
class functor_list_member
{
public:
functor_list_member(Functor f)
{
f.template operator()<T>();
}
};
template
class functor_list:
private boost::mpl::fold<
Sequence,
boost::mpl::empty_base,
boost::mpl::inherit<
boost::mpl::_1,
functor_list_member
>
public:
functor_list(Functor f)
/* how do I call base(f) ? */
{
}
};
typedef boost::mpl::vector
types;
struct functor
{
template <typename T>
void operator()()
{
std::cout << __PRETTY_FUNCTION__ << std::endl;
}
};
typedef functor_list my_functor_list;
int main(int argc, char* argv)
{
functor f;
my_functor_list(f);
}
but I do not know how to call the constructor of the base class in
functor_list::functor_list(Functor f). (see comment /* how do I call
base(f) ? */). Can someone help me?
Best regards,
--
Ares Lagae
Computer Graphics Research Group, Katholieke Universiteit Leuven
http://www.cs.kuleuven.be/~ares/