[cfe-dev] Help getting started

Dave Abrahams dave at boostpro.com
Thu Jan 5 09:58:51 PST 2012


on Thu Jan 05 2012, "Richard Smith" <richard-AT-metafoo.co.uk> wrote:

> On Thu, January 5, 2012 02:01, Dave Abrahams wrote:
>> on Wed Jan 04 2012, "Richard Smith"
>> <richard-Qo5EllUWu/sqdlJmJB21zg-AT-public.gmane.org> wrote:
>>> I'd be somewhat wary of overloading the meaning of 'auto' in this way.
>>> Another
>>> likely proposal for 'auto' extension is allowing 'auto' anywhere within a
>>> variable's type, and deducing the appropriate type from the initializer.
>>> Hence:
>>>
>>> auto (&min)(auto x, auto y) = std::min<int>;
>>
>> [FYI, that code is technically nonportable because you can't know
>> whether std::min has additional, defaulted arguments. ;-) ]
>
> That provision only applies to member functions; see 17.6.5.4/3 for the
> non-member case :)

Curses!  I'm hoist with my own petard!

>>> Perhaps 'template' would be a better keyword to propose than 'auto' here?
>>>
>>> auto min(template a, template b) -> std::remove_reference<decltype(a < b ?
>>> a : b)> noexcept(noexcept(a < b ? a : b)) { return a < b ? a : b; }
>>>
>>> ... or more tersely ...
>>>
>>> auto min(template a, template b) noexcept(auto) { return a < b ? a : b; }
>>
>> No offense, but that is way too far from what I am trying to accomplish
>> to be of much interest to me.  I'm sticking with
>>
>> []min(a, b) { return a < b ? a : b; }
>
> I wasn't intending to suggest you do any differently -- I was commenting on
> the proposal to use 'auto' as a parameter type for creating an implicit
> template, not your proposal (which I quite like).

Ah, thanks for the clarification and for the complement.

-- 
Dave Abrahams
BoostPro Computing
http://www.boostpro.com



More information about the cfe-dev mailing list