Boost logo

Boost :

From: Robert Ramey (ramey_at_[hidden])
Date: 2005-10-11 17:00:04

David Abrahams wrote:
> "Robert Ramey" <ramey_at_[hidden]> writes:
>> Simon Buchan wrote:
>>> Robert Ramey wrote:
>>>> Double check that a is polymorphic - that is, that it has at least
>>>> one virtual function. Then get back to us.
>>>> Robert Ramey
>>>>> I'm guessing that is supposed to be:
>>>>> main(){
>>>>> ...
>>>>> ar.register_type<derived_one>();
>>>>> ar.register_type<derived_two>();
>>>>> base *b;
>>>>> ar & b;
>>>>> }
>>>> nope, its correct. This is a little known quirk of C++ syntax.
>>>> Your second version won't compile on the most conforming compilers.
>>> Not according to Comeau:
>>> "ComeauTest.c", line 16: error: the "template" keyword used for
>>> syntactic disambiguation may only be used within a
>>> template
>> whoops - wrong again. If ar is a template you need "ar.template"
>> other wise you shouldn't have it.
> Nope, wrong again. If ar's type X is dependent and "register_type"
> is a nested template in X, then you need "ar.template
> register_type<...>". Otherwise, you need "ar.register_type<...>"
>> From the above code it could be either. Its really annoying to me
>> to have to keep the context and provinence of a variable like "ar"
>> in my head while I'm writting.
> Guess what; you don't. If you had to know whether ar was a template
> or not, just think how impossible it would be to write generic code?

Hmmm - here is a situation that I come across:

class my_archive {

template<class Arg>
class my_templated_archive{

template<class Archive, T>
void serialize(Archive & ar, T &t, const unsigned int version){
    ar.template register_type<T>(); // ok - I think

void serialize(my_archive & ar, T &t, const unsigned int version){
    ar.template register_type<T>(); // syntax error? or not?

Truth is I can't never keep these kinds of rules straight.

Robert Ramey

Boost list run by bdawes at, gregod at, cpdaniel at, john at