Today we discovered that the functors for multiplying and dividing, are called std::multiplies
and std::divides
, as opposed to, for example, std::multiply
and std::divide
respectively.
This is surprising to say the least, considering that std::plus
and std::minus
are not formulated the same way.
Is there a particular reason for the difference?
It looks like this is nothing more than a blooper: plus and minus are even not verbs...
The name themselves are not C++14 originals: C++14 just adds the <void>
specialization, but the typed version and all other <functional>
header stuff exist from C++98 (and even pre-iso), and certain coding convention (functions as verbs, object as substatives interface as adjectives...) were not yet already well established.
What C++14 does is just add one more feature to existing definitions letting existing code to continues to works as is. It simply cannot redefine names.
That said, consider also that the +
sign is not always used across the entire standard library for add: in std::string
s it is concatenation, and std::plus
, if applied to strings, concatenates them. Similarly, the * is often used as a "closure" operation (think to boost::spirit
).
A more proper "from scratch" library will most likely call them neutrally as cross
, dash
, star
and slash
, letting the classes that provides the corresponding operations to give them consistent names in their own context