|
Boost : |
Subject: Re: [boost] [serialization] Proposal: make 'version' trait (and others)enable_if-friendly
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2012-12-06 01:20:21
On Thu, Dec 6, 2012 at 10:03 AM, Robert Ramey <ramey_at_[hidden]> wrote:
> 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.
FWIW, the similar approach (with an additional template parameter for
SFINAE-based dispatch) is used in Boost.Phoenix, Boost.Proto and
probably elsewhere and is described here:
With the right use (as described at the linked page) I expect it to be
nearly as fast as the regular specialization.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk