
________________________________________ De: boost-bounces@lists.boost.org [boost-bounces@lists.boost.org] En nombre de Daniel Frey [d.frey@gmx.de] Enviado el: domingo, 13 de abril de 2008 13:43 Para: boost@lists.boost.org Asunto: Re: [boost] A C++ puzzler On Sun, 2008-04-13 at 12:51 +0200, Daniel Frey wrote:
The new version (attached) has only 4 overloads instead of N, but it still uses typeof.
OK, another version. No typeof and O(1), due to the fact that in the good case the common_type_helper must always be instantiated with the same T, so the number of template instantiations doesn't grow, it has a constant limit. The bad case will fail anyway, but it might need some instantiations before finding out. I hope that this solution is acceptable for you.
Instead of having nested common_type_helper invokations in the common type calculation formula, you can do it linearly like this: template< typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7 > struct common_type { typedef typename common_type_helper<T0,T1>::type t0; typedef typename common_type_helper<t0,T2>::type t1; typedef typename common_type_helper<t1,T3>::type t2; typedef typename common_type_helper<t2,T4>::type t3; typedef typename common_type_helper<t3,T5>::type t4; typedef typename common_type_helper<t4,T6>::type t5; typedef typename common_type_helper<t5,T7>::type t6; typedef t6 type; }; which has the advantage of being much more easily automatable via Boost.Preprocessor. Boost.PP-generated modified version attached. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo