472,809 Members | 2,507 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,809 software developers and data experts.

illegal explicit template specialization

hi,

the following code produces an "illegal explicit template
specialization" warning. I have been fiddling around a while to find a
solution to specialize a template method of a specialized template
class. Here is what I would like to be able to call:

ChannelIndexTraits<RGB>::index<RED>() == 0
ChannelIndexTraits<RGB>::index<GREEN>() == 1
ChannelIndexTraits<RGB>::index<ALPHA>() == -1
ChannelIndexTraits<RGBA>::index<ALPHA>() == 3
ChannelIndexTraits<RGBA>::index<RED>() == 0

the following code produces the warning:

enum ColorComponents {
RGB,
RGBA
};

enum ChannelType {
ALPHA,
RED,
GREEN,
BLUE
};

template <ColorComponents>
struct ChannelIndexTraits {
template <ChannelType TYPE>
static int index() {return -1;}
};

// explicit template specializations to map channels to colorcomponents

template <>
static int ChannelIndexTraits<RGB>::index<RED>() {return 0;}

template <>
static int ChannelIndexTraits<RGB>::index<GREEN>() {return 1;}

template <>
static int ChannelIndexTraits<RGB>::index<BLUE>() {return 2;}

template <>
static int ChannelIndexTraits<RGBA>::index<RED>() {return 0;}

template <>
static int ChannelIndexTraits<RGBA>::index<GREEN>() {return 1;}

template <>
static int ChannelIndexTraits<RGBA>::index<BLUE>() {return 2;}

template <>
static int ChannelIndexTraits<RGBA>::index<ALPHA>() {return 3;}
Any Ideas?

May 29 '06 #1
3 2380
stain wrote:
hi,

the following code produces an "illegal explicit template
specialization" warning. I have been fiddling around a while to find a
solution to specialize a template method of a specialized template
class. Here is what I would like to be able to call:

ChannelIndexTraits<RGB>::index<RED>() == 0
ChannelIndexTraits<RGB>::index<GREEN>() == 1
ChannelIndexTraits<RGB>::index<ALPHA>() == -1
ChannelIndexTraits<RGBA>::index<ALPHA>() == 3
ChannelIndexTraits<RGBA>::index<RED>() == 0

the following code produces the warning:

enum ColorComponents {
RGB,
RGBA
};

enum ChannelType {
ALPHA,
RED,
GREEN,
BLUE
};

template <ColorComponents>
struct ChannelIndexTraits {
template <ChannelType TYPE>
static int index() {return -1;}
};

// explicit template specializations to map channels to colorcomponents

template <>
static int ChannelIndexTraits<RGB>::index<RED>() {return 0;}

[...]

Try:

template <>
template <>
int ChannelIndexTraits<RGB>::index<RED>() {return 0;}
May 29 '06 #2
> template <>
static int ChannelIndexTraits<RGB>::index<RED>() {return 0;}


This is wrong. You have to provide explicit specializations for
ChannelIndexTraits<RGB> and ChannelIndexTraits<RGBA> first. Once that is
done, you specialize ChannelIndexTraits<RGB>'s functions and
ChannelIndexTraits<RGBA>'s functions.

enum ColorComponents {
RGB,
RGBA
};

enum ChannelType {
ALPHA,
RED,
GREEN,
BLUE
};

template <ColorComponents>
struct ChannelIndexTraits {
template <ChannelType TYPE>
static int index() {return -1;}
};

// specialize ChannelIndexTraits first

template <>
struct ChannelIndexTraits<RGB> {
template <ChannelType TYPE>
static int index() { return -1; }
};

template <>
struct ChannelIndexTraits<RGBA> {
template <ChannelType TYPE>
static int index() { return -1; }
};

// specialize ChannelIndexTraits<RGB>::index()

template <>
int ChannelIndexTraits<RGB>::index<RED>() {return 0;}

template <>
int ChannelIndexTraits<RGB>::index<GREEN>() {return 1;}

template <>
int ChannelIndexTraits<RGB>::index<BLUE>() {return 2;}

// specialize ChannelIndexTraits<RGBA>::index()

template <>
int ChannelIndexTraits<RGBA>::index<RED>() {return 0;}

template <>
int ChannelIndexTraits<RGBA>::index<GREEN>() {return 1;}

template <>
int ChannelIndexTraits<RGBA>::index<BLUE>() {return 2;}

template <>
int ChannelIndexTraits<RGBA>::index<ALPHA>() {return 3;}
May 29 '06 #3
> Try:

template <>
template <>
int ChannelIndexTraits<RGB>::index<RED>() {return 0;}


Thanks! That solved it!

May 30 '06 #4

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

Similar topics

4
by: CoolPint | last post by:
I would be grateful if someone could point out if I am understanding correctly and suggest ways to improve. Sorry for the long message and I hope you will kindly bear with it. I have to make it...
5
by: Andy | last post by:
Hi, I got a little confused on 'instantiation' and 'specialization', espcially for explicit instantiation and explicit sepcialization. Can anybody explain the difference? Thanks a lot! ...
6
by: Vyacheslav Lanovets | last post by:
Hello, All! I know that Explicit Instantiation actually emits code to obj files (so you can even export them from the module as plain functions or classes). But I found that MSVC7.1 compiler...
8
by: Ferdi Smit | last post by:
I've never understood the rationale of allowing partial, but not explicit specialization for classes at non-namespace scope. Ie.: struct A { template <typename T1, typename T2> struct B {}; ...
1
by: Thomas Barnet-Lamb | last post by:
I have a query concerning the handling of explicit specializations. Essentially, I want to know whether it is legal to take a template like >template<class X> typename X::A Foo(typename X::B,...
3
by: Hendrik Schober | last post by:
Hi, both Comeau and CW9 complain about the following code. VC71 accepts it. I cannot cite chapter and verse of the standard disallowing this, but I usually believe what Comeau says. Is that a...
1
by: JohnPantango | last post by:
Can anyone give me a simple work around to fix this compiler error on VC7.1 .....cpp(23) : error C2912: explicit specialization; 'bool Equal<_F32>(const _F32::type,const _F32::type)' is not a...
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:
0
by: greek_bill | last post by:
Hi, I have a template function for which I use SFINAE to restrict one of the parameters. Then I also have a partial specialization of this function.I would like to provide an explicit...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
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...
0
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...
2
isladogs
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...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
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...
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
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...

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.