Topic: [c++std-core-27173] An implementation of
Author: Bjarne Stroustrup <bjarne@stroustrup.com>
Date: Wed, 04 Mar 2015 11:17:22 -0500
Raw View
On 3/3/2015 10:45 PM, Gabriel Dos Reis wrote:
> Should we declare "auto f(auto) -> auto" an excess in sophism?
and those two "auto"s can denote different and unrelated types?
>
> -- Gaby
>
>
>> On Mar 3, 2015, at 6:39 PM, Faisal Vali <faisalv@gmail.com> wrote:
>>
>> In the hopes of soliciting constructive feedback, if anyone has the
>> time or the interest to play with a patched up Clang that implements
>> enhanced auto deduction & abbreviated template syntax from the
>> concepts ts, here it is:
>>
>> https://github.com/faisalv/clang/tree/enhanced-auto-c%2B%2B1z .
>>
>> The last line of the README file tells you the subversion revision of
>> LLVM to use.
>>
>> For examples of test cases that successfully compile, please refer to:
>> -- https://github.com/faisalv/clang/blob/enhanced-auto-c%2B%2B1z/test/CXX/auto/cxx1z-auto-vars-generalized.cpp
>> -- https://github.com/faisalv/clang/blob/enhanced-auto-c%2B%2B1z/test/CXX/auto/cxx1z-abbreviated-templates.cpp
>>
>> I would certainly appreciate the feedback!
>>
>> 1) Enhanced-Auto Deduction:
>>
>> pair<auto...> f() { return make_pair([] { }, [] { }); }
>> vector<auto> v = vector<int>();
>>
>> 2) Abbreviated Template Syntax:
>> void f(auto) <=> template<class T> void f(T);
>>
>>
>> A few, perhaps not so obvious or interesting, technicalities:
>>
>> a) The equivalence of templates when it comes to trailing return
>> types in function pointer parameters is based on the order of the
>> 'auto' that signifies a placeholder, not just the appearance of an
>> auto in the declaration-specifier of a parameter:
>>
>> template<class R, class P> void f( R(P) ); // #1
>> template<class P, class R> void f( R(P) ); // #2 (order of
>> templ-params flipped)
>>
>> template<class R, class P> void f( auto (P)->R); // equivalent to
>> #1, not abbreviated.
>> void f(auto(auto)); // equivalent to #1
>> void f(auto (auto) -> auto); // equivalent to #2
>> // the trailing return type auto
>> // identifies a
>> template parameter
>> template<class R> void f(R(auto); // equivalent to #1
>> template<class P> void f(auto(P)); // equivalent to #2
>>
>> b) variadic auto
>> Once an ellipsis is seen as part of the declarator, all contained
>> auto placeholders get transformed into parameter packs.
>> void f(auto (*...)(auto) -> std::tuple<auto, std::pair<auto, auto>...>);
>> Note there are 4 deducible template parameter packs above.
>>
>> c) multi abbreviated template declarations
>> void f(auto), g(auto);
>> are allowed - the above declares two function templates.
>>
>> d) template aliases desugar their types *after* each auto has been
>> identified as a placeholder (and so must be deduced)
>>
>> template<class T> using Int = int;
>> Int<auto> i = 3; // Is an error, auto must be deducible.
>>
>> e) generic lambda's as default arguments work with abbreviated template syntax:
>> void f(int (*)(int) = [](auto a) { return a; }, auto b = decltype(b){});
>> f<float*>(); // OK
>>
>> f) variable templates and enhanced auto deduction interact as expected:
>> template<class T> pair<auto...> (*vfp)(auto...) = [](T t1, T* t2)
>> { return make_pair(t1, t2); };
>>
>> Thanks!
>> Faisal Vali
>>
>> --
>>
>> ---
>> You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
>> To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
>> To post to this group, send email to std-proposals@isocpp.org.
>> Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
>>
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
.