Boost logo

Boost Users :

From: Chris Ross (cross+boost_at_[hidden])
Date: 2008-06-02 10:06:09

  Forgive me if the answer ends up being strictly C++, rather than
Boost. But, I have a template class that I would rather be able to
deduce it's single [current] template parameter rather than having to
specify it. I'm wondering if boost::function or boost::functional might
make this easier for me to accomplish.

  My functor class is passed to a method similar to std::for_each, and
that template functor class is:

/*! Detach all members of the EntityList via stop_messaging.
 * \todo I suspect there's a way to make this not require template
 * arguments at instantiation, but at the moment it's being used
 * as:
 * mutexed_for_each(detach_all<typeof(arg)>(arg));
template <typename List>
class detach_all {
    detach_all(const List &e) : list(e) {}
    template <class T>
    void operator ()(T*ent) const
        if (dynamic_cast<Messageable*>(ent)) {
            std::for_each(list.begin(), list.end(),
    const List &list;

  If I make the class not be a template, but instead make the
constructor a template member, it would be able to determine the
template parameter List from the argument to the constructor. However,
I'm then unable to keep a reference to the List argument to the
constructor, which I need during the operator() invocation.

  Am I missing something about templates that I don't know? Or, is this
just not possible with C++ templates, and in which case, can I use one
of the boost libraries to help?

  Thanks much.

                                  - Chris

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at