Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > variadic class ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 3 Topic 9767 of 9909
Post > Topic >>

variadic class templates

by Chris Uzdavinis <cuzdav@[EMAIL PROTECTED] > Jul 5, 2008 at 03:57 AM

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! ]
 




 3 Posts in Topic:
variadic class templates
Chris Uzdavinis <cuzda  2008-07-05 03:57:20 
Re: variadic class templates
Chris Fairles <chris.f  2008-07-05 16:51:15 
Re: variadic class templates
Alberto Ganesh Barbati &l  2008-07-06 05:51:56 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Aug 20 3:57:57 CDT 2008.