This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: std::max: if versus ?:
On Sun, Sep 23, 2012 at 8:20 AM, Marc Glisse <marc.glisse@inria.fr> wrote:
> On Sun, 23 Sep 2012, Gabriel Dos Reis wrote:
>
>> On Sun, Sep 23, 2012 at 6:57 AM, Marc Glisse <marc.glisse@inria.fr> wrote:
>>
>>> Seems like if I want a std::max for vectors, I need to overload it...
>>
>>
>> a very natural and sensible design.
>
>
> :-)
>
> Still, that's a pain for such a trivial function. The current max function
> is:
>
> template<typename _Tp>
> inline const _Tp&
> max(const _Tp& __a, const _Tp& __b)
> {
> // concept requirements
> __glibcxx_function_requires(_LessThanComparableConcept<_Tp>)
>
> return __a < __b ? __b : __a;
> }
>
> and I would need to replace it with:
>
> /* If the condition cannot be coerced into a boolean, we are dealing
> with vectors. */
> inline auto
> max(const _Tp& __a, const _Tp& __b)
> -> conditional<is_constructible<bool, decltype (__a < __b)>::value,
> const _Tp&, _Tp>::type
> {
> return __a < __b ? __b : __a;
> }
>
> Overloading instead would still require modifying the generic max function
> to sfinae-disable it for vectors, so that would be even heavier.
Why? Overloading means a well identified parameter list different
from the standard one.
-- Gaby