Boost logo

Boost :

Subject: Re: [boost] [serialization] Proposal: make 'version' trait (and others)enable_if-friendly
From: Robert Ramey (ramey_at_[hidden])
Date: 2012-12-06 01:03:54


Gabriel Redner wrote:
> I have recently run up against a limitation of the serialization
> library in terms of specializing the 'version' trait. Fortunately, I
> believe the issue has a simple workaround which I don't believe will
> break existing code.
>
> In general, one can change the version of a serialized class by
> specializing the 'version' template class:
> ==============================
> template <typename T>
> struct version
> {
> BOOST_STATIC_CONSTANT(unsigned int, value = 0);
> };
> ...
> template <>
> struct version<MyType>
> {
> BOOST_STATIC_CONSTANT(unsigned int, value = 1);
> };
> ==============================
>
> However, this approach does not work if 'MyType' is of the form (see
> [1]): ==============================
> template <typename T>
> struct Foo
> {
> struct MyType
> {
> int data1;
> };
> };
>
> template <typename T>
> struct version<Foo<T>::MyType> // ERROR
> {
> BOOST_STATIC_CONSTANT(unsigned int, value = 1);
> };
> ==============================
> It's not possible for the compiler to deduce the enclosing type, so
> this doesn't work.

Hmm - doesn't the fillowing work? - for each T used

template <>
struct version<Foo<t>::MyType>{
    BOOST_STATIC_CONSTANT(unsigned int, value = 1);
};

I understand it might be a little more tedious and not that clever
but it's much, much, much less time consuming to understand, documment,
explain
and support. Your suggestion is clever - but I just don't think it's
cost effective.

Robert Ramey

>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk