Boost logo

Boost :

From: JOAQUIN M. LOPEZ MUÑOZ (joaquin_at_[hidden])
Date: 2008-04-12 06:15:44


 ________________________________________
De: boost-bounces_at_[hidden] [boost-bounces_at_[hidden]] En nombre de Eric Niebler [eric_at_[hidden]]
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


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk