algorithm.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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/algorithm.hpp>
  5. #include <boost/hana/equal.hpp>
  6. #include <boost/hana/less.hpp>
  7. #include <boost/hana/mult.hpp>
  8. namespace hana = boost::hana;
  9. // The algorithms are taken from the suggested implementations on cppreference.
  10. // Hence, we assume them to be correct and we only make sure they compile, to
  11. // avoid stupid mistakes I could have made when copy/pasting and editing.
  12. //
  13. // Oh, and we also make sure they can be used in a constexpr context.
  14. constexpr bool constexpr_context() {
  15. int x = 0, y = 1;
  16. hana::detail::constexpr_swap(x, y);
  17. int array[6] = {1, 2, 3, 4, 5, 6};
  18. int* first = array;
  19. int* last = array + 6;
  20. hana::detail::reverse(first, last);
  21. hana::detail::next_permutation(first, last, hana::less);
  22. hana::detail::next_permutation(first, last);
  23. hana::detail::lexicographical_compare(first, last, first, last, hana::less);
  24. hana::detail::lexicographical_compare(first, last, first, last);
  25. hana::detail::equal(first, last, first, last, hana::equal);
  26. hana::detail::equal(first, last, first, last);
  27. hana::detail::sort(first, last, hana::equal);
  28. hana::detail::sort(first, last);
  29. hana::detail::find(first, last, 3);
  30. hana::detail::find_if(first, last, hana::equal.to(3));
  31. hana::detail::iota(first, last, 0);
  32. hana::detail::count(first, last, 2);
  33. hana::detail::accumulate(first, last, 0);
  34. hana::detail::accumulate(first, last, 1, hana::mult);
  35. hana::detail::min_element(first, last);
  36. return true;
  37. }
  38. static_assert(constexpr_context(), "");
  39. int main() { }