1

I found out, that GCC 5.1 allows types like list<auto> as function and lambda parameter types. While this feature is really interesting and even useful, I couldnt find any extensions or standards that explain this behavior.

Is there any explanation on GCC's side about this feature?

I made an easy type switch as an example:

#include <iostream>
#include <vector>
#include <typeinfo>
#include <tuple>

using namespace std;

void matchType(const tuple<auto,auto,auto>& x){
    cout << "its a tuple<auto,auto,auto>" << endl;
}

void matchType(const tuple<auto,auto>& x){
    cout << "its a tuple<auto,auto>" << endl;
}

void matchType(const vector<auto>& x){
    cout << "its a vector<" << typeid(typename decay_t<decltype(x)>::value_type).name() << ">" << endl;
}

void matchType(const auto& x){
    cout << "its a " << typeid(x).name() << endl;
}

int main(){
    matchType(make_tuple(23,55,11));
    matchType(make_tuple("hey","it works"));
    matchType(vector<string>{});
    matchType(vector<int>{});
    matchType("test");
}

output:

its a tuple<auto,auto,auto>
its a tuple<auto,auto>
its a vector<NSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE>
its a vector<i>
its a A5_c
tly
  • 1,202
  • 14
  • 17
  • http://stackoverflow.com/questions/25879705/is-auto-as-a-parameter-in-a-regular-function-a-gcc-4-9-extension This I guess? – Baum mit Augen Jul 16 '15 at 20:29
  • @BaummitAugen Yes. Concepts TS it is: http://open-std.org/JTC1/SC22/WG21/docs/papers/2015/n4377.pdf – dyp Jul 16 '15 at 20:33
  • 1
    And gcc's implementation is [known to be buggy](https://stackoverflow.com/questions/28618788/why-does-stdresult-of-not-work-with-lambdas#comment45541088_28618788) – Praetorian Jul 16 '15 at 20:34

0 Answers0