views:

163

answers:

2

What do these two strange lines of code mean?

thread_guard(thread_guard const&) = delete;

thread_guard& operator=(thread_guard const&) = delete;
+10  A: 

It is the new C++0x syntax for disabling the certain functions of the class. See wikipedia for an example. Here you are telling that class thread_guard is neither copyable nor assignable.

Naveen
It works for other functions, too.
sellibitze
+11  A: 

The =delete is a new feature of C++0x. It means the compiler should immediately stop compiling and complain "this function is deleted" once the user use such function (See also: defaulted and deleted functions -- control of defaults of the C++0x FAQ by Bjarne Stroustrup).

The thread_guard(thread_guard const&) is a copy constructor, and thread_guard& operator=(thread_guard const&) is an assignment constructor. These two lines together therefore disables copying of the thread_guard instances.

KennyTM
Almost. The "use" of a deleted function in an unevaluated context (for example, as expression to `decltype`) can qualify as a template argument deduction failure. This makes a compiler just ignore a template. It doesn't make the compiler stop compiling.
sellibitze