Subject: Re: [boost] [operators] A modern SFINAE-based version of boost::operators?
From: Daniel Frey (d.frey_at_[hidden])
Date: 2017-11-19 08:51:37
> On 19. Nov 2017, at 06:22, David Stone via Boost <boost_at_[hidden]> wrote:
> Here is the initial wording of my proposal for the C++ standardization
> committee on generating more operators by default. I welcome any feedback.
> I intend to present this at the next meeting in March.
Arithmetic operators (especially + and *) can be commutative, giving you very different (and more efficient) implementations. In fact, it is my feeling that commutative + and * are more common than the non-commutative versions (even implied by calling them "arithmetic"). Your proposal completely ignores that (and I don't see how you'd be able to specify if you want a commutative or non-commutative version).
Also, picking std::string::operator+ is a bad example. It is too special to be the template for a general implementation, not only because it is non-commutative but also because classes generally don't have capacity() or other similar properties which should play a role on how to overload operators.
Even if we were to agree that your implementation is "ideal" for this specific case, you could just use that implementation for std::string specifically without any additional support from the language. And if you want to argue that there are more, similar enough cases like that this would only speak for a library-based solution (like Boost.Operators or taocpp/operators) to allow different variants to co-exist and be explicitly named by the library author and picked by the user. Language support must be universal enough to cover 90% (or even 99%) of the use-cases - your proposal fails to do that.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk