Boost logo

Boost :

From: Robert Ramey (ramey_at_[hidden])
Date: 2003-11-24 09:50:03


>No, I get the same error message. And no wonder: *this* serialization is not
>causing ambiguity, the ambiguity is between global 'serialization'
>functions.

>Can I ask why the trick with third argument is needed at all? The comment
>says it's workaround for lack of 'Partial Template Specialization'. Hmm...
>are you sure you're not workarounding lack of partial template ordering on
>some compilers.

>E.g. if I have the following set

>template<class A, class T>
>void serialize(A&, T&, unsigned) { /* forward to class method */ }

>template<class A, class K, class V>
>void serialize(A&, std::map<K, V>&, unsigned) { /* do something smart */ }

>struct B : public std::map<int, int> {}

>template<class A>
>void serialize(A&, B&, unsigned) { /* do something even more smart */ }

>Then partial template ordering should select first version only if no other
>version can work.

The problem is there there is always another template definition that can
work.

in serialization.hpp we have

template<class Archive, class T>
inline void serialize(
    Archive & ar,
    T & t,
    const unsigned long int file_version
){
    ...
}

which is the default "fallthrough" if there is no more specific match.
If these templates were not distinguished with a different type for
file_version, function partial specialization would have to be applied
to distiguish the this template from the three above. As far as I
know, Function Template Partial Specialization is currently not
in the standard and not supported by current compilers.

So

a) we need the last argument to pass the file version.
b) it needs to be a different but convertible type to simulate
Function Template Partial Specialization

Robert Ramey


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