1 Aug 01:22
shared_ptr, pimpl, reference semantics, and const correctness
Braddock Gaskill <braddock <at> braddock.com>
2007-07-31 23:22:40 GMT
2007-07-31 23:22:40 GMT
I am continuing work on a futures library for boost. future objects (as
currently considered by the C++ standards committee, in particular Peter
Dimov's proposal) have reference semantics, like many pimpl types.
I have some burning questions about const correctness.
Hypothetical reference-semantic example:
future f1;
future f2 = f1; //f2 refers to the same underlying object as f1
f2.set(42); //do something
assert(f1.get() == 42); // see, same underlying object
This is roughly equivalent to:
boost::shared_ptr<future_impl> f1;
boost::shared_ptr<future_impl> f2 = f1;
A std::vector<T>::iterator is an example of another type with reference
semantics.
So, say I have a simple future class:
class future_impl {
public:
bool get() const {return value_;}
void set(bool value) {value_ = value;}
private:
bool value_;
};
(Continue reading)
RSS Feed