17

A point from ISO draft n3290 section 5.1.2 paragraph, point 19:

The closure type associated with a lambda-expression has a deleted (8.4.3) default constructor and a deleted copy assignment operator. It has an implicitly-declared copy constructor (12.8) and may have an implicitly declared move constructor (12.8). [ Note: The copy/move constructor is implicitly defined in the same way as any other implicitly declared copy/move constructor would be implicitly defined. —end note ]

Can any one please ....tell some example for this point to understand?

Is there any chance/way to check the Closure object(type)?

Xeo
132k55 gold badges299 silver badges406 bronze badges
asked May 31, 2011 at 11:28

2 Answers 2

30

The closure type associated with a lambda-expression has a deleted (8.4.3) default constructor

int main() {
 auto closure = [](){};
 typedef decltype(closure) ClosureType;
 ClosureType closure2; // <-- not allowed
 return 0;
}

and a deleted copy assignment operator. It has an implicitly-declared copy constructor (12.8) and may have an implicitly declared move constructor (12.8).

#include <utility>
int main() {
 auto closure = [](){};
 typedef decltype(closure) ClosureType;
 ClosureType closure2 = closure; // <-- copy constructor
 ClosureType closure3 = std::move(closure); // <-- move constructor
 closure2 = closure3; // <-- copy assignment (not allowed)
 return 0;
}
answered May 31, 2011 at 11:36
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your answer ..Is there any way/chance of explaing ..this point ..in terms of a class Example
I believe that this is well-formed though: auto closure = []{}; decltype(closure) c{};. That may be changed by a defect report for C++0x rev1 though.
4
struct LambdaExample{
 // deleted operations = not allowed
 LambdaExample() = delete;
 LambdaExample& operator=(LambdaExample const&) = delete;
 // generated by the compiler:
 LambdaExample(LambdaExample const& other);
 LambdaExample(LambdaExample&& other);
 // anything else a lambda needs
};

For your second question, if you mean that you can look into the implementation, then nope, not possible. It's created on-the-fly by the compiler. If you mean to get the type of the lambda, sure:

auto l = [](){};
typedef decltype(l) closure_type;
answered May 31, 2011 at 11:38

2 Comments

yes the closure obj type is created on-the-fly by the compiler..atleast is there any chance to check whether it exists or not
@user: What do you mean with "exists"?

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.