?
=?iso-8859-1?q?Erik_Wikstr=F6m?=
I'd like to create a partial specialization of a member-method of a
parameterized class which takes a parameterized argument, but I'm not
sure if it's possible or, if possible, how. The following code
demonstrates what I'd like to to:
#include <iostream>
template<class T>
struct BarA
{
void bar() { std::cout << "BarA\n"; }
};
template<class T>
struct BarB
{
void bar() { std::cout << "BarB\n"; }
};
template<class T>
struct Test
{
template<template<class U = T> class V>
void foo(V<T>& f);
};
template<class T>
template<template<class> class V>
void Test<T>::foo(V<T>& f)
{
f.bar();
}
/* A partial specialization that prepends the output of f.bar() with
"BarB: "
template<class T>
template<>
void Test<T>::foo(BarB<T> f)
{
std::cout "BarB: ";
f.bar();
}
*/
int main()
{
BarA<int> a;
BarB<int> b;
Test<int> t;
t.foo(a);
t.foo(b);
}
This should, print:
BarA
BarB: BarB
Any help appreciated.
parameterized class which takes a parameterized argument, but I'm not
sure if it's possible or, if possible, how. The following code
demonstrates what I'd like to to:
#include <iostream>
template<class T>
struct BarA
{
void bar() { std::cout << "BarA\n"; }
};
template<class T>
struct BarB
{
void bar() { std::cout << "BarB\n"; }
};
template<class T>
struct Test
{
template<template<class U = T> class V>
void foo(V<T>& f);
};
template<class T>
template<template<class> class V>
void Test<T>::foo(V<T>& f)
{
f.bar();
}
/* A partial specialization that prepends the output of f.bar() with
"BarB: "
template<class T>
template<>
void Test<T>::foo(BarB<T> f)
{
std::cout "BarB: ";
f.bar();
}
*/
int main()
{
BarA<int> a;
BarB<int> b;
Test<int> t;
t.foo(a);
t.foo(b);
}
This should, print:
BarA
BarB: BarB
Any help appreciated.