Boost logo

Boost :

Subject: Re: [boost] [operators] A modern SFINAE-based version of boost::operators?
From: Vicente J. Botet Escriba (vicente.botet_at_[hidden])
Date: 2017-11-14 18:58:01


Le 13/11/2017 à 15:20, Beman Dawes via Boost a écrit :
> Peter Sommerlad, committee member and C++Now presenter who often proposes
> additions to fill in holes in the standard library, asked me:
>
> Are you aware of anybody who tried to provide a boost::operators style of
> automatically providing additional operators with a single base class that
> through SFINAE injects all possible operators based on the ones defined in
> the template parameter? This won't give you the control of the current
> boost::operators, but would be much easier to teach.
>
> For example
>
> struct Me : make_operators_for<Me>{
> Me& operator+=(Me const&); // You get +
> bool operator<(Me const&) const; // You get all relops (<=> will make that
> obsolete)
> Me& operator++(); // you get postfix
> //etc.
> };
>
> Today we have the facilities and compilers to make that happen.
>
> What do you think? Who should I ask?
>
> Anyone doing any work on operators or have any thoughts about updating
> boost::operators?
>
I find all or nothing approach innovative. But not all the innovations
are good. I've always preferred to master the proposed interface? so I
prefer to request for set of operators explicitly, e.g. I could ask for
arithmetic_operators.

Note that the default don't map what we could always expect. E.g. when
we are defining a counter, not all the operations supported by an number
are desired (See e.g. chrono::duration, where we want to add durations
but not to multiply them.
I've been working since a long time on strong types wrapper that could
inherit some of the operations of the underlying type,but not all.
The design of the valid operations is not easy. See [1] for some
examples requiring a restricted number of operations.

While the scope of the PO subject is different (defining operations from
other operation on the same type), I believe that it is worth
considering some strong types as concrete examples, and I don't believe
there is a single case where we want all the operations.
So before going with the all or nothing approach I would like to see
some concrete examples where this will be useful.

Best,
Vicente
[1] Strong types POC

https://github.com/viboes/std-make/tree/master/include/experimental/fundamental/v3/strong

 Â Â Â  https://github.com/viboes/std-make/tree/master/example/strong
 Â Â Â  https://github.com/viboes/std-make/tree/master/test/strong


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk