views:

95

answers:

3

Is there a commonly accepted terminology for various types for common functors?

For instance I found myself naturally using comparator for comparison functors like this:

struct ciLessLibC : public std::binary_function<std::string, std::string, bool> {
    bool operator()(const std::string &lhs, const std::string &rhs) const {
        return strcasecmp(lhs.c_str(), rhs.c_str()) < 0 ? 1 : 0;
    }
};

Or using the term deltor for something like this:

struct DeleteAddrInfo { 
    void operator()(const addr_map_t::value_type &pr) const {
        freeaddrinfo(pr.second);
    }
};

If using these kinds of shorthand terms is common, it there some dictionary of them all someplace?

+1  A: 

Surely there are no standards, common rules applies.

adf88
What I'm wondering is if there is a list of commonly used functor terms anywhere? No standards implied...
Robert S. Barnes
+3  A: 

Comparator is fairly widely used, more so in Java than C++ - comparison function being the terminology in the original STL, Comparator the terminology in the Java API.

'deltor' isn't a word in common use, and sounds like 'delta', so wouldn't make me think of something which frees pointers.

Pete Kirkham
I believe the common terms are "ctor" and "dtor" for constructor/destructor.
PeterK
@PeterK I believe the common terms are "constructor" and "destructor" for constructor/destructor. I don't normally write or document my code in txt speak.
Pete Kirkham
@Pete Kirkham: Any suggestions? Delator maybe?
Robert S. Barnes
@Robert "deleter" would be a more common English construction for 'one who deletes'. A 'delator' was the accusing party in Roman law, and still exists as one who delates (accuses). It's not normal to change the vowels in word stems in English; it often changes the meaning of the word.
Pete Kirkham
+2  A: 
  1. A function that takes two arguments and evaluates to a boolean is a "binary predicate" (likewise, "unary" for one argument, and "ternary" for three).

  2. In the second case, "deleter" seems to be an acceptable name (see boost::shared_ptr).

Alex B
+1 for the Boost reference. In regards to the predicate terminology, I'm aware it and looking for more specific short hand terms like the "deleter" you mentioned which imply the functionality of the functor.
Robert S. Barnes