compile.cexpr.unrolled.erb.cpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright Louis Dionne 2013-2017
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  4. #include <boost/hana/detail/variadic/foldl1.hpp>
  5. template <typename ...xs>
  6. struct list { };
  7. template <typename T>
  8. struct basic_type { using type = T; };
  9. template <typename T>
  10. constexpr basic_type<T> type{};
  11. template <typename F, typename State, typename ...Xs>
  12. constexpr auto foldl(F f, State s, list<Xs...> xs)
  13. { return boost::hana::detail::variadic::foldl(f, s, type<Xs>...); }
  14. //////////////////////////////////////////////////////////////////////////////
  15. struct f {
  16. template <typename ...>
  17. struct result { };
  18. template <typename X, typename Y>
  19. constexpr auto operator()(X, Y) const
  20. { return result<X, Y>{}; }
  21. };
  22. template <int> struct x { };
  23. struct state { };
  24. int main() {
  25. constexpr auto xs = list<
  26. <%= (1..input_size).map { |i| "x<#{i}>" }.join(', ') %>
  27. >{};
  28. constexpr auto result = foldl(f{}, state{}, xs);
  29. (void)result;
  30. }