Just a question. Looking at C++ Boost libraries (in particular boost::thread class) I ended up thinking: "how is it possible to create a class defining objects that cannot be copied but that can be returned from a function?"

Well consider this example, the boost::thread class has the characteristics I mentioned before, so it is possible to do this:

Copying and moving can be forbidden separately, so you can setup classes that can be moved, but not copied.

Of course, there are a few magical tricks that let you do this even when your compiler doesn't yet support move semantics (std::auto_ptr, after all moves instead of copying when assigned to), so this might work for boost::thread even in the absence of move semantics.

@Alex: It used to be named C++0x, because it was expected before 2010, but this didn't work out. Many still stick to "C++0x", even though it will likely end up as C++11 or C++12.
–
sbiNov 23 '10 at 19:59

2

@sbi: I think most committee members and compiler implementers still refer to it as C++0x, so I think it'd be more fair to say that it is named C++0x because it was expected before 2010. But that's just nitpicking. :)
–
jalfNov 23 '10 at 21:02

1

@sbi: Ah, right. In that case I correct my previous comment: its name will be "ISO/IEC 14882: Programming Language C++", the same as C++98 and C++03. Which can't possibly cause any confusion :-)
–
Steve JessopNov 24 '10 at 11:31

It basically works by abusing several subtle rules in C++ overload resolution, in particular the rule that non-const references cannot bind to rvalue temporaries and that non-const conversion functions can still be called on non-const temporaries.

You can also use the auto_ptr technique as employed by C++03, which however is seen as broken by several groups because auto_ptr lets you copy variables, but steal resources from the copied-from object (other groups have other opinions about this).