On 2005-04-07, Victor Bazarov <v.********@comAcast.net> wrote:
Old Wolf wrote: I have a template class like this:
template<typename T, int N>
struct Foo
{
...........
};
which I have successfully specialized for some types, eg:
template<int N>
struct Foo<std::string, N>
{ ...... }
Is it possible to specialize it so that T is a std::pair<A,B>
where A and B are new template parameters?
And where would they come from? If neither A nor B are among the
original template's arguments, how is it "specializing"?
Maybe he means something like the following. It's specializing, because
std::pair<A,B> is the first argument to the template.
This compiles with gcc 3.3.5 with standards options turned up. But is it
correct ?
#include <utility>
#include <string>
template<typename T, int N> struct Foo { };
template<int N> struct Foo<std::string, N> { };
template <typename A, typename B>
struct Foo< std::pair<A,B>, 3> { void f() {} };
int main() { Foo<std::pair<int,double>, 3> x; x.f(); }
Cheers,
--
Donovan Rebbechi
http://pegasus.rutgers.edu/~elflord/