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