counter.hpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright Louis Dionne 2013-2017
  2. // Copyright Jason Rice 2017
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  5. #ifndef TEST_SUPPORT_COUNTER_HPP
  6. #define TEST_SUPPORT_COUNTER_HPP
  7. #include <boost/hana/fwd/at.hpp>
  8. #include <boost/hana/fwd/concept/iterable.hpp>
  9. #include <boost/hana/fwd/drop_front.hpp>
  10. #include <boost/hana/fwd/is_empty.hpp>
  11. #include <boost/hana/integral_constant.hpp>
  12. // Counter - an infinite iterable for the masses
  13. struct Counter_tag { };
  14. template <std::size_t N = 0>
  15. struct Counter {
  16. using hana_tag = Counter_tag;
  17. static constexpr std::size_t value = N;
  18. };
  19. namespace boost { namespace hana {
  20. //////////////////////////////////////////////////////////////////////////
  21. // Iterable
  22. //////////////////////////////////////////////////////////////////////////
  23. template <>
  24. struct at_impl<Counter_tag> {
  25. template <typename T, typename N>
  26. static constexpr decltype(auto) apply(T, N) {
  27. return hana::size_c<T::value + N::value>;
  28. }
  29. };
  30. template <>
  31. struct drop_front_impl<Counter_tag> {
  32. template <typename T, typename N>
  33. static constexpr auto apply(T, N) {
  34. return Counter<T::value + N::value>{};
  35. }
  36. };
  37. template <>
  38. struct is_empty_impl<Counter_tag> {
  39. template <typename Xs>
  40. static constexpr auto apply(Xs)
  41. -> hana::false_
  42. { return {}; }
  43. };
  44. }} // end namespace boost::hana
  45. #endif // !TEST_SUPPORT_COUNTER_HPP