Hi,
While experimenting with variadic templates, I tried something that
seems pretty simple, but works differently than I expected. I made up
a problem: have a static member 'value' is true when the first two
template parameter types are the same, and false when they're not.
Only problem is, it always is false:
#include <iostream>
#include <ios>
template <typename T, typename U, typename... Args>
struct X
{
static const bool value = false;
};
template <typename T, typename... Args>
struct X<T, T, ...Args>
{
static const bool value = true;
};
int main()
{
//
// why doesn't this select the specialization?
// (output is "false")
//
bool result = X<int, int>::value;
std::cout << std::boolalpha << result << std::endl;
}
Given partial specialization rules, I would have thought my
specialization was "more specialized" than the primary template, and
as such would be the template selected. The same code, of course,
works as I expect when the trailing, unused variadic parameters are
removed. Is there something about variadic templates that changes
the way they're selected, or is g++ not behaving correctly?
(I'm using g++ 4.3.1.)
Thanks,
Chris
--
[ See http://www.gotw.ca/resources/clcm.htm
for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


|