[BUG]? explicit specialization of templates

  • Thread starter Thread starter Thomas Barnet-Lamb
  • Start date Start date
T

Thomas Barnet-Lamb

I have a query concerning the handling of explicit specializations.
Essentially, I want to know whether it is legal to take a template
like
template<class X> typename X::A Foo(typename X::B, typename X::C)

and specialise it in the case X takes some particular value, such as:
template<> typename Bar::A Foo<Bar>(typename Bar::B, typename Bar::C)

Here is a complete example of what I am trying to do
-------------------------------------------------
template<class linktype> typename linktype::mychildset&
GetCList(typename linktype::parent&,linktype* =0);

struct UniqueID
{
typedef int mychildset;
typedef int parent;
};

int k;

template<> UniqueID::mychildset& GetCList<UniqueID>(UniqueID::parent&
par,UniqueID*)
{
return k;
}

int main()
{
return 0;
}

-------------------------------------------------

..NET 2003 will not compile this code, giving the error message
"explicit specialization; 'UniqueID::mychildset
&GetCList<UniqueID>(UniqueID::parent &,UniqueID *)' is not a
specialization of a function template", whereas the original .NET
accepted it. I was wondering whether this was due to enhanced
standards conformance in '03, or whether it might have some other
cause (e.g. a compiler bug). (BTW, I tried the code on
www.comeaucomputing.com, which accepted it.) Any information
gratefully recieved!

Best,

Thomas Barnet-Lamb
Lionhead Studios Ltd.
www.lionhead.com
 
Thomas Barnet-Lamb said:
[...]
template<class linktype> typename linktype::mychildset&
GetCList(typename linktype::parent&,linktype* =0);

struct UniqueID
{
typedef int mychildset;
typedef int parent;
};

int k;

template<> UniqueID::mychildset& GetCList<UniqueID>(UniqueID::parent&
par,UniqueID*)
{
return k;
}

int main()
{
return 0;
}
[...]


Comeau is happy with your code:

--8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<--

Thank you for testing your code with Comeau C/C++!
Tell others about http://www.comeaucomputing.com/tryitout !

Your Comeau C/C++ test results are as follows:

Comeau C/C++ 4.3.1 (Mar 1 2003 20:09:34) for ONLINE_EVALUATION_BETA1
Copyright 1988-2003 Comeau Computing. All rights reserved.
MODE:strict errors C++

In strict mode, with -tused, Compile succeeded (but remember, the Comeau
online compiler does not link).

--8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<--

Schobi

--
(e-mail address removed) is never read
I'm Schobi at suespammers org

"My hair style calls into immediate question all my judgements."
Scott Meyers

(http://www.google.de/[email protected])
 
Back
Top