Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2004-02-23 07:25:19


Peter Dimov wrote:
> David Abrahams wrote:
>>
>> Simple: specializations that follow the point of instantiation aren't
>> considered. This program exits with an error:
>>
>> template <class T>
>> int f(T) { return 1; }
>>
>> int main() { return ::f(0); }
>>
>> template <> int f(int) { return 0; }
>
> It's ill-formed, actually.

On reflection, I think I see what you are trying to illustrate, and I also
think that you are wrong.

#include <iostream>

// f.hpp

template<class T> void f(T)
{
    std::cout << "General\n";
}

// g.hpp

template<class T> void g(T t)
{
    ::f(t);
}

// X.hpp

struct X {};

/*template<>*/ void f(X)
{
    std::cout << "X-specific\n";
}

// main.cpp

int main()
{
    f( X() );
    g( X() );
}

Uncomment the /*template<>*/ to see what I mean. No order dependency.


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