Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Four types - which ones are MoveConstructible?

Reply
Thread Tools

Four types - which ones are MoveConstructible?

 
 
Niels Dekker - no reply address
Guest
Posts: n/a
 
      02-23-2010
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/WG...tive.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.
--
Niels Dekker
http://www.xs4all.nl/~nd/dekkerware
Scientific programmer at LKEB, Leiden University Medical Center



 
Reply With Quote
 
 
 
 
Niels Dekker - no reply address
Guest
Posts: n/a
 
      02-23-2010
>> 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 Nieminen wrote:
> 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/WG...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
--
Niels Dekker
http://www.xs4all.nl/~nd/dekkerware
Scientific programmer at LKEB, Leiden University Medical Center


 
Reply With Quote
 
 
 
 
Bo Persson
Guest
Posts: n/a
 
      02-23-2010
Niels Dekker - no reply address wrote:
>>> 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 Nieminen wrote:
>> 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/WG...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




 
Reply With Quote
 
Noah Roberts
Guest
Posts: n/a
 
      02-23-2010
In article <(E-Mail Removed)>, http://www.velocityreviews.com/forums/(E-Mail Removed) says...
>
> Niels Dekker - no reply address wrote:
> >>> 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 Nieminen wrote:
> >> 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/WG...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.


--
http://crazyeddiecpp.blogspot.com
 
Reply With Quote
 
Niels Dekker - no reply address
Guest
Posts: n/a
 
      02-24-2010
>> 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;


Bo Persson wrote:
> 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 Roberts wrote:
> 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

--
Niels Dekker
http://www.xs4all.nl/~nd/dekkerware
Scientific programmer at LKEB, Leiden University Medical Center


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
New Canon EIS mirrorless system - Four Thirds, but not Four Thirds! Bruce Digital Photography 31 09-25-2010 05:38 AM
DVD recorders/burners with hard disks - which ones allow editing before burning to DVD-R? Dan E DVD Video 2 06-06-2005 03:05 PM
Hard drives--Are big ones more delicate than smaller ones? PowerPost2000 Computer Support 2 03-01-2005 10:30 PM
The Best Personal Firewalls - Which Ones? wm2004 Computer Security 2 01-30-2004 05:22 PM
web album that lets you select number of photos and specifically which ones Ray Digital Photography 0 08-05-2003 03:38 PM



Advertisments