|
Boost : |
From: Vladimir Prus (ghost_at_[hidden])
Date: 2003-11-25 02:20:45
Robert Ramey wrote:
>>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
> ){
> ...
> }
In fact, the first overload I've mentioned is precisely this predefined one
from serialization lib. That's why there's /* forward to class method */
comment in it's body. Sorry for not saying this explicitly, though.
> 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.
Why? If all three can be called, partial template ordering will come into
play, and the third one will be used as the most specialized. I've created
a small example to illustrate this, and it's at
http://zigzag.cs.msu.su:7813/overload.cpp
gcc has no problems and selects the third function. I'm still missing what's
the problem.
- Volodya
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk