|
Boost : |
From: Dave Harris (brangdon_at_[hidden])
Date: 2002-11-22 16:07:35
In-Reply-To: <01C29013.F4F10610_at_[hidden]>
On Tue, 19 Nov 2002 21:38:09 -0800 Robert Ramey (ramey_at_[hidden]) wrote:
> How do we intialize the const member?
MyClass::MyClass( basic_iarchive &ar ) : i(load<int>(ar)) {
}
> What about version 2
MyClass::MyClass( basic_iarchive &ar ) :
i( load<int>(ar) ),
j( version(ar) = 2 ? load<int>(ar) : 0 ) {
}
In some cases it would be simpler to give up the const member:
MyClass::MyClass( basic_iarchive &ar ) {
version_type v = version(ar);
if (v < 0 || v > 2)
throw "unexpected version";
ar >> i;
if (v >= 2)
ar >> j;
}
The first 3 lines should be refactored into a single function, and it is
best to start version numbers at around 10, so the real code would be:
MyClass::MyClass( basic_iarchive &ar ) {
version_type version = version( ar, 10, 11 );
ar >> i;
if (v >= 11)
ar >> j;
}
> given the above, I never even got to the point of considering how to
> get the version number out of the stream at the right time. maybe
> it easy. I never thought about it.
OK. I'll drop it. It can probably be done without support from the core
library anyway.
-- Dave Harris
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk