Template functor, how to hide the type?

Joined
Oct 26, 2010
Messages
2
Reaction score
0
Hello all,

I have this functor structure :

Code:
template< typename T >
struct Equal
{
    explicit Equal( T e ) : e_( e ) {}

    template< typename T2 >
    bool operator()( T2 rhs ) const
    {
        return e_ == rhs;
    }

    T e_;
};

I saw that I could do this with the boost library:
Code:
boost::function< bool( int ) > fun;
Equal< int > e( 42 );
fun = e;

But I cannot use boost in my current project. So I need to re-code this boost::function.

Code:
template< typename Type >
struct Function
{
template< typename Wrapper >
  explicit Function( Wrapper w ) : f_( w ) {}

  bool operator()( Type e )
{
  return f_( e );
}
   ??? f_;
}

I really don't know how to hide the Wrapper type to the end-user, as boost::function does.
As to me, if there is a functor structure, we have to copy this structure in data member of the Function class. But if we copy this structure, we will have to explicit its type in the constructor of Function.

Please help, I feel so doomed !! :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top