diff --git a/libs/algorithm/test/includes.cpp b/libs/algorithm/test/includes.cpp index 9005af25..cb1f542a 100644 --- a/libs/algorithm/test/includes.cpp +++ b/libs/algorithm/test/includes.cpp @@ -91,6 +91,166 @@ namespace testspr { ); TESTSPR_BOTH_ASSERT(!result); } + +#if defined(__clang__) + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::includes( + testspr::reduct_input(sprout::begin(arr1)), + testspr::reduct_input(sprout::end(arr1)), + testspr::reduct_input(sprout::begin(arr2)), + testspr::reduct_input(sprout::end(arr2)) + ); + TESTSPR_BOTH_ASSERT(result); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::includes( + testspr::reduct_input(sprout::begin(arr1)), + testspr::reduct_input(sprout::end(arr1)), + testspr::reduct_input(sprout::begin(arr3)), + testspr::reduct_input(sprout::end(arr3)) + ); + TESTSPR_BOTH_ASSERT(!result); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::includes( + testspr::reduct_input(sprout::begin(arr1)), + testspr::reduct_input(sprout::begin(arr1) + 5), + testspr::reduct_input(sprout::begin(arr2)), + testspr::reduct_input(sprout::end(arr2)) + ); + TESTSPR_BOTH_ASSERT(!result); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::includes( + testspr::reduct_input(sprout::begin(arr1)), + testspr::reduct_input(sprout::begin(arr1) + 5), + testspr::reduct_input(sprout::begin(arr3)), + testspr::reduct_input(sprout::end(arr3)) + ); + TESTSPR_BOTH_ASSERT(!result); + } + + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::includes( + testspr::reduct_input(sprout::begin(arr1)), + testspr::reduct_input(sprout::end(arr1)), + testspr::reduct_input(sprout::begin(arr2)), + testspr::reduct_input(sprout::end(arr2)), + testspr::less() + ); + TESTSPR_BOTH_ASSERT(result); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::includes( + testspr::reduct_input(sprout::begin(arr1)), + testspr::reduct_input(sprout::end(arr1)), + testspr::reduct_input(sprout::begin(arr3)), + testspr::reduct_input(sprout::end(arr3)), + testspr::less() + ); + TESTSPR_BOTH_ASSERT(!result); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::includes( + testspr::reduct_input(sprout::begin(arr1)), + testspr::reduct_input(sprout::begin(arr1) + 5), + testspr::reduct_input(sprout::begin(arr2)), + testspr::reduct_input(sprout::end(arr2)), + testspr::less() + ); + TESTSPR_BOTH_ASSERT(!result); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::includes( + testspr::reduct_input(sprout::begin(arr1)), + testspr::reduct_input(sprout::begin(arr1) + 5), + testspr::reduct_input(sprout::begin(arr3)), + testspr::reduct_input(sprout::end(arr3)), + testspr::less() + ); + TESTSPR_BOTH_ASSERT(!result); + } +#endif + +#if defined(__clang__) + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::includes( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::end(arr1)), + testspr::reduct_random_access(sprout::begin(arr2)), + testspr::reduct_random_access(sprout::end(arr2)) + ); + TESTSPR_BOTH_ASSERT(result); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::includes( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::end(arr1)), + testspr::reduct_random_access(sprout::begin(arr3)), + testspr::reduct_random_access(sprout::end(arr3)) + ); + TESTSPR_BOTH_ASSERT(!result); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::includes( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::begin(arr1) + 5), + testspr::reduct_random_access(sprout::begin(arr2)), + testspr::reduct_random_access(sprout::end(arr2)) + ); + TESTSPR_BOTH_ASSERT(!result); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::includes( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::begin(arr1) + 5), + testspr::reduct_random_access(sprout::begin(arr3)), + testspr::reduct_random_access(sprout::end(arr3)) + ); + TESTSPR_BOTH_ASSERT(!result); + } + + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::includes( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::end(arr1)), + testspr::reduct_random_access(sprout::begin(arr2)), + testspr::reduct_random_access(sprout::end(arr2)), + testspr::less() + ); + TESTSPR_BOTH_ASSERT(result); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::includes( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::end(arr1)), + testspr::reduct_random_access(sprout::begin(arr3)), + testspr::reduct_random_access(sprout::end(arr3)), + testspr::less() + ); + TESTSPR_BOTH_ASSERT(!result); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::includes( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::begin(arr1) + 5), + testspr::reduct_random_access(sprout::begin(arr2)), + testspr::reduct_random_access(sprout::end(arr2)), + testspr::less() + ); + TESTSPR_BOTH_ASSERT(!result); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::includes( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::begin(arr1) + 5), + testspr::reduct_random_access(sprout::begin(arr3)), + testspr::reduct_random_access(sprout::end(arr3)), + testspr::less() + ); + TESTSPR_BOTH_ASSERT(!result); + } +#endif } } } // namespace testspr diff --git a/libs/algorithm/test/is_heap.cpp b/libs/algorithm/test/is_heap.cpp index 1f175f36..a3057dd8 100644 --- a/libs/algorithm/test/is_heap.cpp +++ b/libs/algorithm/test/is_heap.cpp @@ -73,6 +73,69 @@ namespace testspr { ); TESTSPR_BOTH_ASSERT(result); } + +#if defined(__clang__) + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::is_heap( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::end(arr1)) + ); + TESTSPR_BOTH_ASSERT(result); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::is_heap( + testspr::reduct_random_access(sprout::begin(arr2)), + testspr::reduct_random_access(sprout::end(arr2)) + ); + TESTSPR_BOTH_ASSERT(!result); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::is_heap( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::begin(arr1) + 5) + ); + TESTSPR_BOTH_ASSERT(result); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::is_heap( + testspr::reduct_random_access(sprout::begin(arr2)), + testspr::reduct_random_access(sprout::begin(arr2) + 5) + ); + TESTSPR_BOTH_ASSERT(result); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::is_heap( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::end(arr1)), + testspr::less() + ); + TESTSPR_BOTH_ASSERT(result); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::is_heap( + testspr::reduct_random_access(sprout::begin(arr2)), + testspr::reduct_random_access(sprout::end(arr2)), + testspr::less() + ); + TESTSPR_BOTH_ASSERT(!result); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::is_heap( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::begin(arr1) + 5), + testspr::less() + ); + TESTSPR_BOTH_ASSERT(result); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::is_heap( + testspr::reduct_random_access(sprout::begin(arr2)), + testspr::reduct_random_access(sprout::begin(arr2) + 5), + testspr::less() + ); + TESTSPR_BOTH_ASSERT(result); + } +#endif } } } // namespace testspr diff --git a/libs/algorithm/test/is_heap_until.cpp b/libs/algorithm/test/is_heap_until.cpp index 8c391097..5ee2aa0b 100644 --- a/libs/algorithm/test/is_heap_until.cpp +++ b/libs/algorithm/test/is_heap_until.cpp @@ -73,6 +73,69 @@ namespace testspr { ); TESTSPR_BOTH_ASSERT(found == sprout::begin(arr2) + 5); } + +#if defined(__clang__) + { + SPROUT_STATIC_CONSTEXPR auto found = sprout::is_heap_until( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::end(arr1)) + ).base(); + TESTSPR_BOTH_ASSERT(found == sprout::end(arr1)); + } + { + SPROUT_STATIC_CONSTEXPR auto found = sprout::is_heap_until( + testspr::reduct_random_access(sprout::begin(arr2)), + testspr::reduct_random_access(sprout::end(arr2)) + ).base(); + TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 7); + } + { + SPROUT_STATIC_CONSTEXPR auto found = sprout::is_heap_until( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::begin(arr1) + 5) + ).base(); + TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 5); + } + { + SPROUT_STATIC_CONSTEXPR auto found = sprout::is_heap_until( + testspr::reduct_random_access(sprout::begin(arr2)), + testspr::reduct_random_access(sprout::begin(arr2) + 5) + ).base(); + TESTSPR_BOTH_ASSERT(found == sprout::begin(arr2) + 5); + } + { + SPROUT_STATIC_CONSTEXPR auto found = sprout::is_heap_until( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::end(arr1)), + testspr::less() + ).base(); + TESTSPR_BOTH_ASSERT(found == sprout::end(arr1)); + } + { + SPROUT_STATIC_CONSTEXPR auto found = sprout::is_heap_until( + testspr::reduct_random_access(sprout::begin(arr2)), + testspr::reduct_random_access(sprout::end(arr2)), + testspr::less() + ).base(); + TESTSPR_BOTH_ASSERT(found == sprout::begin(arr2) + 7); + } + { + SPROUT_STATIC_CONSTEXPR auto found = sprout::is_heap_until( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::begin(arr1) + 5), + testspr::less() + ).base(); + TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 5); + } + { + SPROUT_STATIC_CONSTEXPR auto found = sprout::is_heap_until( + testspr::reduct_random_access(sprout::begin(arr2)), + testspr::reduct_random_access(sprout::begin(arr2) + 5), + testspr::less() + ).base(); + TESTSPR_BOTH_ASSERT(found == sprout::begin(arr2) + 5); + } +#endif } } } // namespace testspr diff --git a/libs/algorithm/test/lexicographical_compare.cpp b/libs/algorithm/test/lexicographical_compare.cpp index 4d0b6f04..06d533a0 100644 --- a/libs/algorithm/test/lexicographical_compare.cpp +++ b/libs/algorithm/test/lexicographical_compare.cpp @@ -148,6 +148,278 @@ namespace testspr { ); TESTSPR_BOTH_ASSERT(!result); } + +#if defined(__clang__) + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::lexicographical_compare( + testspr::reduct_input(sprout::begin(arr1)), + testspr::reduct_input(sprout::end(arr1)), + testspr::reduct_input(sprout::begin(arr2)), + testspr::reduct_input(sprout::end(arr2)) + ); + TESTSPR_BOTH_ASSERT(!result); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::lexicographical_compare( + testspr::reduct_input(sprout::begin(arr1)), + testspr::reduct_input(sprout::end(arr1)), + testspr::reduct_input(sprout::begin(arr3)), + testspr::reduct_input(sprout::end(arr3)) + ); + TESTSPR_BOTH_ASSERT(!result); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::lexicographical_compare( + testspr::reduct_input(sprout::begin(arr1)), + testspr::reduct_input(sprout::end(arr1)), + testspr::reduct_input(sprout::begin(arr4)), + testspr::reduct_input(sprout::end(arr4)) + ); + TESTSPR_BOTH_ASSERT(result); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::lexicographical_compare( + testspr::reduct_input(sprout::begin(arr1)), + testspr::reduct_input(sprout::begin(arr1) + 5), + testspr::reduct_input(sprout::begin(arr2)), + testspr::reduct_input(sprout::end(arr2)) + ); + TESTSPR_BOTH_ASSERT(result); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::lexicographical_compare( + testspr::reduct_input(sprout::begin(arr1)), + testspr::reduct_input(sprout::begin(arr1) + 5), + testspr::reduct_input(sprout::begin(arr3)), + testspr::reduct_input(sprout::end(arr3)) + ); + TESTSPR_BOTH_ASSERT(result); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::lexicographical_compare( + testspr::reduct_input(sprout::begin(arr1)), + testspr::reduct_input(sprout::begin(arr1) + 5), + testspr::reduct_input(sprout::begin(arr4)), + testspr::reduct_input(sprout::end(arr4)) + ); + TESTSPR_BOTH_ASSERT(result); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::lexicographical_compare( + testspr::reduct_input(sprout::begin(arr1)), + testspr::reduct_input(sprout::end(arr1)), + testspr::reduct_input(sprout::begin(arr2)), + testspr::reduct_input(sprout::begin(arr2) + 5) + ); + TESTSPR_BOTH_ASSERT(!result); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::lexicographical_compare( + testspr::reduct_input(sprout::begin(arr1)), + testspr::reduct_input(sprout::end(arr1)), + testspr::reduct_input(sprout::begin(arr2)), + testspr::reduct_input(sprout::end(arr2)), + testspr::less() + ); + TESTSPR_BOTH_ASSERT(!result); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::lexicographical_compare( + testspr::reduct_input(sprout::begin(arr1)), + testspr::reduct_input(sprout::end(arr1)), + testspr::reduct_input(sprout::begin(arr3)), + testspr::reduct_input(sprout::end(arr3)), + testspr::less() + ); + TESTSPR_BOTH_ASSERT(!result); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::lexicographical_compare( + testspr::reduct_input(sprout::begin(arr1)), + testspr::reduct_input(sprout::end(arr1)), + testspr::reduct_input(sprout::begin(arr4)), + testspr::reduct_input(sprout::end(arr4)), + testspr::less() + ); + TESTSPR_BOTH_ASSERT(result); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::lexicographical_compare( + testspr::reduct_input(sprout::begin(arr1)), + testspr::reduct_input(sprout::begin(arr1) + 5), + testspr::reduct_input(sprout::begin(arr2)), + testspr::reduct_input(sprout::end(arr2)), + testspr::less() + ); + TESTSPR_BOTH_ASSERT(result); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::lexicographical_compare( + testspr::reduct_input(sprout::begin(arr1)), + testspr::reduct_input(sprout::begin(arr1) + 5), + testspr::reduct_input(sprout::begin(arr3)), + testspr::reduct_input(sprout::end(arr3)), + testspr::less() + ); + TESTSPR_BOTH_ASSERT(result); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::lexicographical_compare( + testspr::reduct_input(sprout::begin(arr1)), + testspr::reduct_input(sprout::begin(arr1) + 5), + testspr::reduct_input(sprout::begin(arr4)), + testspr::reduct_input(sprout::end(arr4)), + testspr::less() + ); + TESTSPR_BOTH_ASSERT(result); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::lexicographical_compare( + testspr::reduct_input(sprout::begin(arr1)), + testspr::reduct_input(sprout::end(arr1)), + testspr::reduct_input(sprout::begin(arr2)), + testspr::reduct_input(sprout::begin(arr2) + 5), + testspr::less() + ); + TESTSPR_BOTH_ASSERT(!result); + } +#endif + +#if defined(__clang__) + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::lexicographical_compare( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::end(arr1)), + testspr::reduct_random_access(sprout::begin(arr2)), + testspr::reduct_random_access(sprout::end(arr2)) + ); + TESTSPR_BOTH_ASSERT(!result); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::lexicographical_compare( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::end(arr1)), + testspr::reduct_random_access(sprout::begin(arr3)), + testspr::reduct_random_access(sprout::end(arr3)) + ); + TESTSPR_BOTH_ASSERT(!result); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::lexicographical_compare( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::end(arr1)), + testspr::reduct_random_access(sprout::begin(arr4)), + testspr::reduct_random_access(sprout::end(arr4)) + ); + TESTSPR_BOTH_ASSERT(result); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::lexicographical_compare( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::begin(arr1) + 5), + testspr::reduct_random_access(sprout::begin(arr2)), + testspr::reduct_random_access(sprout::end(arr2)) + ); + TESTSPR_BOTH_ASSERT(result); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::lexicographical_compare( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::begin(arr1) + 5), + testspr::reduct_random_access(sprout::begin(arr3)), + testspr::reduct_random_access(sprout::end(arr3)) + ); + TESTSPR_BOTH_ASSERT(result); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::lexicographical_compare( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::begin(arr1) + 5), + testspr::reduct_random_access(sprout::begin(arr4)), + testspr::reduct_random_access(sprout::end(arr4)) + ); + TESTSPR_BOTH_ASSERT(result); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::lexicographical_compare( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::end(arr1)), + testspr::reduct_random_access(sprout::begin(arr2)), + testspr::reduct_random_access(sprout::begin(arr2) + 5) + ); + TESTSPR_BOTH_ASSERT(!result); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::lexicographical_compare( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::end(arr1)), + testspr::reduct_random_access(sprout::begin(arr2)), + testspr::reduct_random_access(sprout::end(arr2)), + testspr::less() + ); + TESTSPR_BOTH_ASSERT(!result); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::lexicographical_compare( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::end(arr1)), + testspr::reduct_random_access(sprout::begin(arr3)), + testspr::reduct_random_access(sprout::end(arr3)), + testspr::less() + ); + TESTSPR_BOTH_ASSERT(!result); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::lexicographical_compare( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::end(arr1)), + testspr::reduct_random_access(sprout::begin(arr4)), + testspr::reduct_random_access(sprout::end(arr4)), + testspr::less() + ); + TESTSPR_BOTH_ASSERT(result); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::lexicographical_compare( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::begin(arr1) + 5), + testspr::reduct_random_access(sprout::begin(arr2)), + testspr::reduct_random_access(sprout::end(arr2)), + testspr::less() + ); + TESTSPR_BOTH_ASSERT(result); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::lexicographical_compare( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::begin(arr1) + 5), + testspr::reduct_random_access(sprout::begin(arr3)), + testspr::reduct_random_access(sprout::end(arr3)), + testspr::less() + ); + TESTSPR_BOTH_ASSERT(result); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::lexicographical_compare( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::begin(arr1) + 5), + testspr::reduct_random_access(sprout::begin(arr4)), + testspr::reduct_random_access(sprout::end(arr4)), + testspr::less() + ); + TESTSPR_BOTH_ASSERT(result); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::lexicographical_compare( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::end(arr1)), + testspr::reduct_random_access(sprout::begin(arr2)), + testspr::reduct_random_access(sprout::begin(arr2) + 5), + testspr::less() + ); + TESTSPR_BOTH_ASSERT(!result); + } +#endif } } } // namespace testspr diff --git a/libs/algorithm/test/max_element.cpp b/libs/algorithm/test/max_element.cpp index d25cb2ee..1653097d 100644 --- a/libs/algorithm/test/max_element.cpp +++ b/libs/algorithm/test/max_element.cpp @@ -42,6 +42,70 @@ namespace testspr { ); TESTSPR_BOTH_ASSERT(result == sprout::begin(arr1) + 4); } + + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::max_element( + testspr::reduct_forward(sprout::begin(arr1)), + testspr::reduct_forward(sprout::end(arr1)) + ).base(); + TESTSPR_BOTH_ASSERT(result == sprout::begin(arr1) + 8); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::max_element( + testspr::reduct_forward(sprout::begin(arr1)), + testspr::reduct_forward(sprout::begin(arr1) + 5) + ).base(); + TESTSPR_BOTH_ASSERT(result == sprout::begin(arr1) + 4); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::max_element( + testspr::reduct_forward(sprout::begin(arr1)), + testspr::reduct_forward(sprout::end(arr1)), + testspr::less() + ).base(); + TESTSPR_BOTH_ASSERT(result == sprout::begin(arr1) + 8); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::max_element( + testspr::reduct_forward(sprout::begin(arr1)), + testspr::reduct_forward(sprout::begin(arr1) + 5), + testspr::less() + ).base(); + TESTSPR_BOTH_ASSERT(result == sprout::begin(arr1) + 4); + } + +#if defined(__clang__) + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::max_element( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::end(arr1)) + ).base(); + TESTSPR_BOTH_ASSERT(result == sprout::begin(arr1) + 8); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::max_element( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::begin(arr1) + 5) + ).base(); + TESTSPR_BOTH_ASSERT(result == sprout::begin(arr1) + 4); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::max_element( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::end(arr1)), + testspr::less() + ).base(); + TESTSPR_BOTH_ASSERT(result == sprout::begin(arr1) + 8); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::max_element( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::begin(arr1) + 5), + testspr::less() + ).base(); + TESTSPR_BOTH_ASSERT(result == sprout::begin(arr1) + 4); + } +#endif } } } // namespace testspr diff --git a/libs/algorithm/test/min_element.cpp b/libs/algorithm/test/min_element.cpp index be3cdece..99a010ed 100644 --- a/libs/algorithm/test/min_element.cpp +++ b/libs/algorithm/test/min_element.cpp @@ -42,6 +42,70 @@ namespace testspr { ); TESTSPR_BOTH_ASSERT(result == sprout::begin(arr1) + 3); } + + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::min_element( + testspr::reduct_forward(sprout::begin(arr1)), + testspr::reduct_forward(sprout::end(arr1)) + ).base(); + TESTSPR_BOTH_ASSERT(result == sprout::begin(arr1) + 9); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::min_element( + testspr::reduct_forward(sprout::begin(arr1)), + testspr::reduct_forward(sprout::begin(arr1) + 5) + ).base(); + TESTSPR_BOTH_ASSERT(result == sprout::begin(arr1) + 3); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::min_element( + testspr::reduct_forward(sprout::begin(arr1)), + testspr::reduct_forward(sprout::end(arr1)), + testspr::less() + ).base(); + TESTSPR_BOTH_ASSERT(result == sprout::begin(arr1) + 9); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::min_element( + testspr::reduct_forward(sprout::begin(arr1)), + testspr::reduct_forward(sprout::begin(arr1) + 5), + testspr::less() + ).base(); + TESTSPR_BOTH_ASSERT(result == sprout::begin(arr1) + 3); + } + +#if defined(__clang__) + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::min_element( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::end(arr1)) + ).base(); + TESTSPR_BOTH_ASSERT(result == sprout::begin(arr1) + 9); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::min_element( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::begin(arr1) + 5) + ).base(); + TESTSPR_BOTH_ASSERT(result == sprout::begin(arr1) + 3); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::min_element( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::end(arr1)), + testspr::less() + ).base(); + TESTSPR_BOTH_ASSERT(result == sprout::begin(arr1) + 9); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::min_element( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::begin(arr1) + 5), + testspr::less() + ).base(); + TESTSPR_BOTH_ASSERT(result == sprout::begin(arr1) + 3); + } +#endif } } } // namespace testspr diff --git a/libs/algorithm/test/minmax_element.cpp b/libs/algorithm/test/minmax_element.cpp index 45c76d1a..8a8af325 100644 --- a/libs/algorithm/test/minmax_element.cpp +++ b/libs/algorithm/test/minmax_element.cpp @@ -46,6 +46,78 @@ namespace testspr { TESTSPR_BOTH_ASSERT(result.first == sprout::begin(arr1) + 3); TESTSPR_BOTH_ASSERT(result.second == sprout::begin(arr1) + 4); } + + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::minmax_element( + testspr::reduct_forward(sprout::begin(arr1)), + testspr::reduct_forward(sprout::end(arr1)) + ); + TESTSPR_BOTH_ASSERT(result.first.base() == sprout::begin(arr1) + 9); + TESTSPR_BOTH_ASSERT(result.second.base() == sprout::begin(arr1) + 8); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::minmax_element( + testspr::reduct_forward(sprout::begin(arr1)), + testspr::reduct_forward(sprout::begin(arr1) + 5) + ); + TESTSPR_BOTH_ASSERT(result.first.base() == sprout::begin(arr1) + 3); + TESTSPR_BOTH_ASSERT(result.second.base() == sprout::begin(arr1) + 4); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::minmax_element( + testspr::reduct_forward(sprout::begin(arr1)), + testspr::reduct_forward(sprout::end(arr1)), + testspr::less() + ); + TESTSPR_BOTH_ASSERT(result.first.base() == sprout::begin(arr1) + 9); + TESTSPR_BOTH_ASSERT(result.second.base() == sprout::begin(arr1) + 8); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::minmax_element( + testspr::reduct_forward(sprout::begin(arr1)), + testspr::reduct_forward(sprout::begin(arr1) + 5), + testspr::less() + ); + TESTSPR_BOTH_ASSERT(result.first.base() == sprout::begin(arr1) + 3); + TESTSPR_BOTH_ASSERT(result.second.base() == sprout::begin(arr1) + 4); + } + +#if defined(__clang__) + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::minmax_element( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::end(arr1)) + ); + TESTSPR_BOTH_ASSERT(result.first.base() == sprout::begin(arr1) + 9); + TESTSPR_BOTH_ASSERT(result.second.base() == sprout::begin(arr1) + 8); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::minmax_element( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::begin(arr1) + 5) + ); + TESTSPR_BOTH_ASSERT(result.first.base() == sprout::begin(arr1) + 3); + TESTSPR_BOTH_ASSERT(result.second.base() == sprout::begin(arr1) + 4); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::minmax_element( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::end(arr1)), + testspr::less() + ); + TESTSPR_BOTH_ASSERT(result.first.base() == sprout::begin(arr1) + 9); + TESTSPR_BOTH_ASSERT(result.second.base() == sprout::begin(arr1) + 8); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::minmax_element( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::begin(arr1) + 5), + testspr::less() + ); + TESTSPR_BOTH_ASSERT(result.first.base() == sprout::begin(arr1) + 3); + TESTSPR_BOTH_ASSERT(result.second.base() == sprout::begin(arr1) + 4); + } +#endif } } } // namespace testspr diff --git a/libs/algorithm/test/non_modifying.cpp b/libs/algorithm/test/non_modifying.cpp index 341a3160..dd89fac8 100644 --- a/libs/algorithm/test/non_modifying.cpp +++ b/libs/algorithm/test/non_modifying.cpp @@ -45,6 +45,7 @@ #include "./any_of_equal.cpp" #include "./none_of_equal.cpp" #include "./one_of_equal.cpp" +#include "./tristate_lexicographical_compare.cpp" #include "./is_increasing.cpp" #include "./is_decreasing.cpp" #include "./is_strictly_increasing.cpp" @@ -96,6 +97,7 @@ namespace testspr { testspr::algorithm_any_of_equal_test(); testspr::algorithm_none_of_equal_test(); testspr::algorithm_one_of_equal_test(); + testspr::algorithm_tristate_lexicographical_compare_test(); testspr::algorithm_is_increasing_test(); testspr::algorithm_is_decreasing_test(); testspr::algorithm_is_strictly_increasing_test(); diff --git a/libs/algorithm/test/tristate_lexicographical_compare.cpp b/libs/algorithm/test/tristate_lexicographical_compare.cpp new file mode 100644 index 00000000..b937c6b4 --- /dev/null +++ b/libs/algorithm/test/tristate_lexicographical_compare.cpp @@ -0,0 +1,432 @@ +#ifndef SPROUT_LIBS_ALGORITHM_TEST_TRISTATE_LEXICOGRAPHICAL_COMPARE_CPP +#define SPROUT_LIBS_ALGORITHM_TEST_TRISTATE_LEXICOGRAPHICAL_COMPARE_CPP + +#include +#include +#include +#include + +namespace testspr { + static void algorithm_tristate_lexicographical_compare_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}; + SPROUT_STATIC_CONSTEXPR auto arr2 = array{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}; + SPROUT_STATIC_CONSTEXPR auto arr3 = array{{1, 2, 3, 4, 5, 6, 7, 1, 2, 3}}; + SPROUT_STATIC_CONSTEXPR auto arr4 = array{{1, 2, 3, 4, 5, 6, 7, 11, 12, 13}}; + + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::tristate_lexicographical_compare( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr2), + sprout::end(arr2) + ); + TESTSPR_BOTH_ASSERT(result == 0); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::tristate_lexicographical_compare( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr3), + sprout::end(arr3) + ); + TESTSPR_BOTH_ASSERT(result > 0); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::tristate_lexicographical_compare( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr4), + sprout::end(arr4) + ); + TESTSPR_BOTH_ASSERT(result < 0); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::tristate_lexicographical_compare( + sprout::begin(arr1), + sprout::begin(arr1) + 5, + sprout::begin(arr2), + sprout::end(arr2) + ); + TESTSPR_BOTH_ASSERT(result < 0); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::tristate_lexicographical_compare( + sprout::begin(arr1), + sprout::begin(arr1) + 5, + sprout::begin(arr3), + sprout::end(arr3) + ); + TESTSPR_BOTH_ASSERT(result < 0); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::tristate_lexicographical_compare( + sprout::begin(arr1), + sprout::begin(arr1) + 5, + sprout::begin(arr4), + sprout::end(arr4) + ); + TESTSPR_BOTH_ASSERT(result < 0); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::tristate_lexicographical_compare( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr2), + sprout::begin(arr2) + 5 + ); + TESTSPR_BOTH_ASSERT(result > 0); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::tristate_lexicographical_compare( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr2), + sprout::end(arr2), + testspr::less() + ); + TESTSPR_BOTH_ASSERT(result == 0); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::tristate_lexicographical_compare( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr3), + sprout::end(arr3), + testspr::less() + ); + TESTSPR_BOTH_ASSERT(result > 0); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::tristate_lexicographical_compare( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr4), + sprout::end(arr4), + testspr::less() + ); + TESTSPR_BOTH_ASSERT(result < 0); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::tristate_lexicographical_compare( + sprout::begin(arr1), + sprout::begin(arr1) + 5, + sprout::begin(arr2), + sprout::end(arr2), + testspr::less() + ); + TESTSPR_BOTH_ASSERT(result < 0); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::tristate_lexicographical_compare( + sprout::begin(arr1), + sprout::begin(arr1) + 5, + sprout::begin(arr3), + sprout::end(arr3), + testspr::less() + ); + TESTSPR_BOTH_ASSERT(result < 0); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::tristate_lexicographical_compare( + sprout::begin(arr1), + sprout::begin(arr1) + 5, + sprout::begin(arr4), + sprout::end(arr4), + testspr::less() + ); + TESTSPR_BOTH_ASSERT(result < 0); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::tristate_lexicographical_compare( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr2), + sprout::begin(arr2) + 5, + testspr::less() + ); + TESTSPR_BOTH_ASSERT(result > 0); + } + +#if defined(__clang__) + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::tristate_lexicographical_compare( + testspr::reduct_input(sprout::begin(arr1)), + testspr::reduct_input(sprout::end(arr1)), + testspr::reduct_input(sprout::begin(arr2)), + testspr::reduct_input(sprout::end(arr2)) + ); + TESTSPR_BOTH_ASSERT(result == 0); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::tristate_lexicographical_compare( + testspr::reduct_input(sprout::begin(arr1)), + testspr::reduct_input(sprout::end(arr1)), + testspr::reduct_input(sprout::begin(arr3)), + testspr::reduct_input(sprout::end(arr3)) + ); + TESTSPR_BOTH_ASSERT(result > 0); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::tristate_lexicographical_compare( + testspr::reduct_input(sprout::begin(arr1)), + testspr::reduct_input(sprout::end(arr1)), + testspr::reduct_input(sprout::begin(arr4)), + testspr::reduct_input(sprout::end(arr4)) + ); + TESTSPR_BOTH_ASSERT(result < 0); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::tristate_lexicographical_compare( + testspr::reduct_input(sprout::begin(arr1)), + testspr::reduct_input(sprout::begin(arr1) + 5), + testspr::reduct_input(sprout::begin(arr2)), + testspr::reduct_input(sprout::end(arr2)) + ); + TESTSPR_BOTH_ASSERT(result < 0); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::tristate_lexicographical_compare( + testspr::reduct_input(sprout::begin(arr1)), + testspr::reduct_input(sprout::begin(arr1) + 5), + testspr::reduct_input(sprout::begin(arr3)), + testspr::reduct_input(sprout::end(arr3)) + ); + TESTSPR_BOTH_ASSERT(result < 0); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::tristate_lexicographical_compare( + testspr::reduct_input(sprout::begin(arr1)), + testspr::reduct_input(sprout::begin(arr1) + 5), + testspr::reduct_input(sprout::begin(arr4)), + testspr::reduct_input(sprout::end(arr4)) + ); + TESTSPR_BOTH_ASSERT(result < 0); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::tristate_lexicographical_compare( + testspr::reduct_input(sprout::begin(arr1)), + testspr::reduct_input(sprout::end(arr1)), + testspr::reduct_input(sprout::begin(arr2)), + testspr::reduct_input(sprout::begin(arr2) + 5) + ); + TESTSPR_BOTH_ASSERT(result > 0); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::tristate_lexicographical_compare( + testspr::reduct_input(sprout::begin(arr1)), + testspr::reduct_input(sprout::end(arr1)), + testspr::reduct_input(sprout::begin(arr2)), + testspr::reduct_input(sprout::end(arr2)), + testspr::less() + ); + TESTSPR_BOTH_ASSERT(result == 0); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::tristate_lexicographical_compare( + testspr::reduct_input(sprout::begin(arr1)), + testspr::reduct_input(sprout::end(arr1)), + testspr::reduct_input(sprout::begin(arr3)), + testspr::reduct_input(sprout::end(arr3)), + testspr::less() + ); + TESTSPR_BOTH_ASSERT(result > 0); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::tristate_lexicographical_compare( + testspr::reduct_input(sprout::begin(arr1)), + testspr::reduct_input(sprout::end(arr1)), + testspr::reduct_input(sprout::begin(arr4)), + testspr::reduct_input(sprout::end(arr4)), + testspr::less() + ); + TESTSPR_BOTH_ASSERT(result < 0); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::tristate_lexicographical_compare( + testspr::reduct_input(sprout::begin(arr1)), + testspr::reduct_input(sprout::begin(arr1) + 5), + testspr::reduct_input(sprout::begin(arr2)), + testspr::reduct_input(sprout::end(arr2)), + testspr::less() + ); + TESTSPR_BOTH_ASSERT(result < 0); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::tristate_lexicographical_compare( + testspr::reduct_input(sprout::begin(arr1)), + testspr::reduct_input(sprout::begin(arr1) + 5), + testspr::reduct_input(sprout::begin(arr3)), + testspr::reduct_input(sprout::end(arr3)), + testspr::less() + ); + TESTSPR_BOTH_ASSERT(result < 0); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::tristate_lexicographical_compare( + testspr::reduct_input(sprout::begin(arr1)), + testspr::reduct_input(sprout::begin(arr1) + 5), + testspr::reduct_input(sprout::begin(arr4)), + testspr::reduct_input(sprout::end(arr4)), + testspr::less() + ); + TESTSPR_BOTH_ASSERT(result < 0); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::tristate_lexicographical_compare( + testspr::reduct_input(sprout::begin(arr1)), + testspr::reduct_input(sprout::end(arr1)), + testspr::reduct_input(sprout::begin(arr2)), + testspr::reduct_input(sprout::begin(arr2) + 5), + testspr::less() + ); + TESTSPR_BOTH_ASSERT(result > 0); + } +#endif + +#if defined(__clang__) + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::tristate_lexicographical_compare( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::end(arr1)), + testspr::reduct_random_access(sprout::begin(arr2)), + testspr::reduct_random_access(sprout::end(arr2)) + ); + TESTSPR_BOTH_ASSERT(result == 0); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::tristate_lexicographical_compare( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::end(arr1)), + testspr::reduct_random_access(sprout::begin(arr3)), + testspr::reduct_random_access(sprout::end(arr3)) + ); + TESTSPR_BOTH_ASSERT(result > 0); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::tristate_lexicographical_compare( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::end(arr1)), + testspr::reduct_random_access(sprout::begin(arr4)), + testspr::reduct_random_access(sprout::end(arr4)) + ); + TESTSPR_BOTH_ASSERT(result < 0); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::tristate_lexicographical_compare( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::begin(arr1) + 5), + testspr::reduct_random_access(sprout::begin(arr2)), + testspr::reduct_random_access(sprout::end(arr2)) + ); + TESTSPR_BOTH_ASSERT(result < 0); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::tristate_lexicographical_compare( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::begin(arr1) + 5), + testspr::reduct_random_access(sprout::begin(arr3)), + testspr::reduct_random_access(sprout::end(arr3)) + ); + TESTSPR_BOTH_ASSERT(result < 0); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::tristate_lexicographical_compare( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::begin(arr1) + 5), + testspr::reduct_random_access(sprout::begin(arr4)), + testspr::reduct_random_access(sprout::end(arr4)) + ); + TESTSPR_BOTH_ASSERT(result < 0); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::tristate_lexicographical_compare( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::end(arr1)), + testspr::reduct_random_access(sprout::begin(arr2)), + testspr::reduct_random_access(sprout::begin(arr2) + 5) + ); + TESTSPR_BOTH_ASSERT(result > 0); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::tristate_lexicographical_compare( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::end(arr1)), + testspr::reduct_random_access(sprout::begin(arr2)), + testspr::reduct_random_access(sprout::end(arr2)), + testspr::less() + ); + TESTSPR_BOTH_ASSERT(result == 0); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::tristate_lexicographical_compare( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::end(arr1)), + testspr::reduct_random_access(sprout::begin(arr3)), + testspr::reduct_random_access(sprout::end(arr3)), + testspr::less() + ); + TESTSPR_BOTH_ASSERT(result > 0); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::tristate_lexicographical_compare( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::end(arr1)), + testspr::reduct_random_access(sprout::begin(arr4)), + testspr::reduct_random_access(sprout::end(arr4)), + testspr::less() + ); + TESTSPR_BOTH_ASSERT(result < 0); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::tristate_lexicographical_compare( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::begin(arr1) + 5), + testspr::reduct_random_access(sprout::begin(arr2)), + testspr::reduct_random_access(sprout::end(arr2)), + testspr::less() + ); + TESTSPR_BOTH_ASSERT(result < 0); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::tristate_lexicographical_compare( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::begin(arr1) + 5), + testspr::reduct_random_access(sprout::begin(arr3)), + testspr::reduct_random_access(sprout::end(arr3)), + testspr::less() + ); + TESTSPR_BOTH_ASSERT(result < 0); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::tristate_lexicographical_compare( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::begin(arr1) + 5), + testspr::reduct_random_access(sprout::begin(arr4)), + testspr::reduct_random_access(sprout::end(arr4)), + testspr::less() + ); + TESTSPR_BOTH_ASSERT(result < 0); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::tristate_lexicographical_compare( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::end(arr1)), + testspr::reduct_random_access(sprout::begin(arr2)), + testspr::reduct_random_access(sprout::begin(arr2) + 5), + testspr::less() + ); + TESTSPR_BOTH_ASSERT(result > 0); + } +#endif + } + } +} // namespace testspr + +#ifndef TESTSPR_CPP_INCLUDE +# define TESTSPR_TEST_FUNCTION testspr::algorithm_tristate_lexicographical_compare_test +# include +#endif + +#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_TRISTATE_LEXICOGRAPHICAL_COMPARE_CPP diff --git a/sprout/algorithm/includes.hpp b/sprout/algorithm/includes.hpp index 7679d106..d19a74a1 100644 --- a/sprout/algorithm/includes.hpp +++ b/sprout/algorithm/includes.hpp @@ -2,16 +2,19 @@ #define SPROUT_ALGORITHM_INCLUDES_HPP #include +#include #include #include +#include #include +#include namespace sprout { namespace detail { - template - inline SPROUT_CONSTEXPR RandomAccessIterator2 + template + inline SPROUT_CONSTEXPR InputIterator2 includes_impl_ra( - RandomAccessIterator1 first1, RandomAccessIterator1 last1, RandomAccessIterator2 first2, RandomAccessIterator2 last2, Compare comp, + RandomAccessIterator1 first1, RandomAccessIterator1 last1, InputIterator2 first2, InputIterator2 last2, Compare comp, typename std::iterator_traits::difference_type pivot ) { @@ -30,10 +33,13 @@ namespace sprout { ) ; } - template - inline SPROUT_CONSTEXPR bool + template + inline SPROUT_CONSTEXPR typename std::enable_if< + sprout::is_constant_distance_iterator::value, + bool + >::type includes( - RandomAccessIterator1 first1, RandomAccessIterator1 last1, RandomAccessIterator2 first2, RandomAccessIterator2 last2, Compare comp, + RandomAccessIterator1 first1, RandomAccessIterator1 last1, InputIterator2 first2, InputIterator2 last2, Compare comp, std::random_access_iterator_tag* ) { @@ -46,33 +52,67 @@ namespace sprout { ; } - // Copyright (C) 2011 RiSK (sscrisk) template - inline SPROUT_CONSTEXPR bool - includes_impl(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, Compare comp) { - return first2 == last2 ? true - : first1 == last1 ? false - : !comp(*first1, *first2) && !comp(*first2, *first1) - ? sprout::detail::includes_impl(sprout::next(first1), last1, sprout::next(first2), last2) - : sprout::detail::includes_impl(sprout::next(first1), last1, first2, last2) + inline SPROUT_CONSTEXPR sprout::pair + includes_impl_1( + sprout::pair const& current, + InputIterator1 last1, InputIterator2 last2, Compare comp, + typename std::iterator_traits::difference_type n + ) + { + typedef sprout::pair type; + return current.second == last2 || current.first == last1 ? current + : n == 1 ? !comp(*current.first, *current.second) && !comp(*current.second, *current.first) + ? type(sprout::next(current.first), sprout::next(current.second)) + : type(sprout::next(current.first), current.second) + : sprout::detail::includes_impl_1( + sprout::detail::includes_impl_1( + current, + last1, last2, comp, n / 2 + ), + last1, last2, comp, n - n / 2 + ) + ; + } + template + inline SPROUT_CONSTEXPR sprout::pair + includes_impl( + sprout::pair const& current, + InputIterator1 last1, InputIterator2 last2, Compare comp, + typename std::iterator_traits::difference_type n + ) + { + typedef sprout::pair type; + return current.second == last2 || current.first == last1 ? current + : sprout::detail::includes_impl( + sprout::detail::includes_impl_1( + current, + last1, last2, comp, n + ), + last1, last2, comp, n * 2 + ) ; } template inline SPROUT_CONSTEXPR bool includes( - InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, Compare comp, + InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2, + Compare comp, void* ) { - return sprout::detail::includes_impl(first1, last1, first2, comp); + typedef sprout::pair type; + return first2 == last2 ? true + : sprout::detail::includes_impl(type(first1, first2), last1, last2, comp, 1).second == last2 + ; } } // namespace detail // 25.4.5.1 includes // // recursion depth: - // [first, last) is RandomAccessIterator -> O(log N) - // otherwise -> O(N) + // O(log(N1+N2)) // template inline SPROUT_CONSTEXPR bool diff --git a/sprout/algorithm/lexicographical_compare.hpp b/sprout/algorithm/lexicographical_compare.hpp index 1afcaf43..0bc171f8 100644 --- a/sprout/algorithm/lexicographical_compare.hpp +++ b/sprout/algorithm/lexicographical_compare.hpp @@ -1,8 +1,11 @@ #ifndef SPROUT_ALGORITHM_LEXICOGRAPHICAL_COMPARE_HPP #define SPROUT_ALGORITHM_LEXICOGRAPHICAL_COMPARE_HPP +#include +#include #include #include +#include #include #include #include @@ -12,7 +15,7 @@ namespace sprout { namespace detail { template inline SPROUT_CONSTEXPR bool - lexicographical_compare_impl_ra_2( + lexicographical_compare_impl_check( RandomAccessIterator1 last1, RandomAccessIterator2 last2, Compare comp, sprout::pair const& found ) @@ -21,6 +24,7 @@ namespace sprout { : found.first == last1 || comp(*found.first, *found.second) ; } + template inline SPROUT_CONSTEXPR sprout::pair lexicographical_compare_impl_ra_1( @@ -50,7 +54,7 @@ namespace sprout { ) { typedef sprout::pair found_type; - return sprout::detail::lexicographical_compare_impl_ra_2( + return sprout::detail::lexicographical_compare_impl_check( last1, last2, comp, sprout::detail::lexicographical_compare_impl_ra_1( first1, sprout::next(first1, size), first2, sprout::next(first2, size), comp, @@ -59,7 +63,10 @@ namespace sprout { ); } template - inline SPROUT_CONSTEXPR bool + inline SPROUT_CONSTEXPR typename std::enable_if< + sprout::is_constant_distance_iterator::value, + bool + >::type lexicographical_compare( RandomAccessIterator1 first1, RandomAccessIterator1 last1, RandomAccessIterator2 first2, RandomAccessIterator2 last2, Compare comp, std::random_access_iterator_tag* @@ -74,14 +81,45 @@ namespace sprout { ; } - // Copyright (C) 2011 RiSK (sscrisk) template - inline SPROUT_CONSTEXPR bool - lexicographical_compare_impl(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, Compare comp) { - return first2 == last2 ? false - : first1 == last1 || comp(*first1, *first2) ? true - : comp(*first2, *first1) ? false - : sprout::detail::lexicographical_compare_impl(sprout::next(first1), last1, sprout::next(first2), last2, comp) + inline SPROUT_CONSTEXPR sprout::pair + lexicographical_compare_impl_1( + sprout::pair current, + InputIterator1 last1, InputIterator2 last2, Compare comp, + typename std::iterator_traits::difference_type n + ) + { + typedef sprout::pair type; + return current.second == last2 || current.first == last1 ? current + : n == 1 ? comp(*current.first, *current.second) ? type(last1, current.second) + : comp(*current.second, *current.first) ? type(current.first, last2) + : type(sprout::next(current.first), sprout::next(current.second)) + : sprout::detail::lexicographical_compare_impl_1( + sprout::detail::lexicographical_compare_impl_1( + current, + last1, last2, comp, n / 2 + ), + last1, last2, comp, n - n / 2 + ) + ; + } + template + inline SPROUT_CONSTEXPR sprout::pair + lexicographical_compare_impl( + sprout::pair current, + InputIterator1 last1, InputIterator2 last2, Compare comp, + typename std::iterator_traits::difference_type n + ) + { + typedef sprout::pair type; + return current.second == last2 || current.first == last1 ? current + : sprout::detail::lexicographical_compare_impl( + sprout::detail::lexicographical_compare_impl_1( + current, + last1, last2, comp, n + ), + last1, last2, comp, n * 2 + ) ; } template @@ -91,15 +129,18 @@ namespace sprout { void* ) { - return sprout::detail::lexicographical_compare_impl(first1, last1, first2, last2, comp); + typedef sprout::pair type; + return sprout::detail::lexicographical_compare_impl_check( + last1, last2, comp, + sprout::detail::lexicographical_compare_impl(type(first1, first2), last1, last2, comp, 1) + ); } } // namespace detail // 25.4.8 Lexicographical comparison // // recursion depth: - // [first1, last1), [first2, last2) are RandomAccessIterator -> O(log N) - // otherwise -> O(N) + // O(log(N1+N2)) // template inline SPROUT_CONSTEXPR bool diff --git a/sprout/algorithm/max_element.hpp b/sprout/algorithm/max_element.hpp index c2f536aa..9dc1ac55 100644 --- a/sprout/algorithm/max_element.hpp +++ b/sprout/algorithm/max_element.hpp @@ -2,8 +2,11 @@ #define SPROUT_ALGORITHM_MAX_ELEMENT_HPP #include +#include #include #include +#include +#include #include HDR_FUNCTIONAL_SSCRISK_CEL_OR_SPROUT namespace sprout { @@ -36,7 +39,10 @@ namespace sprout { ; } template - inline SPROUT_CONSTEXPR RandomAccessIterator + inline SPROUT_CONSTEXPR typename std::enable_if< + sprout::is_constant_distance_iterator::value, + RandomAccessIterator + >::type max_element( RandomAccessIterator first, RandomAccessIterator last, Compare comp, std::random_access_iterator_tag* @@ -50,16 +56,41 @@ namespace sprout { ; } - // Copyright (C) 2011 RiSK (sscrisk) template - inline SPROUT_CONSTEXPR ForwardIterator - max_element_impl( - ForwardIterator first, ForwardIterator last, Compare comp, - ForwardIterator found + inline SPROUT_CONSTEXPR sprout::pair + max_element_impl_1( + sprout::pair const& current, + ForwardIterator last, Compare comp, typename std::iterator_traits::difference_type n ) { - return first == last ? found - : sprout::detail::max_element_impl(sprout::next(first), last, comp, sprout::detail::iter_max(found, first, comp)) + typedef sprout::pair type; + return current.first == last ? current + : n == 1 ? type(sprout::next(current.first), sprout::detail::iter_max(current.second, current.first, comp)) + : sprout::detail::max_element_impl_1( + sprout::detail::max_element_impl_1( + current, + last, comp, n / 2 + ), + last, comp, n - n / 2 + ) + ; + } + template + inline SPROUT_CONSTEXPR sprout::pair + max_element_impl( + sprout::pair const& current, + ForwardIterator last, Compare comp, typename std::iterator_traits::difference_type n + ) + { + typedef sprout::pair type; + return current.first == last ? current + : sprout::detail::max_element_impl( + sprout::detail::max_element_impl_1( + current, + last, comp, n + ), + last, comp, n * 2 + ) ; } template @@ -69,8 +100,9 @@ namespace sprout { void* ) { + typedef sprout::pair type; return first == last ? last - : sprout::detail::max_element_impl(sprout::next(first), last, comp, first) + : sprout::detail::max_element_impl(type(sprout::next(first), first), last, comp, 1).second ; } } // namespace detail @@ -78,8 +110,7 @@ namespace sprout { // 25.4.7 Minimum and maximum // // recursion depth: - // [first, last) is RandomAccessIterator -> O(log N) - // otherwise -> O(N) + // O(log N) // template inline SPROUT_CONSTEXPR ForwardIterator diff --git a/sprout/algorithm/min_element.hpp b/sprout/algorithm/min_element.hpp index c5daef38..b58417f1 100644 --- a/sprout/algorithm/min_element.hpp +++ b/sprout/algorithm/min_element.hpp @@ -2,15 +2,18 @@ #define SPROUT_ALGORITHM_MIN_ELEMENT_HPP #include +#include #include #include +#include +#include #include HDR_FUNCTIONAL_SSCRISK_CEL_OR_SPROUT namespace sprout { namespace detail { - template - inline SPROUT_CONSTEXPR InputIterator - iter_min(InputIterator a, InputIterator b, Compare comp) { + template + inline SPROUT_CONSTEXPR ForwardIterator + iter_min(ForwardIterator a, ForwardIterator b, Compare comp) { return comp(*b, *a) ? b : a; } @@ -36,7 +39,10 @@ namespace sprout { ; } template - inline SPROUT_CONSTEXPR RandomAccessIterator + inline SPROUT_CONSTEXPR typename std::enable_if< + sprout::is_constant_distance_iterator::value, + RandomAccessIterator + >::type min_element( RandomAccessIterator first, RandomAccessIterator last, Compare comp, std::random_access_iterator_tag* @@ -50,16 +56,41 @@ namespace sprout { ; } - // Copyright (C) 2011 RiSK (sscrisk) template - inline SPROUT_CONSTEXPR ForwardIterator - min_element_impl( - ForwardIterator first, ForwardIterator last, Compare comp, - ForwardIterator found + inline SPROUT_CONSTEXPR sprout::pair + min_element_impl_1( + sprout::pair const& current, + ForwardIterator last, Compare comp, typename std::iterator_traits::difference_type n ) { - return first == last ? found - : sprout::detail::min_element_impl(sprout::next(first), last, comp, sprout::detail::iter_min(found, first, comp)) + typedef sprout::pair type; + return current.first == last ? current + : n == 1 ? type(sprout::next(current.first), sprout::detail::iter_min(current.second, current.first, comp)) + : sprout::detail::min_element_impl_1( + sprout::detail::min_element_impl_1( + current, + last, comp, n / 2 + ), + last, comp, n - n / 2 + ) + ; + } + template + inline SPROUT_CONSTEXPR sprout::pair + min_element_impl( + sprout::pair const& current, + ForwardIterator last, Compare comp, typename std::iterator_traits::difference_type n + ) + { + typedef sprout::pair type; + return current.first == last ? current + : sprout::detail::min_element_impl( + sprout::detail::min_element_impl_1( + current, + last, comp, n + ), + last, comp, n * 2 + ) ; } template @@ -69,8 +100,9 @@ namespace sprout { void* ) { + typedef sprout::pair type; return first == last ? last - : sprout::detail::min_element_impl(sprout::next(first), last, comp, first) + : sprout::detail::min_element_impl(type(sprout::next(first), first), last, comp, 1).second ; } } // namespace detail @@ -78,8 +110,7 @@ namespace sprout { // 25.4.7 Minimum and maximum // // recursion depth: - // [first, last) is RandomAccessIterator -> O(log N) - // otherwise -> O(N) + // O(log N) // template inline SPROUT_CONSTEXPR ForwardIterator diff --git a/sprout/algorithm/minmax_element.hpp b/sprout/algorithm/minmax_element.hpp index 79ba0d01..72fe0873 100644 --- a/sprout/algorithm/minmax_element.hpp +++ b/sprout/algorithm/minmax_element.hpp @@ -2,8 +2,10 @@ #define SPROUT_ALGORITHM_MINMAX_ELEMENT_HPP #include +#include #include #include +#include #include #include HDR_FUNCTIONAL_SSCRISK_CEL_OR_SPROUT @@ -11,12 +13,20 @@ namespace sprout { namespace detail { template inline SPROUT_CONSTEXPR InputIteratorPair - iter_minmax(InputIteratorPair a, InputIteratorPair b, Compare comp) { + iter_minmax_pair(InputIteratorPair const& a, InputIteratorPair const& b, Compare comp) { return InputIteratorPair( comp(*sprout::first(b), *sprout::first(a)) ? sprout::first(b) : sprout::first(a), comp(*sprout::second(a), *sprout::second(b)) ? sprout::second(b) : sprout::second(a) ); } + template + inline SPROUT_CONSTEXPR InputIteratorPair + iter_minmax(InputIteratorPair const& a, InputIterator b, Compare comp) { + return InputIteratorPair( + comp(*b, *sprout::first(a)) ? b : sprout::first(a), + comp(*sprout::second(a), *b) ? b : sprout::second(a) + ); + } template inline SPROUT_CONSTEXPR sprout::pair @@ -26,7 +36,7 @@ namespace sprout { ) { return pivot == 0 ? sprout::pair(first, first) - : sprout::detail::iter_minmax( + : sprout::detail::iter_minmax_pair( sprout::detail::minmax_element_impl_ra( first, sprout::next(first, pivot), comp, pivot / 2 @@ -40,7 +50,10 @@ namespace sprout { ; } template - inline SPROUT_CONSTEXPR sprout::pair + inline SPROUT_CONSTEXPR typename std::enable_if< + sprout::is_constant_distance_iterator::value, + sprout::pair + >::type minmax_element( RandomAccessIterator first, RandomAccessIterator last, Compare comp, std::random_access_iterator_tag* @@ -54,17 +67,41 @@ namespace sprout { ; } - // Copyright (C) 2011 RiSK (sscrisk) template - inline SPROUT_CONSTEXPR sprout::pair - minmax_element_impl( - ForwardIterator first, ForwardIterator last, Compare comp, - ForwardIterator min, ForwardIterator max + inline SPROUT_CONSTEXPR sprout::pair > + minmax_element_impl_1( + sprout::pair > const& current, + ForwardIterator last, Compare comp, typename std::iterator_traits::difference_type n ) { - return first == last ? sprout::pair(min, max) - : comp(*first, *min) ? sprout::detail::minmax_element_impl(sprout::next(first), last, comp, first, max) - : sprout::detail::minmax_element_impl(sprout::next(first), last, comp, min, comp(*first, *max) ? max : first) + typedef sprout::pair > type; + return current.first == last ? current + : n == 1 ? type(sprout::next(current.first), sprout::detail::iter_minmax(current.second, current.first, comp)) + : sprout::detail::minmax_element_impl_1( + sprout::detail::minmax_element_impl_1( + current, + last, comp, n / 2 + ), + last, comp, n - n / 2 + ) + ; + } + template + inline SPROUT_CONSTEXPR sprout::pair > + minmax_element_impl( + sprout::pair > const& current, + ForwardIterator last, Compare comp, typename std::iterator_traits::difference_type n + ) + { + typedef sprout::pair > type; + return current.first == last ? current + : sprout::detail::minmax_element_impl( + sprout::detail::minmax_element_impl_1( + current, + last, comp, n + ), + last, comp, n * 2 + ) ; } template @@ -74,8 +111,9 @@ namespace sprout { void* ) { - return first == last ? sprout::pair(last, last) - : sprout::detail::minmax_element_impl(sprout::next(first), last, comp, first, first) + typedef sprout::pair > type; + return first == last ? sprout::pair(first, first) + : sprout::detail::minmax_element_impl(type(sprout::next(first), sprout::pair(first, first)), last, comp, 1).second ; } } // namespace detail @@ -83,8 +121,7 @@ namespace sprout { // 25.4.7 Minimum and maximum // // recursion depth: - // [first, last) is RandomAccessIterator -> O(log N) - // otherwise -> O(N) + // O(log N) // template inline SPROUT_CONSTEXPR sprout::pair