views:

367

answers:

3

I realize this is a ludicrous question for something that takes less than 2 seconds to implement. But I vaguely remember reading that one was introduced with the new standard.

I grep'ed VC10's headers and came up with nothing. Can you help? It's bugging me! :)

edit: On second thought, the new functor I was remembering was probably the unrelated std::default_deleter.

+8  A: 

You could always write a no-op lambda: []{}

tzaman
I like this, but it doesn't work for the number of `std::conditional`s I have scattered about. And an empty `std::function` will throw on operator().
dean
A: 

You was probably thinking about the identity function (std::identity and apparently it's removed in the current draft) that is not the same thing though.

snk_kid
I had known of `identity` but dismissed it for being a unary. I recall having needed a generic default_deleter for something, six months ago... can't quite remember what for.
dean
A: 

How about this?

// Return a noop function 
template <typename T>
struct noop
{
  T return_val;

  noop (T retval = T ())
       :  return_val (retval)
  {
  }

  T
  operator (...)
  {
    return return_val;
  }
};

template <>
struct noop<void>
{
  void
  operator (...)
  {
  }
};

This should work for just about any use.

Joe D