visual c++ - How do I swap an MFC CString? -


ok, i'm sold on copy-and-swap idiom , think know how implement it.

however, or codebase uses mfc's cstring class string , ain't gonna change.

since swap must (should???) nothrow, cannot do

std::swap(this->my_cstring, rhs.my_cstring); 

since create temporary cstring object may throw. (plus inefficient.)

so i'm left? should add try-catch? should allow (well, extremely rare) out of memory condition raise exception , make swap fail?

looking @ cstrings implementation, doesn't seem there's member or function allows swapping ...

self-answer:

after looking cstring more closely, appears due fact cstring reference counted string implementation, swapping via std::swap "99%" exception safe because happens reference count increments , decrements.

it's "99%" safe, when cstring object islocked, copy.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -