Re: Template template partial specialization
On 4 mar, 19:08, Victor Bazarov <v.baza...@comcast.invalid> wrote:
On 3/4/2011 10:28 AM, Hizo wrote:
On 4 mar, 15:16, Victor Bazarov<v.baza...@comcast.invalid> wrote:
On 3/3/2011 9:19 PM, Hizo wrote:
Hi everybody,
I would like to use partial template specialization with template
parameters and optional template parameters, but I didn't find out
documentation about it and my compiler (g++) doesn't seem to accept
it : so how to proceed ?
For a piece of illustration here is my situation:
Don't post "a piece". Post a complete program you're trying to comp=
ile.
Don't post a huge one, remove everything irrelevant to your inq=
uiry.
FAQ 5.8.
---------------------------------
// global
template< template<class> class, class>
class Z
{};
// e.g.
template< class, class Opt = O>
What's "O"?
class X
{};
// specialized
template< class B, class Opt = O>
Again, what's "O"?
class Z< X<class, O>, B>
{};
---------------------------------
Thanks in advance for your help.
Sorry, can't provide any - not enough information in your article.
FAQ 5.8.
V
--
I do not respond to top-posted replies, please don't ask
Ok, sorry I thought that it would help since it might be more clear.
Here is my code in substance in which I removed everything
irrelevant :
------------------------------------
[..]
I took your code and tried compiling it. Lots of irrelevant errors sti=
ll.
Please, read the FAQ 5.8. If you're asking about a compile error, you
are going to get the most help if you supply the example that produces
your error, and only your error. For instance, in your code you have
// a class
template< class T >
class Object
{
public:
Object(AType a, T t) : /* init members */ {}
/* class code */
};
'AType' in undefined. You need to define it, even if you just make it =
a
typedef'ed int. The colon that does not have anything after that needs
to be removed as well before you post your question here. Make all
comments C-style: /*like this*/.
I am not trying to be difficult. I am trying to help you post the righ=
t
amount of relevant information. Read the FAQ please.
As for partial specializations, do you have a copy of Vandevoorde and
Josuttis, "C++ Templates"? It might help you immensely. There are
probably numerous examples of specializations you can already find in
previous posts, and generally on the Web. Have you tried googling for =
them?
V
--
I do not respond to top-posted replies, please don't ask
Here it is :
-----------------------
#include <functional>
using std::equal_to;
using std::less_equal;
typedef int AType;
/* a class */
template< class T >
class Object
{
public:
Object(AType a, T t)
{
/* init */
}
/* class code */
};
/* abstract class (designated as an interface for a relation order
between vectors) */
template< class >
class VectorWeakOrder
{
/* code */
};
/* template class (no polymorphism but template because we must create
pointer of that type order for further use of special properties of it
in one of the methods of this class) */
template< template <class> class VectorWeakOrderT, class ValueType,
class Equal = equal_to< ValueType > >
class ROR
{
/* code */
typedef Object< VectorWeakOrderT<ValueType> > ObjT;
ObjT create() const
{
AType a;
/* code */
return ObjT( a, VectorWeakOrderT<ValueType>() );
}
};
/* template SpecialOrder class which is a VectorWeakOrder of type T */
template< class T, class Equal = equal_to<T>, class LessOrEqual =
less_equal<T> >
class SpecialOrder: VectorWeakOrder<T>
{
/* class code */
};
/* partially specializing class ? */
template< class ValueType, class Equal = equal_to< ValueType >, class
LessOrEqual = less_equal< ValueType > >
class ROR< SpecialOrder<class T,Equal,LessOrEqual>, ValueType, Equal >
{
/* same code as before (before I was trying to specialize only
a
templated method of the unspecialized template class but I read that
it was not standard so I gave up this idea and specialized the entire
class which was templated with another argument which is only useful
for this method) */
/* specialized method */
ObjT create() const
{
AType a;
SpecialOrder< ValueType, Equal, LessOrEqual >
special_order_obj;
/* do some stuff with order_obj and the class members
(const) */
return ObjT( a, special_order_obj );
}
};
-------------------------------------
* Arch: i686
* Kernel: Linux 2.6.32-hardened-r9-srv
* Compiler: gcc version 4.3.4 (Gentoo 4.3.4 p1.0, pie-10.1.5)
* Compiler flags: -O2 -march=i686 -mtune=prescott -pipe
* Error messages:
- error: type/value mismatch at argument 1 in template parameter list
for =91template<template<class> class VectorWeakOrderT, class ValueType,
class Equal> class ROR'
- error: expected a class template, got =91SpecialOrder<T, Equal,
LessOrEqual>'
As for partial specializations, do you have a copy of Vandevoorde and
Josuttis, "C++ Templates"? It might help you immensely. There are
probably numerous examples of specializations you can already find in
previous posts, and generally on the Web. Have you tried googling for th=
em?
No I have not, but that's why I thought I could find help here.
However I searched around in the web but I didn't find out examples of
template template parameter partial specialization, or the partial
specialization wasn't on the template template parameter but on other
parameters.
Thanks for your time.