std::not1() doesn't accept a function pointer

Discussion in 'C++' started by Juha Nieminen, Jan 26, 2010.

  1. Basically any STL algorithm which requires a predicate as parameter
    can be given either a function object or a regular function as that
    parameter. For example, you can give a function object or a regular
    function pointer as the third parameter to std::remove_if(), and it
    will work ok.

    If you want to *negate* the predicate, you can do it with std::not1().
    However, for some reason std::not1() can only be called with a function
    object, not a function pointer. If you want to use it with a regular
    function, you have to do it like std::not1(std::ptr_fun(theFunction)).

    But why? Why couldn't std::not1() accept a regular function as parameter?
    Juha Nieminen, Jan 26, 2010
    #1
    1. Advertising

  2. Pete Becker <> wrote:
    > Because it has to return an object whose type has a couple of nested
    > typedefs, and their definitions are propagated from the type that you
    > instantiate it with. A pointer to function doesn't have those typedefs,
    > so can't be used here. The same problem arises with not2, bind1st and
    > bind2nd. The solution is to wrap the function pointer in a type that
    > provides those typedefs, using ptr_fun.


    Why cannot std::not1() do this itself? Why do you have to do it
    manually?
    Juha Nieminen, Jan 27, 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. John Black

    how to use not1?

    John Black, Jun 15, 2004, in forum: C++
    Replies:
    6
    Views:
    1,467
    Rob Williscroft
    Jun 16, 2004
  2. Ingo Nolden
    Replies:
    1
    Views:
    467
    Rob Williscroft
    Jul 14, 2004
  3. dragon9

    why not std::not1 ?

    dragon9, Feb 29, 2008, in forum: C++
    Replies:
    1
    Views:
    1,103
    Triple-DES
    Feb 29, 2008
  4. Alf P. Steinbach
    Replies:
    10
    Views:
    3,045
    Alf P. Steinbach
    Jul 27, 2011
  5. Scott Meyers

    not1/not2 support in C++11

    Scott Meyers, Dec 21, 2011, in forum: C++
    Replies:
    6
    Views:
    578
    Scott Meyers
    Dec 26, 2011
Loading...

Share This Page