Hi
Template partial specialization always seems like a fairly
straightforward concept - until I try to do it :).
I am trying to implement the input sequence type (from Stroustrup
section 18.3.1, 'Iseq'). I want the version for containers that he
gives, but also to provide a specialization for construction from a
pair<It,It> (eg because that is returned by equal_range()). [Iseq is
actually implemented as a pair<> - but that is a separate issue.]
Here is what I have:
// ---------------------------------------------------------------
// A type representing an 'input sequence':
template<class In>
class Iseq : public pair<In, In> {
public:
Iseq(In i1, In i2) : pair<In, In>(i1, i2) {}
bool IsEmpty() const { return first == second; }
};
// A helper function to make one (since ctors can't
// infer the types of template arguments):
template<class C>
Iseq<typename C::iterator> iseq(C& c) {
return Iseq<typename C::iterator>(c.begin(), c.end());
}
// A specialisation for pairs:
template<class T>
Iseq<T> iseq_p(pair<T, T> p) {
return Iseq<T>(p.first, p.second);
}
// An overloaded version of STL find() taking an input sequence:
template<class In, class T>
In find(Iseq<In> r, const T& v) { return find(r.first, r.second, v);
}
// And finally, a client:
Iseq<MMIt> FindMemberships(UserReference member) {
return iseq_p( memberships_.equal_range(member) );
}
MMIt MemberAt(UserReference member, Path path) {
return find(FindMemberships(member), make_pair(member,
path));
}
// ---------------------------------------------------------------
This works. But only because I have renamed my 'specialisation' of
iseq() for pairs to iseq_p. I don't want to (and don't think I have
to) do that, for this or any further specialisations. Simply replacing
'iseq_p' with 'iseq' in the above causes the compiler (gcc2.95) to
attempt to use the first definition of iseq, and it (rightly)
complains that pair<>::iterator does not exist. What mistake am I
making?
[ As an aside: Stroustrup makes Iseq<T> publicly inherit pair<T,T>. I
might be inclined to make it privately inherit it - surely no client
wants to use the pair<> interface? ] 17 6748
Paul MG wrote: Hi
Template partial specialization always seems like a fairly straightforward concept - until I try to do it :).
I am trying to implement the input sequence type (from Stroustrup section 18.3.1, 'Iseq'). I want the version for containers that he gives, but also to provide a specialization for construction from a pair<It,It> (eg because that is returned by equal_range()). [Iseq is actually implemented as a pair<> - but that is a separate issue.]
Here is what I have:
// ---------------------------------------------------------------
// A type representing an 'input sequence':
template<class In> class Iseq : public pair<In, In> { public: Iseq(In i1, In i2) : pair<In, In>(i1, i2) {} bool IsEmpty() const { return first == second; } };
// A helper function to make one (since ctors can't // infer the types of template arguments):
template<class C> Iseq<typename C::iterator> iseq(C& c) { return Iseq<typename C::iterator>(c.begin(), c.end()); }
// A specialisation for pairs:
template<class T> Iseq<T> iseq_p(pair<T, T> p) { return Iseq<T>(p.first, p.second); }
this is not specialisation of class Iseq for pairs if u replace iseq_p
with Iseq. it is a function.
the specialisation is:
template <>
template <class T>
class Iseq<pair<T,T> >
{
public:
Iseq(pair<T,T> pairv): pair<T,T>(pairv.first, pairv.second)
};
this is not the solution to yr problem though, but it will give u the
basic idea.
// An overloaded version of STL find() taking an input sequence:
template<class In, class T> In find(Iseq<In> r, const T& v) { return find(r.first, r.second, v); }
// And finally, a client:
Iseq<MMIt> FindMemberships(UserReference member) { return iseq_p( memberships_.equal_range(member) ); } MMIt MemberAt(UserReference member, Path path) { return find(FindMemberships(member), make_pair(member, path)); }
// ---------------------------------------------------------------
This works. But only because I have renamed my 'specialisation' of iseq() for pairs to iseq_p. I don't want to (and don't think I have to) do that, for this or any further specialisations. Simply replacing 'iseq_p' with 'iseq' in the above causes the compiler (gcc2.95) to attempt to use the first definition of iseq, and it (rightly) complains that pair<>::iterator does not exist. What mistake am I making?
[ As an aside: Stroustrup makes Iseq<T> publicly inherit pair<T,T>. I might be inclined to make it privately inherit it - surely no client wants to use the pair<> interface? ]
Paul MG wrote: Hi
Template partial specialization always seems like a fairly straightforward concept - until I try to do it :).
I am trying to implement the input sequence type (from Stroustrup section 18.3.1, 'Iseq'). I want the version for containers that he gives, but also to provide a specialization for construction from a pair<It,It> (eg because that is returned by equal_range()). [Iseq is actually implemented as a pair<> - but that is a separate issue.]
Here is what I have:
// ---------------------------------------------------------------
// A type representing an 'input sequence':
template<class In> class Iseq : public pair<In, In> { public: Iseq(In i1, In i2) : pair<In, In>(i1, i2) {} bool IsEmpty() const { return first == second; } };
// A helper function to make one (since ctors can't // infer the types of template arguments):
template<class C> Iseq<typename C::iterator> iseq(C& c) { return Iseq<typename C::iterator>(c.begin(), c.end()); }
// A specialisation for pairs:
template<class T> Iseq<T> iseq_p(pair<T, T> p) { return Iseq<T>(p.first, p.second); }
this is not specialisation of class Iseq for pairs if u replace iseq_p
with Iseq. it is a function.
the specialisation is:
template <>
template <class T>
class Iseq<pair<T,T> >
{
public:
Iseq(pair<T,T> pairv): pair<T,T>(pairv.first, pairv.second)
};
this is not the solution to yr problem though, but it will give u the
basic idea.
// An overloaded version of STL find() taking an input sequence:
template<class In, class T> In find(Iseq<In> r, const T& v) { return find(r.first, r.second, v); }
// And finally, a client:
Iseq<MMIt> FindMemberships(UserReference member) { return iseq_p( memberships_.equal_range(member) ); } MMIt MemberAt(UserReference member, Path path) { return find(FindMemberships(member), make_pair(member, path)); }
// ---------------------------------------------------------------
This works. But only because I have renamed my 'specialisation' of iseq() for pairs to iseq_p. I don't want to (and don't think I have to) do that, for this or any further specialisations. Simply replacing 'iseq_p' with 'iseq' in the above causes the compiler (gcc2.95) to attempt to use the first definition of iseq, and it (rightly) complains that pair<>::iterator does not exist. What mistake am I making?
[ As an aside: Stroustrup makes Iseq<T> publicly inherit pair<T,T>. I might be inclined to make it privately inherit it - surely no client wants to use the pair<> interface? ]
> > // A specialisation for pairs: template<class T> Iseq<T> iseq_p(pair<T, T> p) { return Iseq<T>(p.first, p.second); }
That isn't a specialization, but a function overload.
Hmmmm... so if you define a templated function
template<class T> iseq(T);
and then later add
template<> iseq(SomeType);
then the second is a function overload not a specialization? That is
what I am trying to do (I think). Its just that when SomeType is
'pair<T1,T2>', you need to specify T1 and T2 too so you can't just say
'template<>' like I have here... Simply replacing 'iseq_p' with 'iseq' in the above causes the compiler (gcc2.95) to attempt to use the first definition of iseq, and it (rightly) complains that pair<>::iterator does not exist. What mistake am I making?
Using a 3 year old compiler. Upgrade to gcc 3.0+ and it will work fine. The missing feature is "partial template function ordering", which knows how to choose the best match amongst different template specializations that match a function call.
I have other places in the code where it correctly chooses the 'most
specific' implementation of a templated function just like what I
outlined above. So I don't think it is total lack of compiler support
- it could be a failure to support something in this specific case I
suppose, yes. [ As an aside: Stroustrup makes Iseq<T> publicly inherit pair<T,T>. I might be inclined to make it privately inherit it - surely no client wants to use the pair<> interface? ]
Your find overload does...
Only cos I copied it out of Stroustrup. I would have preferred to
inherit Iseq<T> privately from pair<T,T>, and give it accessors
begin() and end() which return pair<T,T>::first and pair<T,T>::second.
But I am unwilling to assume that I am cleverer than Stroustrup :).
Someone let me know my error?
cheers!
pmg
> > // A specialisation for pairs: template<class T> Iseq<T> iseq_p(pair<T, T> p) { return Iseq<T>(p.first, p.second); } this is not specialisation of class Iseq for pairs if u replace iseq_p with Iseq. it is a function.
['with iseq' is what I meant, I presume what you meant too]
i think what i was trying to do was create a specialisation of the
template function iseq, not the class Iseq (see my response to tom).
are you suggesting then that i am trying the wrong approach?
the specialisation is:
template <> template <class T> class Iseq<pair<T,T> > { public: Iseq(pair<T,T> pairv): pair<T,T>(pairv.first, pairv.second) };
this is not the solution to yr problem though, but it will give u the basic idea.
Never seen that 'template<> template<class T>' thing before.
Interesting. So the 'template<>' shows that this is a partial
specialisation, the 'class Iseq<pair<T, T> >' says that it is a
specialisation for pairs, and the 'template <class T>' bit in between
states that pair<T,T> itself requires a template parameter T. Is that
right?
Anyway, now I can do this then:
pair<It, It> myRange = getRange();
find(ISeq(myRange), someValue);
?
Would rather specialise/overload the factory function iseq() than the
class itself though, if only because otherwise it is unsymmetrical
with the other case of constructing off a collection (which uses the
factory function so that the template type can be inferred):
vector<Foo> foos = getFoos();
find(iseq(foos), someValue);
// which is just neater than:
// find(ISeq<Foo::iterator>(foos), someValue));
Hope this makes sense, thanks for your input,
cheers
pmg Hmmmm... so if you define a templated function
template<class T> iseq(T);
and then later add
template<> iseq(SomeType);
then the second is a function overload not a specialization?
this is template function specialisation.
That is what I am trying to do (I think). Its just that when SomeType is 'pair<T1,T2>', you need to specify T1 and T2 too so you can't just say 'template<>' like I have here...
yes, u shud write:
template<> template <typename T1, typename T2> iseq(pair<T1, T2>)
sorry...i messed up a bit....
what i meant is:
template <> is not partial specialization, it is fully specialisation :-))
On 25 Jun 2003 01:22:37 -0700, pa****@digitalbrain.com (Paul MG)
wrote: > // A specialisation for pairs: > > template<class T> > Iseq<T> iseq_p(pair<T, T> p) { > return Iseq<T>(p.first, p.second); > } That isn't a specialization, but a function overload.
Hmmmm... so if you define a templated function
template<class T> iseq(T);
and then later add
template<> iseq(SomeType);
then the second is a function overload not a specialization?
It is a specialization (ignoring the missing return type). It is
better to write it as:
template<>
Iseq<WhateverType> iseq<SomeType>(SomeType c);
so that the compiler knows with overload of iseq you are specializing
(by matching the bit between the <> with the signatures), if there is
more than one possibility (*).
The overload version would be:
Iseq<SomeType> iseq(SomeType);
That iswhat I am trying to do (I think). Its just that when SomeType is 'pair<T1,T2>', you need to specify T1 and T2 too so you can't just say 'template<>' like I have here...
Ahh, so you are trying to partially specialize a function template.
That isn't possible in C++, so you have to use overloading. If partial
specialization existed, the syntax would be analogous to class partial
specialization:
template<class T>
Iseq<T> iseq<pair<T, T> >(pair<T, T> p) {
return Iseq<T>(p.first, p.second);
}
but if you feed that to your compiler, you'll get an error. In any
case, partial specialization wouldn't really make sense even if it did
exist, since you're changing the return type from T::iterator to, in
effect, T::first_type.
What you have is two completely different template functions that are
related only by the fact that they share the same name. >Simply replacing >'iseq_p' with 'iseq' in the above causes the compiler (gcc2.95) to >attempt to use the first definition of iseq, and it (rightly) >complains that pair<>::iterator does not exist. What mistake am I >making? Using a 3 year old compiler. Upgrade to gcc 3.0+ and it will work fine. The missing feature is "partial template function ordering", which knows how to choose the best match amongst different template specializations that match a function call.
I have other places in the code where it correctly chooses the 'most specific' implementation of a templated function just like what I outlined above. So I don't think it is total lack of compiler support - it could be a failure to support something in this specific case I suppose, yes.
I just tried it in g++, and it looks like the problem might be that
g++ doesn't properly implement SFINAE (substitution failure is not an
error), instead making the substitution of the pair into the first
overload an error, when all it should do is discard it from the
overload list.
So in fact, partial ordering doesn't directly affect this issue, since
the first overload should be eliminated before the compiler gets to
partial ordering. >[ As an aside: Stroustrup makes Iseq<T> publicly inherit pair<T,T>. I >might be inclined to make it privately inherit it - surely no client >wants to use the pair<> interface? ]
Your find overload does...
Only cos I copied it out of Stroustrup. I would have preferred to inherit Iseq<T> privately from pair<T,T>, and give it accessors begin() and end() which return pair<T,T>::first and pair<T,T>::second.
But I am unwilling to assume that I am cleverer than Stroustrup :). Someone let me know my error?
I suppose Iseq doesn't need accessors in the same way that pair
doesn't need them. It is a fundamental type that simply holds two
iterators.
However, adding accessors won't hurt anything except possibly
performance, depending on whether you return by value or reference.
Tom
On Wed, 25 Jun 2003 02:11:11 +0530, Chandra Shekhar Kumar
<ch***********@oracle.com> wrote:
Hmmmm... so if you define a templated function
template<class T> iseq(T);
and then later add
template<> iseq(SomeType);
then the second is a function overload not a specialization?
this is template function specialisation.
That is what I am trying to do (I think). Its just that when SomeType is 'pair<T1,T2>', you need to specify T1 and T2 too so you can't just say 'template<>' like I have here...
yes, u shud write:
template<> template <typename T1, typename T2> iseq(pair<T1, T2>)
What is the above supposed to be? It isn't legal code, in any case.
Tom
> template<> template <typename T1, typename T2> iseq(pair<T1, T2>)
What is the above supposed to be? It isn't legal code, in any case.
see the code below and run it, u will understand what i meant by
above...............(use a good compiler ::-))
#include <iostream>
#include <map>
using namespace std;
template<class T> h(T a) { cout << "h::" << a << endl; }
template<> template<class T1, class T2> h(pair<T1, T2>& p) { cout << "pair::"
<< p.first << ":::" << p.second << endl;}
int main()
{
h(20);
pair<int, float> p(20, 30.34);
h(p);
}
> That is what I am trying to do (I think). Its just that when SomeType is 'pair<T1,T2>', you need to specify T1 and T2 too so you can't just say 'template<>' like I have here...
Ahh, so you are trying to partially specialize a function template. That isn't possible in C++.
u r wrong....
see the code below::
#include <iostream>
#include <map>
using namespace std;
template<class T> h(T a) { cout << "h::" << a << endl; }
template<> template<class T1, class T2> h(pair<T1, T2>& p) { cout << "pair::"
<< p.first << ":::" << p.second << endl;}
int main()
{
h(20);
pair<int, float> p(20, 30.34);
h(p);
}
so , now the question is when to choose function templates, and when function
overloading.....
the limitation of function templates is that they donot scale well.
what i mean is: with the function templates having 2 or more arguments cann't
be fully specilaized.
see the code below:
#include <iostream>
#include <map>
using namespace std;
template<class T1, class T2> f(T1 a, T2 b) { cout << a << ":" << b << endl;}
//partial specialization of f......
template<class T1> f(T1 a, int b) { cout << "partial::" << a << ":" << b <<
endl;}
//fully specialisation of f.....not legal code...so commented.....
//template<> f(int a, int b) { cout << "fully:::" << a << ":" << b << endl;}
template <class T> g(T a) { cout << "g:: " << a << endl;}
//fully specialisation of g.....legal here coz g takes only one argument.....
template<> g(int a) { cout << "fully::g:::" << a << endl;}
template<class T> h(T a) { cout << "h::" << a << endl; }
//fully specialisation...same as above....:-)))
template<> template<class T1, class T2> h(pair<T1, T2>& p) { cout << "pair::"
<< p.first << ":::" << p.second << endl;}
int main()
{
f(5.45,4.56);
f(34.45, 3);
f(2, 3);
g(3.45);
g(2);
h(20);
pair<int, float> p(20, 30.34);
h(p);
}
"Chandra Shekhar Kumar" <ch***********@oracle.com> wrote... template<> template <typename T1, typename T2> iseq(pair<T1, T2>) What is the above supposed to be? It isn't legal code, in any case.
see the code below and run it, u will understand what i meant by above...............(use a good compiler ::-))
See the results below. Perhaps, you need to use a good book? #include <iostream> #include <map>
using namespace std;
template<class T> h(T a) { cout << "h::" << a << endl; }
template<> template<class T1, class T2> h(pair<T1, T2>& p) { cout <<
"pair::" << p.first << ":::" << p.second << endl;}
int main() { h(20); pair<int, float> p(20, 30.34); h(p); }
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++
"ComeauTest.c", line 6: error: omission of explicit type is nonstandard
("int"
assumed)
template<class T> h(T a) { cout << "h::" << a << endl; }
^
"ComeauTest.c", line 6: warning: missing return statement at end of non-void
function
"h(T) [with T=T]"
template<class T> h(T a) { cout << "h::" << a << endl; }
^
"ComeauTest.c", line 8: error: omission of explicit type is nonstandard
("int"
assumed)
template<> template<class T1, class T2> h(pair<T1, T2>& p) { cout <<
"pair::"
^
"ComeauTest.c", line 8: error: this declaration cannot have multiple
"template <...>"
clauses
template<> template<class T1, class T2> h(pair<T1, T2>& p) { cout <<
"pair::"
^
"ComeauTest.c", line 6: error: no operator "<<" matches these operands
operand types are: std::basic_ostream<char,
std::char_traits<char>> << std::pair<int, float>
template<class T> h(T a) { cout << "h::" << a << endl; }
^
detected during instantiation of
"int h(T) [with T=std::pair<int, float>]"
4 errors detected in the compilation of "ComeauTest.c".
In strict mode, with -tused, Compile failed
"Chandra Shekhar Kumar" <ch***********@oracle.com> wrote in message
news:3E***************@oracle.com... That iswhat I am trying to do (I think). Its just that when SomeType is 'pair<T1,T2>', you need to specify T1 and T2 too so you can't just say 'template<>' like I have here... Ahh, so you are trying to partially specialize a function template. That isn't possible in C++.
u r wrong.... see the code below::
#include <iostream> #include <map>
using namespace std;
template<class T> h(T a) { cout << "h::" << a << endl; }
template<> template<class T1, class T2> h(pair<T1, T2>& p) { cout <<
"pair::" << p.first << ":::" << p.second << endl;}
int main() { h(20); pair<int, float> p(20, 30.34); h(p); }
This code doesn't compile. It's plain bogus. Please try to
compile any code before you post it.
On Wed, 25 Jun 2003 06:31:52 +0530, Chandra Shekhar Kumar
<ch***********@oracle.com> wrote: > > template<> template <typename T1, typename T2> iseq(pair<T1, T2>) What is the above supposed to be? It isn't legal code, in any case.
see the code below and run it, u will understand what i meant by above...............(use a good compiler ::-))
I have two good compilers (Comeau C++ and G++ 3.2) and neither liked
the code. Here's Comeau's error (once I put return types into the
function declarations)
"main.cpp", line 9: error: this declaration cannot have multiple
"template
<...>" clauses
template<> template<class T1, class T2> void h(pair<T1, T2>& p) {
cout << "pai
r::"
^ #include <iostream> #include <map>
using namespace std;
template<class T> h(T a) { cout << "h::" << a << endl; }
Is that meant to be a template function? Where's the return type? template<> template<class T1, class T2> h(pair<T1, T2>& p) { cout << "pair::" << p.first << ":::" << p.second << endl;}
What the hell is that supposed to be? You have two template parameter
lists!
What compiler are you using? It appears to be severely broken...
Ahh, I just tried g++ 2.95.3 and that seems to compile it (once I put
in void return types). But that is a very old non-standard compiler -
a standard compiler is required to reject the code. I assume that you
intended to write this:
#include <iostream>
#include <map>
using namespace std;
template<class T> void h(T a) { cout << "h::" << a << endl; }
template<class T1, class T2> void h(pair<T1, T2>& p) { cout <<
"pair::"
<< p.first << ":::" << p.second << endl;}
int main()
{
h(20);
pair<int, float> p(20, 30.34);
h(p);
}
which compiles happily on GCC 3.2, Comeau C++, and GCC 2.95 for that
matter.
Tom
> #include <iostream> #include <map>
using namespace std;
template<class T> h(T a) { cout << "h::" << a << endl; }
template<> template<class T1, class T2> h(pair<T1, T2>& p) { cout << "pair::" << p.first << ":::" << p.second << endl;}
int main() { h(20); pair<int, float> p(20, 30.34); h(p); }
This code doesn't compile. It's plain bogus. Please try to compile any code before you post it.
hi Victor, actually i compiled the above with g++ 2.8.1 and it ran well...
but i tried the same with Comeau too and u r right there....
it's not standard code....g++ guys are lenient i think.....
but my main point is this: function templates can be specialised ....see my
next posting of the code(pl forgive me for missing the return types , i meant
it to be void though :-))
i tried it with Comeau too, and it run....
#include <iostream>
#include <map>
using namespace std;
template<class T1, class T2> void f(T1 a, T2 b) { cout << a << ":" << b <<
endl;}
//partial specialization of f......
template<class T1> void f(T1 a, int b) { cout << "partial::" << a << ":" << b
<<
endl;}
//fully specialisation of f.....not legal code...so commented.....
//template<> f(int a, int b) { cout << "fully:::" << a << ":" << b << endl;}
template <class T> void g(T a) { cout << "g:: " << a << endl;}
//fully specialisation of g.....legal here coz g takes only one argument.....
template<> void g(int a) { cout << "fully::g:::" << a << endl;}
int main()
{
f(5.45,4.56);
f(34.45, 3);
f(2, 3);
g(3.45);
g(2);
}
and the book i refer is "Modern C++ Design" by Andrei....
Thanks for yr input , no offense :-)))
Chandra
"Chandra Shekhar Kumar" <ch***********@oracle.com> wrote... #include <iostream> #include <map>
using namespace std;
template<class T> h(T a) { cout << "h::" << a << endl; }
template<> template<class T1, class T2> h(pair<T1, T2>& p) { cout << "pair::" << p.first << ":::" << p.second << endl;}
int main() { h(20); pair<int, float> p(20, 30.34); h(p); }
This code doesn't compile. It's plain bogus. Please try to compile any code before you post it.
hi Victor, actually i compiled the above with g++ 2.8.1 and it ran
well... but i tried the same with Comeau too and u r right there.... it's not standard code....g++ guys are lenient i think..... but my main point is this: function templates can be specialised ....see
my next posting of the code(pl forgive me for missing the return types , i
meant it to be void though :-))
i tried it with Comeau too, and it run.... #include <iostream> #include <map>
using namespace std;
template<class T1, class T2> void f(T1 a, T2 b) { cout << a << ":" << b << endl;}
//partial specialization of f......
template<class T1> void f(T1 a, int b) { cout << "partial::" << a << ":"
<< b << endl;}
This is not a partial specialisation of 'f'. It's another template
called 'f' that has one template argument. That's known as "function
overloading" (please see subclause 14.8.3). A partial specialisation
(if it were allowed) _would_ look like this:
template<class T1> void f<T1,int>(T1 a, int b) ...
Victor
On Wed, 25 Jun 2003 06:46:41 +0530, Chandra Shekhar Kumar
<ch***********@oracle.com> wrote: so , now the question is when to choose function templates, and when function overloading..... the limitation of function templates is that they donot scale well. what i mean is: with the function templates having 2 or more arguments cann't be fully specilaized.
see the code below:
#include <iostream> #include <map>
using namespace std;
template<class T1, class T2> f(T1 a, T2 b) { cout << a << ":" << b << endl;}
Where is the return type? The code is illegal, and if your compiler
compiles it, your compiler is non-standard. //partial specialization of f......
template<class T1> f(T1 a, int b) { cout << "partial::" << a << ":" << b << endl;}
That is an overload. Why do you think it is a partial specialization?
//fully specialisation of f.....not legal code...so commented.....
//template<> f(int a, int b) { cout << "fully:::" << a << ":" << b << endl;}
That is indeed a full specialization (again, missing the return type).
It would be legal code if you put in the argument list, and thus told
the compiler which overload you were specializing:
template<> void f<int>(int a, int b) { cout << "fully:::" << a << ":"
<< b << endl;}
(note the <int> bit)
template <class T> g(T a) { cout << "g:: " << a << endl;}
//fully specialisation of g.....legal here coz g takes only one argument.....
template<> g(int a) { cout << "fully::g:::" << a << endl;}
Right, but where is the return type? Where did you learn your
"dialect" of C++!? template<class T> h(T a) { cout << "h::" << a << endl; }
//fully specialisation...same as above....:-)))
template<> template<class T1, class T2> h(pair<T1, T2>& p) { cout << "pair::" << p.first << ":::" << p.second << endl;}
That is illegal code, and your compiler appears to be broken.
Please don't form an opinion of what and what isn't legal code based
on an old, pre-standard compiler, and please don't misinform readers
by posting complete rubbish.
Tom This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Agent Mulder |
last post by:
Hi group,
I have a problem with partial template specialization. In the code
below I have a template struct Music with one method, play(),
and three kinds of music, Jazz, Funk and Bach. When I...
|
by: TT \(Tom Tempelaere\) |
last post by:
Comeau compiler complains (too few arguments for class template "B") at line
***
#include <memory>
template<typename T, size_t n>
struct A {};
template<typename T, size_t n>
struct B;
|
by: BekTek |
last post by:
I'm still confused about the template partial specialization which is used
in many libraries..
due to lack of introduction for beginner..
Could you tell me about that in short?
Thanks in...
|
by: Levent |
last post by:
Hi,
Why doesn't this work? (tried with gcc 3.3.3 and VC++ 7.1):
#include <iostream>
template<class T, unsigned N>
struct Foo {
void func();
};
template<class T, unsigned N>
|
by: Alfonso Morra |
last post by:
Does VC 7.1 support template specialization and partial specialization ?
|
by: Marek Vondrak |
last post by:
Hello.
I have written the following program and am curious why it prints "1" "2".
What are the exact effects of explicitly providing function template
parameters at the call? Is the second...
|
by: stephen.diverdi |
last post by:
Can anyone lend a hand on getting this particular template
specialization working? I've been trying to compile with g++ 4.1 and
VS 2005.
...
|
by: flopbucket |
last post by:
Hi,
I want to provide a specialization of a class for any type T that is a
std::map.
template<typename T>
class Foo
{
// ...
};
|
by: Ioannis Gyftos |
last post by:
Hello,
First the code :)
///////////////////////////////////////////////////////////////////////////////////
// in another header file
namespace LJC{
|
by: erikbower65 |
last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA:
1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
|
by: kcodez |
last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: Taofi |
last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same
This are my field names
ID, Budgeted, Actual, Status and Differences
...
|
by: Rina0 |
last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
|
by: DJRhino |
last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer)
If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _
310030356 Or 310030359 Or 310030362 Or...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: lllomh |
last post by:
How does React native implement an English player?
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
| |