0

With C++20 you can now do the following:

auto x = []<typename T>(T x){};

this is fine with template argument deduction, but if I have a non-type template parameter, e.g.

auto x = []<std::size_t N>(){};

how do I specify N?

x<1>();

doesn't work, instead it's handled as lt comparison between x and 1.

Yamahari
  • 1,926
  • 9
  • 25
  • That dupe doesn't apply; it's answers are specifically for C++17 and `auto` parameters. This is a C++20 question. – sweenish Oct 12 '20 at 15:12
  • @sweenish: Check the answer there. It gives the `operator()` form of the function call operator, which accepts template arguments. I.e. `x.operator()<1>()`. – MSalters Oct 12 '20 at 15:16
  • @sweenish, nothing has changed in C++20 in that respect. `x.operator()();` is the answer. – Evg Oct 12 '20 at 15:16
  • Note that even non-type template parameters can be deducible: `[](std::array &d) {…}` can usefully find a base-class subobject, for example. – Davis Herring Oct 12 '20 at 20:00

0 Answers0