2 // { dg-do compile { target c++14 } }
8 using size_t = decltype(0);
12 template <typename T, T> struct _with_index {
13 template <typename F> constexpr void operator()(F &&) const;
15 template <typename T, T v> struct _times { _with_index<T, v> with_index; };
17 template <typename T, T v> struct _integral_constant {
19 operator value_type() const;
20 ic_detail::_times<T, v> times;
22 template <detail::std::size_t i>
23 constexpr _integral_constant<detail::std::size_t, i> size_t{};
24 template <typename, typename = void> struct datatype;
29 inline namespace __cxx11 {}
33 template <bool> struct when;
34 template <typename, typename, typename> struct to_impl;
35 template <typename T, typename> struct datatype : datatype<T, when<true>> {};
36 template <typename T, bool condition> struct datatype<T, when<condition>> {
37 using type = typename T::hana::datatype;
39 template <typename> struct _models;
40 template <typename To, typename From>
42 From, when < _models<From> {
46 template <typename T, T> struct integer_sequence;
47 template <size_t... n> using index_sequence = integer_sequence<size_t, n...>;
48 namespace int_seq_detail {
49 template <size_t> struct make_index_sequence {
50 using type = index_sequence<0>;
52 template <typename, typename> struct cast_to;
53 template <typename T, typename U, U... u>
54 struct cast_to<T, integer_sequence<U, u...>> {
55 using type = integer_sequence<T, u...>;
58 template <typename T, T>
59 using make_integer_sequence = typename int_seq_detail::cast_to<
60 T, int_seq_detail::make_index_sequence<1>::type>::type;
64 template <typename T, T N, typename = detail::std::make_integer_sequence<T, N>>
66 template <typename T, T N, T... i>
67 struct go<T, N, detail::std::integer_sequence<T, i...>> {
69 template <typename F> static void with_index(F f) {
70 swallow{(f(_integral_constant<T, i>{}), 0)...};
73 template <typename T, T v>
75 constexpr void _with_index<T, v>::operator()(F &&f) const {
76 go<T, 0>::with_index(f);
82 template <typename> class allocator;
83 template <class> struct char_traits;
84 template <typename _CharT, typename = char_traits<_CharT>> class basic_ostream;
86 template <typename _CharT, typename = char_traits<_CharT>,
87 typename = allocator<_CharT>>
88 class basic_stringstream;
90 typedef basic_ostream<char> ostream;
91 typedef basic_stringstream<char> stringstream;
92 template <typename, typename> class basic_ostream {};
93 template <typename _CharT, typename>
94 class basic_iostream : public basic_ostream<_CharT> {};
96 template <typename _CharT, typename _Traits, typename>
97 class basic_stringstream : public basic_iostream<_CharT, _Traits> {};
100 namespace hana = boost::hana;
101 template <typename> struct print_impl;
102 template <typename X> void print(std::ostream os, X x) {
103 using Tag = typename hana::datatype<X>::type;
104 print_impl<Tag>::apply(os, x);
107 template <typename, typename> struct vector2 {
109 using datatype = Vector;
111 static constexpr std::size_t size = 0;
113 template <> struct print_impl<Vector> {
114 template <typename vectorN> static void apply(std::ostream, vectorN) {
115 constexpr auto N = hana::size_t<vectorN::size>;
116 N.times.with_index([&](auto) { N - hana::size_t<1>; });
120 std::stringstream ss;
121 vector2<int, char> v2;