473,467 Members | 2,224 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Specialization

I'm having a big problem(its probably simple but I just can't seem to figure
it out).

I have a Node template:

template <unsigned int I, unsigned int J, typename T>
struct Node
{
enum {i = I};
enum {j = J};
typedef T Class;
};
Now I have a template class I'm trying to pass a Node to

template <class A>
struct T
{
.....
};

and I would do something like T<Node<3,2,someclass>> B;

Now what I want to do is specialize T so that it if A is of Node type then
it will inherit Node::Class i.e.

template <class A>
struct T : public A::Class
{
}
which works fine... but this isn't specializing T. I've tried to do

template <class A>
struct T
{
};

template <class A>
struct T<Node> : public A::Class
{

};

but that doesn't work... I've tried to use template template parameters and
a whole lot of other crap but nothing works ;/

I need to specialize T because in reality I will be having a variable number
of Nodes... hmm.. I just can't figure out why the above won't work(ofcourse
its cause I'm weak at templates but thats besides the point).

To me, the way I see it is that when I do

T<Node<1,2,someclass>> the compiler will find the specialization of T that
is being passed a note type(or does it also try to match the exact type such
as 1,2,class?) and then everything should work...

Just not sure what to do since I get some errors that don't make any sense
to me like:

'Node' : unspecialized class template can't be used as a template argument
for template parameter 'A', expected a real type.
Any ideas how to do this?

Thanks, Jon

Sep 15 '05 #1
5 1440
template <unsigned int I, unsigned int J, typename X>
struct T< Node<I,J,X> > : public Node<I,J,X>::Class
{
};

Sep 15 '05 #2

"persenaama" <ju***@liimatta.org> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
template <unsigned int I, unsigned int J, typename X>
struct T< Node<I,J,X> > : public Node<I,J,X>::Class
{
};


Thanks, I tried something similar but I was not getting the public part
right. I think I see now. (I was trying to do it directly from X such as
public X::Class thinking that it would know but I guess thats not right).

Jon
Sep 15 '05 #3

"Jon Slaughter" <Jo***********@Hotmail.com> wrote in message
news:11*************@corp.supernews.com...

"persenaama" <ju***@liimatta.org> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
template <unsigned int I, unsigned int J, typename X>
struct T< Node<I,J,X> > : public Node<I,J,X>::Class
{
};


Thanks, I tried something similar but I was not getting the public part
right. I think I see now. (I was trying to do it directly from X such as
public X::Class thinking that it would know but I guess thats not right).

Jon

crap ;/ I can't seem to be able to do what I need to do.
template <unsigned int I, unsigned int J, typename T>
struct Node
{
enum {i = I};
enum {j = J};
typedef T Class;
};
template <int i, typename T>
struct RT { };
template <int I, int J, typename T>
struct RT< Node<I,J,T>::i, Node<I,J,T> > : public Node<I,J,T>::Class
{
static const int t = Node<I,J,T>::i;
};
I have no problem access i when inside the struct above but I can't use it
to pass it to the RT specifier...

I figured that Node<I,J,T>::i would return an literal int and just stick it
in there as if I did

template <int I, int J, typename T>
struct RT<3, Node<I,J,T> > : public Node<I,J,T>::Class
{
static const int t = Node<I,J,T>::i;
};

(which works)

What am I missing here? (The ::Class part works fine but the ::i
doesn't... ) I assume I need to somehow "Cast" Node<I,J,T>::i to a simple
type but I have no idea if this is true or not and how to do it((int)
doesn't work)
error C2755: 'RT<Node<I,J,T>::i,Node<I,J,T>>' : non-type parameter of a
partial specialization must be a simple identifier
not sure what it means by simple identifier but I assume it doesn't realize
that Node<I,J,T>::i is suppose to be a literal int?

Is my approach wrong to do what I have did by using node to "encapsulate"
those types? (I tried to model it off the Int2Type and Type2Type in modern
C++ but I can't seem to extract the right stuff that works from his examples
;/)

Thanks
Jon
Sep 15 '05 #4

template <int I, int J, typename T>
struct RT< I, Node<I,J,T> > : public Node<I,J,T>::Class
{
static const int t = Node<I,J,T>::i;

};
not sure what it means by simple identifier but I assume it
doesn't realize that Node<I,J,T>::i is suppose to be a literal int?


It does, after the types have been matched. At that point I suppose the
compiler is still trying to match the types to determine if that
specialization should be invoked or not only to find out that the
matching should be DONE ALREADY, just a hunch could be easily wrong.

The smart ones will flock here after a mistake so you're all set for
the correct answer. Now we just have to wait..

Sep 16 '05 #5

"persenaama" <ju***@liimatta.org> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...

template <int I, int J, typename T>
struct RT< I, Node<I,J,T> > : public Node<I,J,T>::Class
{
static const int t = Node<I,J,T>::i;

};


duh ;) lol. I was up all last night so I have an excuse ;) I think I was
thinking the first I was part of the I in the template definition or
something.

I just wish I could do something like

template <Node T>
struct ...

And it treated T as a node type ;/ I guess it causses some issues or
something though and that why one has to use class name and specialization?

not sure what it means by simple identifier but I assume it
doesn't realize that Node<I,J,T>::i is suppose to be a literal int?


It does, after the types have been matched. At that point I suppose the
compiler is still trying to match the types to determine if that
specialization should be invoked or not only to find out that the
matching should be DONE ALREADY, just a hunch could be easily wrong.

The smart ones will flock here after a mistake so you're all set for
the correct answer. Now we just have to wait..


Thanks.

jon
Sep 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Paul MG | last post by:
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...
4
by: Dave Theese | last post by:
Hello all, I'm trying to get a grasp of the difference between specializing a function template and overloading it. The example below has a primary template, a specialization and an overload. ...
6
by: jesse | last post by:
I am frustrated by class specialization. i don't think it helps me a lot. suppose we have template <class T> class Talkative { T& t; public:
8
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...
4
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;
2
by: Jonathan Turkanis | last post by:
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...
19
by: Nicolas Fleury | last post by:
Hi everyone, I would to know what do you think of this PEP. Any comment welcomed (even about English mistakes). PEP: XXX Title: Specialization Syntax Version: $Revision: 1.10 $...
2
by: Barry | last post by:
The following code compiles with VC8 but fails to compiles with Comeau online, I locate the standard here: An explicit specialization of any of the following:
8
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 { // ... };
6
by: abir | last post by:
i have a template as shown template<typename Sclass Indexer{}; i want to have a specialization for std::vector both const & non const version. template<typename T,typename Aclass...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.