I don't my deduction of NoDuplicates are correct or not
please correct my error if I did

template<typename TList> struct NoDuplicates;

struct NoDuplicates<NullType>
  typedef NullType Result;

template<typename Head, typename Tail>
struct NoDuplicates<Typelist<Head, Tail> >
  //private :
    typedef typename NoDuplicates<Tail>::Result L1;
    typedef typename Erase<L1, Head>::Result L2;

  public :
    typedef Typelist<Head, L2> Result;

Example : Typelist<T1, Typelist<T1, Typelist<T2, NullType> > >
The idea of Noduplicates is very simple

NoDuplicates will extract the Tail of Typelist(L1)
and compare with the Head of the Typelist
erase the Type same as Head one time if there were and get a new type(L2)
Then we will get a new

Typelist = Typelist<Head, L2>

In this example it should be

Typelist<T1, Typelist<T2, NullType> >

Then NoDuplicates will run again until the end of the types

The idea is straight forward, but we have to accomplish it by the way of recursive
for simplicity, I would reduce the template parameters to two
Example : Typelist<T1, Typelist<T1,NullType> >


typedef typename NoDuplicates<Typelist<T1, NullType> >::Result L1;
typedef typename Erase<L1, T1>::Result L2;
typedef typename Typelist<T1, L2> Result;


typedef typename NoDuplicates<NullType>::Result L1 == NullType
typedef typename Erase<NullType, T1>::Result L2 == NullType
typedef typename Typelist<T1, NullType> Result

back to (1)

L1 == Typelist<T1, NullType>
typedef typename Erase<Typelist<T1, NullType>, T1>::Result L2 == NullType
typedef typename Typelist<T1, NullType> Result;

Do I make any mistake?
Could I find some good books talk about variadic template
vs old times TMP?


Edited by stereomatching: n/a

6 Years
Discussion Span
Last Post by stereomatching

Looks good to me.

Test it out to make sure it's working.

With variadic templates (using the earlier 'indexof'):

template< typename T > struct unique ;

template<> struct unique< typelist<> > { typedef typelist<> type ; } ;

template< typename FIRST, typename ...REST > struct unique< typelist<FIRST,REST...> >
    typedef typename unique< typelist<REST...> >::type urtype ;
    typedef typename std::conditional<
                        indexof< FIRST, typelist<REST...> >::value == -1,
                        typename push_front< FIRST, urtype >::type, urtype >::type type ;

Edited by vijayan121: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.