Boost logo

Boost Users :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2008-06-02 10:38:29


Chris Ross:
> 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.

...

> template <typename List>
> class detach_all {
> public:
> 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(),
> stop_messaging(dynamic_cast<Messageable*>(ent)));
> }
> }

struct detach_all
{
    typedef void result_type;

    template<class T, class L>
    void operator()( T * pt, L * pl ) const
    {
        if( Messageable * pm = dynamic_cast<...>( pt ) )
        {
            std::for_each( pl->begin(), pl->end(),
                stop_messaging( pm ) );
        }
    }
};

int main()
{
    List list;
    mutexed_for_each( boost::bind( detach_all(), _1, &list ) );
}

is one alternative.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net