Is there any reason for std::multiplies and std::divides to be in third person? [closed]

StackOverflow https://stackoverflow.com/questions/22723092

  •  23-06-2023
  •  | 
  •  

문제

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::strings 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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top