8

Namely:

[](auto const& foo) {
    ??? bar; // should be same base type as foo, minus const&
}

So far, I'm using:

typename std::remove_const<typename std::remove_reference<decltype(foo)>::type>::type combination

But I'm really hoping theres an easier alternative!

Yakk - Adam Nevraumont
  • 262,606
  • 27
  • 330
  • 524
mmocny
  • 8,775
  • 7
  • 40
  • 50
  • 1
    As far as I've read, I was `auto` type deduction semantics, but in a place where I need to use `decltype` since I'm not assigning an expression. They introduced `decltype(auto) foo = bar` for the reverse problem, but now I want `decltype(bar) foo;` ;) – mmocny Jun 07 '14 at 03:15

1 Answers1

10

std::decay<decltype(whatever)>::type, or decay_t if your std library has been updated with it.

It emulates various kinds of function argument decays. It handles if your arg was a reference-to-function. On reference-to-array, it produces a pointer as well, which is less ideal.

If you want to handle those differently, you'll have to roll your own.

Yakk - Adam Nevraumont
  • 262,606
  • 27
  • 330
  • 524