3

I'm using a lambda function for boilerplate code:

auto import = [&](auto & value){
   // Do some stuff
};

As value is in fact a std::vector, I need to access its value_type static member to call a template function on one of its element.

I tried use of decltype without success :

auto import = [&](auto & value){
   decltype(value)::value_type v;
};

Is there any way to do so ?

etham
  • 2,189
  • 2
  • 13
  • 12
  • 2
    `use of 'auto' in lambda parameter declaration only available with c++14`... please update your question tag – NutCracker Apr 23 '20 at 10:11

1 Answers1

3

The type of value is an lvalue-reference, you can't get the member type from it and have to remove the reference part, e.g

typename std::decay_t<decltype(value)>::value_type v;

PS: You also need to add typename in advance (as @Vlad answered) for the dependent type name. See Where and why do I have to put the “template” and “typename” keywords?.

LIVE

songyuanyao
  • 147,421
  • 15
  • 261
  • 354