Four types - which ones are MoveConstructible?

Discussion in 'C++' started by Niels Dekker - no reply address, Feb 23, 2010.

  1. 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.
    --
    Niels Dekker
    http://www.xs4all.nl/~nd/dekkerware
    Scientific programmer at LKEB, Leiden University Medical Center
    Niels Dekker - no reply address, Feb 23, 2010
    #1
    1. Advertising

  2. >> 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/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
    --
    Niels Dekker
    http://www.xs4all.nl/~nd/dekkerware
    Scientific programmer at LKEB, Leiden University Medical Center
    Niels Dekker - no reply address, Feb 23, 2010
    #2
    1. Advertising

  3. Niels Dekker - no reply address

    Bo Persson Guest

    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/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
    Bo Persson, Feb 23, 2010
    #3
  4. Niels Dekker - no reply address

    Noah Roberts Guest

    In article <>, 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/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.


    --
    http://crazyeddiecpp.blogspot.com
    Noah Roberts, Feb 23, 2010
    #4
  5. >> 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
    Niels Dekker - no reply address, Feb 24, 2010
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Manish
    Replies:
    1
    Views:
    632
    Steve C. Orr [MVP, MCSD]
    Nov 17, 2003
  2. -
    Replies:
    4
    Views:
    327
    Owen Jacobson
    Jul 10, 2005
  3. Hendrik Maryns
    Replies:
    18
    Views:
    1,398
  4. John Nagle
    Replies:
    1
    Views:
    350
    Jan Claeys
    Dec 17, 2007
  5. Tim Zych
    Replies:
    2
    Views:
    168
    Tim Zych
    Nov 28, 2005
Loading...

Share This Page