-
November 22nd, 2010, 10:19 AM
#1
Explicit Template Confusion
Hi Gurus,
Howdy, I've been gone a while.
I would like to make specializations of a template subroutine within the specialization of a template struct.
- I know that the standard does not allow explicit template specilizations within a non-namespace scope.
- I also know that VC does allow it and does compiles it (non-standard).
- I know that GCC complains (correctly) about "error: explicit specialization in non-namespace scope".
- What I don't know is how to code it.
I have the code below. It works for VC and is non-standard. It doesn't work with GCC because GCC is conformant and the code is not.
Could anyone please tell me how to code it correctly?
Thanks. Sincerely, Chris.
Code:
#include <iostream>
namespace my_name
{
// Interface of outer
template<const unsigned A, const unsigned B>
struct outer { };
// Specialization for A = 1, B = ?.
template<const unsigned B>
struct outer<1u, B>
{
template<const unsigned C> static void inner(void)
{
std::cout << "Not yet implemented" << std::endl;
}
// Specialization for A = 1, B = ?, C = 0
template<> static void inner<0u>(void)
{
std::cout << (1u + B + 0u) << std::endl;
}
// Specialization for A = 1, B = ?, C = 1
template<> static void inner<1u>(void)
{
std::cout << (1u + B + 1u) << std::endl;
}
// Specialization for A = 1, B = ?, C = 2
template<> static void inner<2u>(void)
{
std::cout << (1u + B + 2u) << std::endl;
}
};
}
int main(void)
{
my_name::outer<1u, 2u>::inner<0u>(); // 3
my_name::outer<1u, 2u>::inner<1u>(); // 4
my_name::outer<1u, 2u>::inner<2u>(); // 5
my_name::outer<1u, 2u>::inner<3u>(); // Not yet implemented
}
You're gonna go blind staring into that box all day.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|