// RUN: %clang_cc1 -fsyntax-only -verify %s // A simple cons-style typelist struct nil { }; template struct cons { typedef Head head; typedef Tail tail; }; // is_same trait, for testing template struct is_same { static const bool value = false; }; template struct is_same { static const bool value = true; }; // metaprogram that computes the length of a list template struct length; template struct length > { static const unsigned value = length::value + 1; }; template<> struct length { static const unsigned value = 0; }; typedef cons > > > unsigned_inttypes; int length0[length::value == 4? 1 : -1]; // metaprogram that reverses a list // FIXME: I would prefer that this be a partial specialization, but // that requires partial ordering of class template partial // specializations. template class reverse { typedef typename reverse::type reversed_tail; typedef typename reverse::type most_of_tail; public: typedef cons >::type> type; }; template class reverse > { public: typedef cons type; }; template<> class reverse { public: typedef nil type; }; int reverse0[is_same::type, cons > > > >::value? 1 : -1]; // metaprogram that finds a type within a list // FIXME: I would prefer that this be a partial specialization, but // that requires partial ordering of class template partial // specializations. template struct find : find { }; template struct find, T> { typedef cons type; }; template struct find { typedef nil type; }; int find0[is_same::type, cons > >::value? 1 : -1]; int find1[is_same::type, nil>::value? 1 : -1];