Consider the following code that mimics a constexpr lambda (proposed for C ++ 17, not available in C ++ 14).
#include <iostream> template<int M, class Pred> constexpr auto fun(Pred pred) { return pred(1) <= M; } template<int M> struct C { template<int N> static constexpr auto pred(int x) noexcept { // simulate a constexpr lambda (not allowed in C++14) struct lambda { int n_, x_; constexpr auto operator()(int y) const noexcept { return this->n_ * this->x_ + y; // ^^^^ ^^^^ <---- here } }; return fun<M>(lambda{N, x}); } }; int main() { constexpr auto res = C<7>::template pred<2>(3); std::cout << res; // prints 1, since 2 * 3 + 1 <= 7; }
Here lambda defined inside a member of the class template function template. Surprisingly, I have to this-> eliminate the lambda n_ and x_ member variables.
Live examples ( with this-> , without this-> )
I got the impression that this is only needed in dependent base classes, but the lambda class is just a local class, not a dependent base class.
Question : can someone point me to the appropriate standard for finding the name of local class members inside templates?
source share