Re: Template-based implementation of Sutter's exception-safe operator= idiom
From: Steven E. Harris (seh_at_panix.com)
Date: 08/21/04
- Next message: tom_usenet: "Re: export (WAS: Boost Workshop at OOPSLA 2004) (WILL BE: Save Andrei)"
- Previous message: Walter: "Re: export (WAS: Boost Workshop at OOPSLA 2004) (WILL BE: Save Andrei)"
- In reply to: David Abrahams: "Re: Template-based implementation of Sutter's exception-safe operator= idiom"
- Next in thread: James Hopkin: "Re: Template-based implementation of Sutter's exception-safe operator= idiom"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 20 Aug 2004 23:56:00 -0400
David Abrahams <dave@boost-consulting.com> writes:
> Any time you make assignment give the strong guarantee by copying
> and swapping, you force anyone who wants to use assignment in an
> operation which doesn't need that strong guarantee to pay for the
> unneccessary copy, which could be very expensive.
For those who do need the strong guarantee at a higher level, how do
they go about getting it? I understand the "SGI argument" about
concurrency control, but I'm missing the analogous option here to add
exception-safe "locks" at a higher level.
Take your example where a client wants an assignment followed by
push_back() to have the strong guarantee.¹ Is this a potential
solution?
// Neither compiled nor tested.
template <typename C, typename T>
C& safe_assign_push(C& dest, C const& src, T const& val)
{
C temp( src );
temp.push_back( val );
dest.swap( temp );
return dest;
}
Footnotes:
¹ http://lists.boost.org/MailArchives/boost/msg36928.php
--
Steven E. Harris
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
- Next message: tom_usenet: "Re: export (WAS: Boost Workshop at OOPSLA 2004) (WILL BE: Save Andrei)"
- Previous message: Walter: "Re: export (WAS: Boost Workshop at OOPSLA 2004) (WILL BE: Save Andrei)"
- In reply to: David Abrahams: "Re: Template-based implementation of Sutter's exception-safe operator= idiom"
- Next in thread: James Hopkin: "Re: Template-based implementation of Sutter's exception-safe operator= idiom"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|