J
Jonathan Turkanis
[I just posted this to comp.lang.c++.moderated, but I'm impatient]
Hi All,
The simple test program at the end of this message defines a class template
foo with a member function bar implemented by delegating to a static member
function of a specialization of the class template bar_impl, nested within foo.
The template bar_impl is partially specialized outside of foo. My question is
which specialization should be selected: the primary template or the partial
specialization. Or does the program exhibit undefined behavior?
Here are the results for several recent compilers:
* partial specialization is selected - VC7.1-8.0(beta), Comeau 4.3.3, Intel
8.0 for Windows
* primary template is selected: GCC 3.2-3.4.1
* fails to compile: CodeWarrior 8.3-9.2(eval), DigitalMars 8.38n
Best Regards,
Jonathan
----
#include <iostream>
template<typename T>
struct foo {
template<typename U, typename V>
struct bar_impl {
static void bar() { std:: cout << "unspecialized\n"; }
};
void bar()
{
typedef bar_impl<foo<T>, int> type;
type::bar();
}
};
template<typename T>
template<typename V>
struct foo<T>::bar_impl<foo<T>, V> {
static void bar() { std::cout << "specialized\n"; }
};
int main()
{
foo<int> f;
f.bar();
}
Hi All,
The simple test program at the end of this message defines a class template
foo with a member function bar implemented by delegating to a static member
function of a specialization of the class template bar_impl, nested within foo.
The template bar_impl is partially specialized outside of foo. My question is
which specialization should be selected: the primary template or the partial
specialization. Or does the program exhibit undefined behavior?
Here are the results for several recent compilers:
* partial specialization is selected - VC7.1-8.0(beta), Comeau 4.3.3, Intel
8.0 for Windows
* primary template is selected: GCC 3.2-3.4.1
* fails to compile: CodeWarrior 8.3-9.2(eval), DigitalMars 8.38n
Best Regards,
Jonathan
----
#include <iostream>
template<typename T>
struct foo {
template<typename U, typename V>
struct bar_impl {
static void bar() { std:: cout << "unspecialized\n"; }
};
void bar()
{
typedef bar_impl<foo<T>, int> type;
type::bar();
}
};
template<typename T>
template<typename V>
struct foo<T>::bar_impl<foo<T>, V> {
static void bar() { std::cout << "specialized\n"; }
};
int main()
{
foo<int> f;
f.bar();
}