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


|