Thread: auto_ptr in exception safety design

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    1,579

    auto_ptr in exception safety design

    Hello everyone,


    What I am confused is about,

    http://www.gotw.ca/gotw/059.htm

    --------------------
    Indeed, often the best way to implement the Pimpl idiom is exactly as shown in Example 4 above, by using a pointer (in order to take advantage of nonthrowing operations) while still wrapping the dynamic resource safely in an auto_ptr manager object. Just remember that now your object must provide its own copy construction and assignment with the right semantics for the auto_ptr member, or disable them if copy construction and assignment don't make sense for the class.
    --------------------

    1. What means "the right semantics for the auto_ptr member"?

    2. "disable" means for the class, copy construction and assignment are not needed? Curious. Never thought of a class which does not need that two basic functions. :-)


    thanks in advance,
    George

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    1) Means it must clone the implementation to perform a deep-copy.

    2) There's lots of them.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thanks CornedBee,


    I understand what is deep copy. But I am not quite sure about what do you mean "clone the implementation".

    Do you mean copy the object pointed by auto_ptr, other than copy the auto_ptr member itself?

    Quote Originally Posted by CornedBee View Post
    1) Means it must clone the implementation to perform a deep-copy.

    regards,
    George

  4. #4
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    > But I am not quite sure about what do you mean "clone the implementation".

    The only thing auto-ptr really does is delete the object it holds when it falls out of scope. It acts like a bald pointer in every other respect, so when you need separate pointers (like you would here) you have to do a deep copy. So think about the implementation for a deep copy with a bald pointer, and the phrase should make some sense.

  5. #5
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Hi citizen,


    "bald pointer" you mean raw pointer?

    Quote Originally Posted by citizen View Post
    > But I am not quite sure about what do you mean "clone the implementation".

    The only thing auto-ptr really does is delete the object it holds when it falls out of scope. It acts like a bald pointer in every other respect, so when you need separate pointers (like you would here) you have to do a deep copy. So think about the implementation for a deep copy with a bald pointer, and the phrase should make some sense.

    regards,
    George

  6. #6
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Sure, same difference.

  7. #7
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Quote Originally Posted by George2 View Post
    2. "disable" means for the class, copy construction and assignment are not needed? Curious. Never thought of a class which does not need that two basic functions. :-)
    I/O Streams are a classic example of something that should not be copyable. Singletons are another.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  8. #8
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thanks citizen and iMalc,


    Question answered.

    Quote Originally Posted by iMalc View Post
    I/O Streams are a classic example of something that should not be copyable. Singletons are another.

    regards,
    George

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Exception handling in a large project
    By EVOEx in forum C++ Programming
    Replies: 7
    Last Post: 01-25-2009, 07:33 AM
  2. exception handling
    By coletek in forum C++ Programming
    Replies: 2
    Last Post: 01-12-2009, 05:28 PM
  3. thread safety in Windows Service design
    By George2 in forum C# Programming
    Replies: 0
    Last Post: 04-14-2008, 06:25 AM
  4. Signal and exception handling
    By nts in forum C++ Programming
    Replies: 23
    Last Post: 11-15-2007, 02:36 PM
  5. Problem with the exception class in MINGW
    By indigo0086 in forum C++ Programming
    Replies: 6
    Last Post: 01-20-2007, 01:12 PM