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 > common_type res...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 10 Topic 9768 of 9909
Post > Topic >>

common_type result dependent on order or template parameters

by Chris Fairles <chris.fairles@[EMAIL PROTECTED] > Jul 5, 2008 at 07:34 AM

I'm working on a common_type impl. and the current working draft
doesn't say much about the behavior other than "you must define it
like this". However, if the intent is to produce a type that all types
are implicitly convertible to, consider this:

struct C { }:

struct B : C { };
struct A : C { };

Now say you write:
common_type<A,B,C>::type;

The variadic template instantiation process tries A and B first, which
fails because they are not implicitly convertible to each other.
However, had you written:
common_type<A,C,B>::type;

then, common_type<A,C>::type == C, thus common_type<A,C,B>::type ==
common_type<C,B>::type == C.

My implementation assumes this is intended because the std (N2691)
doesn't actually say "common_type<...>::type shall return a type that
all given types can implicitly convert to". However, although I
haven't tried, there might be SFINAE tricks you could use to try
permutations of the parameters so that common_type<A,B,C>::type ==
common_type<A,C,B>::type.

So, is a successful common_type<...>::type statement intentionally
dependent on the order of the type parameters?

Chris









--
      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
 




 10 Posts in Topic:
common_type result dependent on order or template parameters
Chris Fairles <chris.f  2008-07-05 07:34:40 
Re: common_type result dependent on order or template parameters
Howard Hinnant <howard  2008-07-06 16:35:34 
Re: common_type result dependent on order or template parameters
Alberto Ganesh Barbati &l  2008-07-07 06:24:40 
Re: common_type result dependent on order or template parameters
Pete Becker <pete@[EMA  2008-07-07 06:28:03 
Re: common_type result dependent on order or template parameters
Greg Herlihy <greghe@[  2008-07-07 08:59:55 
Re: common_type result dependent on order or template parameters
Howard Hinnant <howard  2008-07-07 17:59:03 
Re: common_type result dependent on order or template parameters
Pete Becker <pete@[EMA  2008-07-08 03:15:28 
Re: common_type result dependent on order or template parameters
Alberto Ganesh Barbati &l  2008-07-08 05:27:05 
Re: common_type result dependent on order or template parameters
Marsh Ray <marsh527@[E  2008-07-08 20:27:11 
Re: common_type result dependent on order or template parameters
Alberto Ganesh Barbati &l  2008-07-09 14:58:08 

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 4:05:41 CDT 2008.