Every lambda should have a unique unknown type.. is it guaranteed that two lambdas into the same scope have different types?
int main() {
auto l1 = [](){};
auto l2 = [](){};
static_assert(std::is_same<decltype(l1), decltype(l2)>::value == false, "Types cannot be equal!");
}
This works but I'd like to know if it's guaranteed that the assert will never fire.
Yes, each lambda expression produces a unique type ([expr.prim.lambda]/3):
The type of the lambda-expression (which is also the type of the closure object) is a unique , unnamed nonunion class type — called the closure type — whose properties are described below.
[emphasis added]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.