1// PR c++/58176 2// { dg-do compile { target c++11 } } 3 4// Nil 5struct nil_ { constexpr nil_ () {} }; 6constexpr nil_ nil; 7 8// Cons 9template <class H, class T = nil_> 10struct cons_ { 11 using head_ = H; 12 using tail_ = T; 13 14 H head; 15 T tail; 16 17 constexpr cons_() {} 18 constexpr cons_(H const &h, T const &t) : head(h), tail(t) {} 19}; 20template <class H, class T = nil_> 21constexpr cons_<H, T> cons (H const &h, T const &t = nil) { return 22cons_<H,T>(h,t); } 23 24// List 25template <class... T> struct list_s; 26template <class H, class... T> 27struct list_s<H, T...> { 28 using type = cons_<H, typename list_s<T...>::type>; 29}; 30template <> 31struct list_s<> { 32 using type = nil_; 33}; 34template <class... T> 35using list_ = typename list_s<T...>::type; 36constexpr nil_ list () { return nil; } 37template <class H, class... T> 38constexpr list_<H, T...> list (H h, T... t) { return cons(h, list(t...)); } 39 40constexpr auto l1 = list("monkey", 123.4, cons(1, 2), nullptr); 41