
On Thu, Dec 6, 2012 at 10:03 AM, Robert Ramey <ramey@rrsd.com> 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: http://www.boost.org/doc/libs/release/doc/html/proto/appendices.html#boost_p... With the right use (as described at the linked page) I expect it to be nearly as fast as the regular specialization.