STL container of auto_ptr

Discussion in 'C++' started by Boston, Jan 31, 2005.

  1. Boston

    Boston Guest

    my version of the STL has the following documentation:

    You can pass an auto_ptr<Type> object by value as an argument to a function
    call. You can return such an object by value as well. Both operations depend
    on the implicit construction of intermediate objects of class
    auto_ptr<Type>::auto_ptr_ref<Other>, by various subtle conversion rules. You
    cannot, however, reliably manage a sequence of auto_ptr<Type> objects with a
    Standard Template Library container.

    Is this restriction against having, say, a vector of auto_ptr normal? If
    so, why?
    Boston, Jan 31, 2005
    #1
    1. Advertising

  2. * Boston:
    >
    > Is this restriction against having, say, a vector of auto_ptr normal?


    It's in the standard, if that's what you're asking.


    > If so, why?


    Technically because a std:.atuo_ptr is not a copyable object. Standard
    containers require copyable objects. They copy things around.

    --
    A: Because it messes up the order in which people normally read text.
    Q: Why is it such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?
    Alf P. Steinbach, Jan 31, 2005
    #2
    1. Advertising

  3. Boston

    Boston Guest

    "Alf P. Steinbach" <> wrote in message
    news:...
    >* Boston:
    >>
    >> Is this restriction against having, say, a vector of auto_ptr normal?

    >
    > It's in the standard, if that's what you're asking.
    >
    >
    >> If so, why?

    >
    > Technically because a std:.atuo_ptr is not a copyable object. Standard
    > containers require copyable objects. They copy things around.


    Ah, because if you copy the auto_ptr, the source sets its ptr to NULL,
    therefore it couldn't be const&. I understand now, thanks.
    Boston, Jan 31, 2005
    #3
    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. Maitre Bart
    Replies:
    2
    Views:
    507
    Maitre Bart
    Feb 11, 2004
  2. Siemel Naran

    auto_ptr<Derived> to auto_ptr<Base>

    Siemel Naran, Jan 10, 2005, in forum: C++
    Replies:
    2
    Views:
    1,529
    Dave Rahardja
    Jan 11, 2005
  3. Replies:
    4
    Views:
    776
    Daniel T.
    Feb 16, 2006
  4. wolverine
    Replies:
    2
    Views:
    434
    Marcus Kwok
    Jul 24, 2006
  5. Sousuke
    Replies:
    9
    Views:
    1,119
    Bart van Ingen Schenau
    Mar 16, 2010
Loading...

Share This Page