Template functor, how to hide the type?

Discussion in 'C Programming' started by Gb42, Oct 26, 2010.

  1. Gb42

    Gb42

    Joined:
    Oct 26, 2010
    Messages:
    2
    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 !! :)
     
    Gb42, Oct 26, 2010
    #1
    1. Advertising

  2. Gb42

    Gb42

    Joined:
    Oct 26, 2010
    Messages:
    2
    Well, I resolved this problem by using only free functions :p
     
    Gb42, Nov 8, 2010
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chandra Shekhar Kumar

    functor object in template class

    Chandra Shekhar Kumar, Jun 24, 2003, in forum: C++
    Replies:
    5
    Views:
    1,276
    porschberg
    Jun 26, 2003
  2. CoolPint
    Replies:
    3
    Views:
    713
    tom_usenet
    Dec 29, 2003
  3. jack
    Replies:
    3
    Views:
    404
    Victor Bazarov
    Feb 28, 2004
  4. daniel.w.gelder@gmail.com

    Please help me write a functor template

    daniel.w.gelder@gmail.com, Mar 13, 2005, in forum: C++
    Replies:
    8
    Views:
    405
    daniel.w.gelder@gmail.com
    Mar 18, 2005
  5. woessner@gmail.com

    Functor Parameters: Template vs. Members

    woessner@gmail.com, Dec 5, 2006, in forum: C++
    Replies:
    4
    Views:
    504
Loading...

Share This Page