c++ - deducing return type from auto input argument -


why following fail compile? can compiler not deduce return type input?

don't follow type conversion error being displayed.

auto func(auto &x) {  return x[0]; }  int main() {   vector<int> v = { 1, 2, 3};   (void)func(v); }  $ g++ -std=c++1z auto.cc  auto.cc: in instantiation of ‘auto func(auto:1&) [with auto:1 = std::vector<int>]’: auto.cc:15:16:   required here auto.cc:8:14: error: not convert ‘(& x)->std::vector<_tp, _alloc>::operator[]<int, std::allocator<int> >(0ul)’ ‘__gnu_cxx::__alloc_traits<std::allocator<int> >::value_type {aka int}’ ‘std::vector<int>’     return x[0]; 

auto function argument type is not standard c++. nevertheless, g++ 7 (svn) accepts it... and code compiles.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -