Search code examples
c++tr1

Is there a sane default for std::tr1::function?


I spent some time googling but didn't really find anything. I want to be able to do this:

std::tr1::function<void()> foo(SOME_DEFAULT_FUNCTION_THAT_DOES_NOTHING);
//
//Some code that could possibly assign foo
//
foo();

Otherwise I have to do this:

std::tr1::function<void()> foo;
//
//Some code that could possibly assign foo
//
if(foo)
{
    foo();
}

I realize I could just make a function that does nothing, but I am looking for some standard way of not having to deal with checking to see if the function was given a value ala the null object pattern.


Solution

  • void noop() { }