From: DeMarcus on
Hi,

I find the paper N2855 - Rvalue References and Exception Safety very promising.

http://www.open-std.org/Jtc1/sc22/WG21/docs/papers/2009/n2855.html

In the introduction of N2855 they deal with the problem that the move operation may throw due to invocation of the copy constructor when the move constructor T(T&&) is absent. In the paper they locate such problems with Concepts, but now in the absence of Concepts (that won't make it into C++0x), what are the guidelines writing classes with strong exception guarantee?

If I make sure that I always provide the move constructor along with the copy constructor, will I be safe then?

E.g.

class SomeClass
{
public:
SomeClass( const SomeClass& sc );
noexcept SomeClass( SomeClass&& sc );
};

or

class SomeClass
{
public:
SomeClass( const SomeClass& sc ) = delete;
SomeClass( SomeClass&& sc ) = delete;
};

or

class SomeClass
{
public:
SomeClass( const SomeClass& sc ) = delete;
noexcept SomeClass( SomeClass&& sc );
};

or (will be caught by the compiler during move)

class SomeClass
{
public:
SomeClass( const SomeClass& sc );
SomeClass( SomeClass&& sc ) = delete;
};

but definitely *not* the following that would be easy to do by mistake

class SomeClass
{
public:
SomeClass( const SomeClass& sc );
};


Am I guaranteed to be safe if I always provide the move constructor along with the copy constructor?


Thanks,
Daniel


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]