cdmh

Joined 14 years ago

Karma
82
Submissions
32
Member since
Aug 20
technologist, software systems architect, C++ enthusiast. Creator of @smartafeed real-time social media and web data processing platform. http://smartafeed.com
View on Hacker News

Recent submissions

Comment · 13 years ago
Comment · 13 years ago
21.4.1 p6 states invalidation of iterators/references is only allowed for — as an argument to any standard library function taking a reference to non-const basic_string as an argument. — Calling non-const member functions, except operator[], at, front, back, begin, rbegin, end, and rend.

The non-const operator[] in a COW string requires making a copy of the string if the ref count > 1 which invalidates references and violates this paragraph.

Comment · 13 years ago
The class is movable already. Reference counting will allow a copy constructor or copy assignment to avoid copying the string object, just increase the reference count.
Comment · 13 years ago
COW is prohibited in C++11 Standard implementations of std::basic_string
Comment · 13 years ago
That is accurate. The object reference by immutable msg is hello_world which is mutable. If the value of hello_world changes, then the value of msg changes too. In the simple example, it won't happen, but the point is that it could, especially when multi-threaded.
Comment · 13 years ago
Hi Alex, you say I "claim[s] that objects accessed via reference to const can modify themselves". Which paragraph are you referring to? It don't see that? I'm happy to update the article to make it clearer. Thanks, Craig
Comment · 13 years ago
I'm toying with implementing O(1) copies by using a reference counted pointer to basic_string instead of storing it by value within the class. It would mean a small memory overhead and another level of indirection, but probably worth doing. Thoughts?

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton