Four types - which ones are MoveConstructible?

  • Thread starter Niels Dekker - no reply address
  • Start date
N

Niels Dekker - no reply address

Which of the following four types (T1, T2, T3, T4) do you consider
MoveConstructible?

typedef int T1;
typedef const int T2;
typedef std::unique_ptr<int> T3;
typedef const std::unique_ptr<int> T4;

I'm asking because the definition of MoveConstructible, as specified by the
current C++0x working draft <www.open-std.org/JTC1/sc22/WG21>, may still
need some finetuning. Daniel Kruegler has already opened an issue on the
subject: "Missing expressions for Move/CopyConstructible",
http://www.open-std.org/JTC1/sc22/WG21/docs/lwg-active.html#1309 I'm
interested to hear your opinion.


Kind regards,

Niels

PS Just in case you don't know std::unique_ptr<T>: It's a new smart pointer
template class, to be included with C++0x. It will have a move-constructor,
which allows transferring the ownership from an rvalue argument. Its
copy-constructor will be deleted. Please check the current C++0x draft for a
more accurate specification.
 
N

Niels Dekker - no reply address

I'm asking because the definition of MoveConstructible, as specified
Juha said:
I thought concepts were dropped from C++0x.

Yes, indeed. But C++0x will still use terms like "MoveConstructible" to
specify the requirements of std library templates. For example, when
defining std::swap:

template<class T> void swap(T& a, T& b);
Requires: Type T shall be MoveConstructible and MoveAssignable.
Effects: Exchanges values stored in two locations.

See http://www.open-std.org/JTC1/sc22/WG21/docs/papers/2010/n3035.pdf

The term MoveConstructible is defined in Table 33:

Table 33 - MoveConstructible requirements [moveconstructible]
Expression Post-condition
T t(rv) t is equivalent to the value of rv before the construction

So now I wonder which of those four types are MoveConstructible:

typedef int T1;
typedef const int T2;
typedef std::unique_ptr<int> T3;
typedef const std::unique_ptr<int> T4;


Kind regards,

Niels
 
B

Bo Persson

Niels said:
Juha said:
I thought concepts were dropped from C++0x.

Yes, indeed. But C++0x will still use terms like
"MoveConstructible" to specify the requirements of std library
templates. For example, when defining std::swap:

template<class T> void swap(T& a, T& b);
Requires: Type T shall be MoveConstructible and MoveAssignable.
Effects: Exchanges values stored in two locations.

See
http://www.open-std.org/JTC1/sc22/WG21/docs/papers/2010/n3035.pdf
The term MoveConstructible is defined in Table 33:

Table 33 - MoveConstructible requirements [moveconstructible]
Expression Post-condition
T t(rv) t is equivalent to the value of rv before the construction

So now I wonder which of those four types are MoveConstructible:

typedef int T1;
typedef const int T2;
typedef std::unique_ptr<int> T3;
typedef const std::unique_ptr<int> T4;

In my opinion, T1, T2, and T3. Being CopyConstructible is sufficient
for the first two, and T3 has a move constructor.

T4 has a deleted copy constructor, which should stop it from being
copied. The constness would stop it from being cast to unique_ptr&&,
so it can't be moved either.


Bo Persson
 
N

Noah Roberts

I'm asking because the definition of MoveConstructible, as
specified by the current C++0x working draft
<www.open-std.org/JTC1/sc22/WG21>, may still need some finetuning.

Juha said:
I thought concepts were dropped from C++0x.

Yes, indeed. But C++0x will still use terms like
"MoveConstructible" to specify the requirements of std library
templates. For example, when defining std::swap:

template<class T> void swap(T& a, T& b);
Requires: Type T shall be MoveConstructible and MoveAssignable.
Effects: Exchanges values stored in two locations.

See
http://www.open-std.org/JTC1/sc22/WG21/docs/papers/2010/n3035.pdf
The term MoveConstructible is defined in Table 33:

Table 33 - MoveConstructible requirements [moveconstructible]
Expression Post-condition
T t(rv) t is equivalent to the value of rv before the construction

So now I wonder which of those four types are MoveConstructible:

typedef int T1;
typedef const int T2;
typedef std::unique_ptr<int> T3;
typedef const std::unique_ptr<int> T4;

In my opinion, T1, T2, and T3. Being CopyConstructible is sufficient
for the first two, and T3 has a move constructor.

T4 has a deleted copy constructor, which should stop it from being
copied. The constness would stop it from being cast to unique_ptr&&,
so it can't be moved either.

I would imagine T4 could still be constructed from an rvalue reference.
It's the constructed FROM part that could not be constant. Once T4 were
move constructed though you wouldn't be able to use it in the move
construction of another object.
 
N

Niels Dekker - no reply address

So now I wonder which of those four types are MoveConstructible:
Bo said:
In my opinion, T1, T2, and T3. Being CopyConstructible is sufficient
for the first two, and T3 has a move constructor.

T4 has a deleted copy constructor, which should stop it from being
copied. The constness would stop it from being cast to unique_ptr&&,
so it can't be moved either.

Noah said:
I would imagine T4 could still be constructed from an rvalue
reference. It's the constructed FROM part that could not be constant.
Once T4 were move constructed though you wouldn't be able to use it
in the move construction of another object.

Thanks, Bo and Noah.

So I guess all of us agree that T1, T2, and T3 are MoveConstructible. While
whether or not T4 (const std::unique_ptr<int>) is considered as a
MoveConstructible type depends on one's point of view.

Personally I don't think "const std::unique_ptr<int>" should be
MoveConstructible. But of course, eventually it's just a matter of
definition. And the C++0x definition of MoveConstructible may still change
one way or the other (LWG issue #1309).

Kind regards,

Niels
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top