
Hey, my implementation is in the attachment. It's rather ugly ;) so it's probably not what You had in mind, but AFAIK it works. the common_type<...> template is declared only for three args, but with a little help from boost/preprocessor it could be generalized to N params. Unfortunatelly i don't have the time to play with that right now :-P. Nice puzzler though ;) Best, On Sat, Apr 12, 2008 at 12:15 PM, JOAQUIN M. LOPEZ MUÑOZ <joaquin@tid.es> wrote:
________________________________________ De: boost-bounces@lists.boost.org [boost-bounces@lists.boost.org] En nombre de Eric Niebler [eric@boost-consulting.com] Enviado el: sábado, 12 de abril de 2008 9:28 Para: Boost mailing list Asunto: [boost] A C++ puzzler
I recently had a C++ problem and found an answer that tickled my brain. In the spirit of Car Talk on NPR, I thought I'd share it in the form of a puzzler. [...]
Hello Eric, I am not sure if this is what you have in mind, since from your description is not clear how the input types are represented: I've assumed they're just the args of a class template with a fixed number of template parameters:
struct default_t{};
template<typename T> struct holder_base{typedef T type;};
template<> struct holder_base<default_t>{};
template<typename T,int> struct holder:virtual holder_base<T>{};
template<typename T1,typename T2,typename T3,typename T4,typename T5> struct common_type_base: holder<T1,1>,holder<T2,2>,holder<T3,3>,holder<T4,4>,holder<T5,5>{};
template<typename T1,typename T2,typename T3,typename T4,typename T5> struct common_type:common_type_base<T1,T2,T3,T4,T5> { typedef typename common_type_base<T1,T2,T3,T4,T5>::type type; };
template<> struct common_type<default_t,default_t,default_t,default_t,default_t> { typedef default_t type; };
Best,
Joaquín M López Muñoz Telefónica, Investigación y Desarrollo _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
-- ________________ ::matus_chochlik