What's the difference between a Predicate and a Functor?

Viewed 7233

I just read somebody call a class with a constructor and an operator() a predicate:

// Example
class Foo {
  public:
    Foo(Bar);
    bool operator()(Baz);
  private:
    Bar bar;
};

However, I haven't heard the word predicate being used in this context before. I would call such a thing a functor. For me, a predicate would be something from the domain of formal logic.

This raises the following questions:

  • Is this a common word for something like Foo?
  • Are both terms used interchangeably, or do they mean slightly different things?
  • Or
    • Does the return type (bool versus something else) have something to do with it?
    • What about the operator() being const?
5 Answers
Related