In-Reply-To: <[EMAIL PROTECTED]>
On Tue, 19 Nov 2002 21:38:09 -0800 Robert Ramey ([EMAIL PROTECTED]) 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

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Reply via email to