Boost logo

Boost :

From: Marco Costalba (mcostalba_at_[hidden])
Date: 2008-04-12 07:17:24

On Sat, Apr 12, 2008 at 12:15 PM, JOAQUIN M. LOPEZ MUÑOZ <joaquin_at_[hidden]> wrote:
> Joaquín M López Muñoz
> Telefónica, Investigación y Desarrollo

Mine is very similar to Joaquin one with one less indirection level.

Default type here is assumed to be int, just to easy the test.

template<typename T>
struct each_type
    typedef T type;

struct each_type<int> {}; // int is the default_type

template<typename T, int n>
struct unique_type : virtual each_type<T> {};

template<typename T1, typename T2, typename T3>
struct test : unique_type<T1, 0>, unique_type<T2, 1>, unique_type<T3, 2> {};

struct test<int, int, int>
    typedef int type;

testing is:

int main(int, char**)
    test<int, int, int>::type default_value = 0;

    test<int, char, int>::type char_value = 'x';

    test<int, char, char>::type char_value_2 = 'y';

    // test<int, char, double>::type error_value; compile error here!

    return 0;

Boost list run by bdawes at, gregod at, cpdaniel at, john at