Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the Standard say about the namespace of lambda types?

Tags:

c++

c++11

Let's say that I have a setup like this:

namespace hi {
    template<typename L, typename R> L operator+(L l, R r) {
        // some body
    }
    auto f() {
        return [] {}; // Legal C++14
    }
}
int main() {
    auto x = hi::f();
    1 + x; // Is this legal?
}

The question is whether ADL on the lambda type will find the overloaded operator in that namespace by Standard.

like image 747
Puppy Avatar asked May 25 '13 18:05

Puppy


1 Answers

C++11 says (5.1.2, p3) that the type of a lambda will be declared "in the smallest block scope, class scope, or namespace scope that contains the corresponding lambda-expression." So in this case, the type will be declared in f. C++14's CD has the same language.

So the question really is what the namespace for a local class is. I don't think it has one.

C++11, section 9.8, p1, states: The name of a local class is local to its enclosing scope. As such, I don't believe that it has any associated namespaces (per 3.4.2, p2), and is therefore not subject to ADL.

like image 133
Nicol Bolas Avatar answered Oct 04 '22 18:10

Nicol Bolas