Re: CopyConstructible requirement for standard library containers

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • subramanian100in@yahoo.com, India

    #1

    Re: CopyConstructible requirement for standard library containers

    * James Kanze <james.ka...@gm ail.comwrote:

    Suppose I have kept the copy ctor of the element type T as 'explicit'.
    Then, can I say that T is still CopyConstructib le ?

    Only if the implementation of the particular standard library uses
    copy-initialization on some container(vecto r in this case) operations,
    then those operations cannot be performed. Am I correct ?

    Kindly clarify.

    Thanks
    V.Subramanian
  • James Kanze

    #2
    Re: CopyConstructib le requirement for standard library containers

    On Sep 30, 8:27 am, "subramanian10. ..@yahoo.com, India"
    <subramanian10. ..@yahoo.comwro te:
    * James Kanze <james.ka...@gm ail.comwrote:
    Suppose I have kept the copy ctor of the element type T as 'explicit'.
    Then, can I say that T is still CopyConstructib le ?
    Apparently, according to the text in the standard. I wouldn't
    declare a copy constructor explicit, however---I'm not sure what
    that means, or even what it should mean, logically.
    Only if the implementation of the particular standard library
    uses copy-initialization on some container(vecto r in this
    case) operations, then those operations cannot be performed.
    Am I correct ?
    I'm not sure what you're trying to say, but if I understand
    explicit copy constructors correctly, copy initialization isn't
    allowed if the copy constructor is explicit. In practice,
    however, I don't think it's an issue, since the objects are
    passed by reference, and normally "copied" by using an explicit
    invocation of placement new (since allocation and initialization
    are separated), which is direct initialization.

    (BTW: I wouldn't worry about these sort of things unless I were
    actually writing a compiler. They just don't affect real code,
    and there are a lot of more important issues to be concerned
    with.)

    --
    James Kanze (GABI Software) email:james.kan ze@gmail.com
    Conseils en informatique orientée objet/
    Beratung in objektorientier ter Datenverarbeitu ng
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

    Comment

    • Pete Becker

      #3
      Re: CopyConstructib le requirement for standard library containers

      On 2008-09-30 05:59:23 -0400, James Kanze <james.kanze@gm ail.comsaid:
      On Sep 30, 8:27 am, "subramanian10. ..@yahoo.com, India"
      <subramanian10. ..@yahoo.comwro te:
      >* James Kanze <james.ka...@gm ail.comwrote:
      >
      >Suppose I have kept the copy ctor of the element type T as 'explicit'.
      >Then, can I say that T is still CopyConstructib le ?
      >
      Apparently, according to the text in the standard. I wouldn't
      declare a copy constructor explicit, however---I'm not sure what
      that means, or even what it should mean, logically.
      One implication is this:

      T t0;
      T t1(t0); // OK: explicit copy construction
      T t2 = t0; // error: implicit copy construction

      And that's a very good reason not to do it.

      --
      Pete
      Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
      Standard C++ Library Extensions: a Tutorial and Reference
      (www.petebecker.com/tr1book)

      Comment

      • James Kanze

        #4
        Re: CopyConstructib le requirement for standard library containers

        On Sep 30, 12:51 pm, Pete Becker <p...@versatile coding.comwrote :
        On 2008-09-30 05:59:23 -0400, James Kanze <james.ka...@gm ail.comsaid:
        On Sep 30, 8:27 am, "subramanian10. ..@yahoo.com, India"
        <subramanian10. ..@yahoo.comwro te:
        * James Kanze <james.ka...@gm ail.comwrote:
        Suppose I have kept the copy ctor of the element type T as
        'explicit'. Then, can I say that T is still
        CopyConstructib le ?
        Apparently, according to the text in the standard. I
        wouldn't declare a copy constructor explicit, however---I'm
        not sure what that means, or even what it should mean,
        logically.
        One implication is this:
        T t0;
        T t1(t0); // OK: explicit copy construction
        T t2 = t0; // error: implicit copy construction
        And that's a very good reason not to do it.
        That's what I understand as well. But only as a result of some
        discussions in the newsgroups. This means that you can't pass
        objects with explicit copy constructors to functions, or return
        them from functions, which (IMHO) pretty much makes copying
        useless (or irrelevant)---perhaps it would make sense if you
        only want to support copy so that you can implement some form of
        generic clone function. But even that seems exoteric enough
        that I wouldn't use it.

        It also means, of course, that an implementation of the standard
        library cannot pass the instantiation type by value, or return
        it, since the requirements are only that the expression T(t) is
        legal, and this is the case even if the copy constructor is
        explicit.

        --
        James Kanze (GABI Software) email:james.kan ze@gmail.com
        Conseils en informatique orientée objet/
        Beratung in objektorientier ter Datenverarbeitu ng
        9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

        Comment

        Working...