1
0
Fork 0
mirror of https://github.com/bolero-MURAKAMI/Sprout synced 2024-11-12 21:09:01 +00:00

fix recursion depth: some algorithms

This commit is contained in:
bolero-MURAKAMI 2013-01-12 02:39:51 +09:00
parent 830fc27394
commit cb584edb3f
14 changed files with 1443 additions and 71 deletions

View file

@ -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<int>()
);
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<int>()
);
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<int>()
);
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<int>()
);
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<int>()
);
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<int>()
);
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<int>()
);
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<int>()
);
TESTSPR_BOTH_ASSERT(!result);
}
#endif
}
}
} // namespace testspr

View file

@ -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<int>()
);
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<int>()
);
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<int>()
);
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<int>()
);
TESTSPR_BOTH_ASSERT(result);
}
#endif
}
}
} // namespace testspr

View file

@ -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<int>()
).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<int>()
).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<int>()
).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<int>()
).base();
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr2) + 5);
}
#endif
}
}
} // namespace testspr

View file

@ -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<int>()
);
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<int>()
);
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<int>()
);
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<int>()
);
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<int>()
);
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<int>()
);
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<int>()
);
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<int>()
);
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<int>()
);
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<int>()
);
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<int>()
);
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<int>()
);
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<int>()
);
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<int>()
);
TESTSPR_BOTH_ASSERT(!result);
}
#endif
}
}
} // namespace testspr

View file

@ -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<int>()
).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<int>()
).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<int>()
).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<int>()
).base();
TESTSPR_BOTH_ASSERT(result == sprout::begin(arr1) + 4);
}
#endif
}
}
} // namespace testspr

View file

@ -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<int>()
).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<int>()
).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<int>()
).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<int>()
).base();
TESTSPR_BOTH_ASSERT(result == sprout::begin(arr1) + 3);
}
#endif
}
}
} // namespace testspr

View file

@ -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<int>()
);
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<int>()
);
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<int>()
);
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<int>()
);
TESTSPR_BOTH_ASSERT(result.first.base() == sprout::begin(arr1) + 3);
TESTSPR_BOTH_ASSERT(result.second.base() == sprout::begin(arr1) + 4);
}
#endif
}
}
} // namespace testspr

View file

@ -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();

View file

@ -0,0 +1,432 @@
#ifndef SPROUT_LIBS_ALGORITHM_TEST_TRISTATE_LEXICOGRAPHICAL_COMPARE_CPP
#define SPROUT_LIBS_ALGORITHM_TEST_TRISTATE_LEXICOGRAPHICAL_COMPARE_CPP
#include <sprout/algorithm/tristate_lexicographical_compare.hpp>
#include <sprout/array.hpp>
#include <sprout/container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_tristate_lexicographical_compare_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}};
SPROUT_STATIC_CONSTEXPR auto arr2 = array<int, 10>{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}};
SPROUT_STATIC_CONSTEXPR auto arr3 = array<int, 10>{{1, 2, 3, 4, 5, 6, 7, 1, 2, 3}};
SPROUT_STATIC_CONSTEXPR auto arr4 = array<int, 10>{{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<int>()
);
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<int>()
);
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<int>()
);
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<int>()
);
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<int>()
);
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<int>()
);
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<int>()
);
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<int>()
);
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<int>()
);
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<int>()
);
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<int>()
);
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<int>()
);
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<int>()
);
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<int>()
);
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<int>()
);
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<int>()
);
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<int>()
);
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<int>()
);
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<int>()
);
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<int>()
);
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<int>()
);
TESTSPR_BOTH_ASSERT(result > 0);
}
#endif
}
}
} // namespace testspr
#ifndef TESTSPR_CPP_INCLUDE
# define TESTSPR_TEST_FUNCTION testspr::algorithm_tristate_lexicographical_compare_test
# include <testspr/include_main.hpp>
#endif
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_TRISTATE_LEXICOGRAPHICAL_COMPARE_CPP

View file

@ -2,16 +2,19 @@
#define SPROUT_ALGORITHM_INCLUDES_HPP
#include <iterator>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/iterator/operation.hpp>
#include <sprout/iterator/type_traits/is_iterator.hpp>
#include <sprout/functional/less.hpp>
#include <sprout/utility/pair.hpp>
namespace sprout {
namespace detail {
template<typename RandomAccessIterator1, typename RandomAccessIterator2, typename Compare>
inline SPROUT_CONSTEXPR RandomAccessIterator2
template<typename RandomAccessIterator1, typename InputIterator2, typename Compare>
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<RandomAccessIterator1>::difference_type pivot
)
{
@ -30,10 +33,13 @@ namespace sprout {
)
;
}
template<typename RandomAccessIterator1, typename RandomAccessIterator2, typename Compare>
inline SPROUT_CONSTEXPR bool
template<typename RandomAccessIterator1, typename InputIterator2, typename Compare>
inline SPROUT_CONSTEXPR typename std::enable_if<
sprout::is_constant_distance_iterator<RandomAccessIterator1>::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<typename InputIterator1, typename InputIterator2, typename Compare>
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<InputIterator1, InputIterator2>
includes_impl_1(
sprout::pair<InputIterator1, InputIterator2> const& current,
InputIterator1 last1, InputIterator2 last2, Compare comp,
typename std::iterator_traits<InputIterator1>::difference_type n
)
{
typedef sprout::pair<InputIterator1, InputIterator2> 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<typename InputIterator1, typename InputIterator2, typename Compare>
inline SPROUT_CONSTEXPR sprout::pair<InputIterator1, InputIterator2>
includes_impl(
sprout::pair<InputIterator1, InputIterator2> const& current,
InputIterator1 last1, InputIterator2 last2, Compare comp,
typename std::iterator_traits<InputIterator1>::difference_type n
)
{
typedef sprout::pair<InputIterator1, InputIterator2> 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<typename InputIterator1, typename InputIterator2, typename Compare>
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<InputIterator1, InputIterator2> 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<typename InputIterator1, typename InputIterator2, typename Compare>
inline SPROUT_CONSTEXPR bool

View file

@ -1,8 +1,11 @@
#ifndef SPROUT_ALGORITHM_LEXICOGRAPHICAL_COMPARE_HPP
#define SPROUT_ALGORITHM_LEXICOGRAPHICAL_COMPARE_HPP
#include <iterator>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/iterator/operation.hpp>
#include <sprout/iterator/type_traits/is_iterator.hpp>
#include <sprout/iterator/type_traits/common.hpp>
#include <sprout/utility/pair.hpp>
#include <sprout/algorithm/min.hpp>
@ -12,7 +15,7 @@ namespace sprout {
namespace detail {
template<typename RandomAccessIterator1, typename RandomAccessIterator2, typename Compare>
inline SPROUT_CONSTEXPR bool
lexicographical_compare_impl_ra_2(
lexicographical_compare_impl_check(
RandomAccessIterator1 last1, RandomAccessIterator2 last2, Compare comp,
sprout::pair<RandomAccessIterator1, RandomAccessIterator2> const& found
)
@ -21,6 +24,7 @@ namespace sprout {
: found.first == last1 || comp(*found.first, *found.second)
;
}
template<typename RandomAccessIterator1, typename RandomAccessIterator2, typename Compare>
inline SPROUT_CONSTEXPR sprout::pair<RandomAccessIterator1, RandomAccessIterator2>
lexicographical_compare_impl_ra_1(
@ -50,7 +54,7 @@ namespace sprout {
)
{
typedef sprout::pair<RandomAccessIterator1, RandomAccessIterator2> 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<typename RandomAccessIterator1, typename RandomAccessIterator2, typename Compare>
inline SPROUT_CONSTEXPR bool
inline SPROUT_CONSTEXPR typename std::enable_if<
sprout::is_constant_distance_iterator<RandomAccessIterator1>::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<typename InputIterator1, typename InputIterator2, typename Compare>
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<InputIterator1, InputIterator2>
lexicographical_compare_impl_1(
sprout::pair<InputIterator1, InputIterator2> current,
InputIterator1 last1, InputIterator2 last2, Compare comp,
typename std::iterator_traits<InputIterator1>::difference_type n
)
{
typedef sprout::pair<InputIterator1, InputIterator2> 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<typename InputIterator1, typename InputIterator2, typename Compare>
inline SPROUT_CONSTEXPR sprout::pair<InputIterator1, InputIterator2>
lexicographical_compare_impl(
sprout::pair<InputIterator1, InputIterator2> current,
InputIterator1 last1, InputIterator2 last2, Compare comp,
typename std::iterator_traits<InputIterator1>::difference_type n
)
{
typedef sprout::pair<InputIterator1, InputIterator2> 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<typename InputIterator1, typename InputIterator2, typename Compare>
@ -91,15 +129,18 @@ namespace sprout {
void*
)
{
return sprout::detail::lexicographical_compare_impl(first1, last1, first2, last2, comp);
typedef sprout::pair<InputIterator1, InputIterator2> 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<typename InputIterator1, typename InputIterator2, typename Compare>
inline SPROUT_CONSTEXPR bool

View file

@ -2,8 +2,11 @@
#define SPROUT_ALGORITHM_MAX_ELEMENT_HPP
#include <iterator>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/iterator/operation.hpp>
#include <sprout/iterator/type_traits/is_iterator.hpp>
#include <sprout/utility/pair.hpp>
#include HDR_FUNCTIONAL_SSCRISK_CEL_OR_SPROUT
namespace sprout {
@ -36,7 +39,10 @@ namespace sprout {
;
}
template<typename RandomAccessIterator, typename Compare>
inline SPROUT_CONSTEXPR RandomAccessIterator
inline SPROUT_CONSTEXPR typename std::enable_if<
sprout::is_constant_distance_iterator<RandomAccessIterator>::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<typename ForwardIterator, typename Compare>
inline SPROUT_CONSTEXPR ForwardIterator
max_element_impl(
ForwardIterator first, ForwardIterator last, Compare comp,
ForwardIterator found
inline SPROUT_CONSTEXPR sprout::pair<ForwardIterator, ForwardIterator>
max_element_impl_1(
sprout::pair<ForwardIterator, ForwardIterator> const& current,
ForwardIterator last, Compare comp, typename std::iterator_traits<ForwardIterator>::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<ForwardIterator, ForwardIterator> 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<typename ForwardIterator, typename Compare>
inline SPROUT_CONSTEXPR sprout::pair<ForwardIterator, ForwardIterator>
max_element_impl(
sprout::pair<ForwardIterator, ForwardIterator> const& current,
ForwardIterator last, Compare comp, typename std::iterator_traits<ForwardIterator>::difference_type n
)
{
typedef sprout::pair<ForwardIterator, ForwardIterator> 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<typename ForwardIterator, typename Compare>
@ -69,8 +100,9 @@ namespace sprout {
void*
)
{
typedef sprout::pair<ForwardIterator, ForwardIterator> 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<typename ForwardIterator, typename Compare>
inline SPROUT_CONSTEXPR ForwardIterator

View file

@ -2,15 +2,18 @@
#define SPROUT_ALGORITHM_MIN_ELEMENT_HPP
#include <iterator>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/iterator/operation.hpp>
#include <sprout/iterator/type_traits/is_iterator.hpp>
#include <sprout/utility/pair.hpp>
#include HDR_FUNCTIONAL_SSCRISK_CEL_OR_SPROUT
namespace sprout {
namespace detail {
template<typename InputIterator, typename Compare>
inline SPROUT_CONSTEXPR InputIterator
iter_min(InputIterator a, InputIterator b, Compare comp) {
template<typename ForwardIterator, typename Compare>
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<typename RandomAccessIterator, typename Compare>
inline SPROUT_CONSTEXPR RandomAccessIterator
inline SPROUT_CONSTEXPR typename std::enable_if<
sprout::is_constant_distance_iterator<RandomAccessIterator>::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<typename ForwardIterator, typename Compare>
inline SPROUT_CONSTEXPR ForwardIterator
min_element_impl(
ForwardIterator first, ForwardIterator last, Compare comp,
ForwardIterator found
inline SPROUT_CONSTEXPR sprout::pair<ForwardIterator, ForwardIterator>
min_element_impl_1(
sprout::pair<ForwardIterator, ForwardIterator> const& current,
ForwardIterator last, Compare comp, typename std::iterator_traits<ForwardIterator>::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<ForwardIterator, ForwardIterator> 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<typename ForwardIterator, typename Compare>
inline SPROUT_CONSTEXPR sprout::pair<ForwardIterator, ForwardIterator>
min_element_impl(
sprout::pair<ForwardIterator, ForwardIterator> const& current,
ForwardIterator last, Compare comp, typename std::iterator_traits<ForwardIterator>::difference_type n
)
{
typedef sprout::pair<ForwardIterator, ForwardIterator> 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<typename ForwardIterator, typename Compare>
@ -69,8 +100,9 @@ namespace sprout {
void*
)
{
typedef sprout::pair<ForwardIterator, ForwardIterator> 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<typename ForwardIterator, typename Compare>
inline SPROUT_CONSTEXPR ForwardIterator

View file

@ -2,8 +2,10 @@
#define SPROUT_ALGORITHM_MINMAX_ELEMENT_HPP
#include <iterator>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/iterator/operation.hpp>
#include <sprout/iterator/type_traits/is_iterator.hpp>
#include <sprout/utility/pair.hpp>
#include HDR_FUNCTIONAL_SSCRISK_CEL_OR_SPROUT
@ -11,12 +13,20 @@ namespace sprout {
namespace detail {
template<typename InputIteratorPair, typename Compare>
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<typename InputIteratorPair, typename InputIterator, typename Compare>
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<typename RandomAccessIterator, typename Compare>
inline SPROUT_CONSTEXPR sprout::pair<RandomAccessIterator, RandomAccessIterator>
@ -26,7 +36,7 @@ namespace sprout {
)
{
return pivot == 0 ? sprout::pair<RandomAccessIterator, RandomAccessIterator>(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<typename RandomAccessIterator, typename Compare>
inline SPROUT_CONSTEXPR sprout::pair<RandomAccessIterator, RandomAccessIterator>
inline SPROUT_CONSTEXPR typename std::enable_if<
sprout::is_constant_distance_iterator<RandomAccessIterator>::value,
sprout::pair<RandomAccessIterator, RandomAccessIterator>
>::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<typename ForwardIterator, typename Compare>
inline SPROUT_CONSTEXPR sprout::pair<ForwardIterator, ForwardIterator>
minmax_element_impl(
ForwardIterator first, ForwardIterator last, Compare comp,
ForwardIterator min, ForwardIterator max
inline SPROUT_CONSTEXPR sprout::pair<ForwardIterator, sprout::pair<ForwardIterator, ForwardIterator> >
minmax_element_impl_1(
sprout::pair<ForwardIterator, sprout::pair<ForwardIterator, ForwardIterator> > const& current,
ForwardIterator last, Compare comp, typename std::iterator_traits<ForwardIterator>::difference_type n
)
{
return first == last ? sprout::pair<ForwardIterator, ForwardIterator>(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<ForwardIterator, sprout::pair<ForwardIterator, ForwardIterator> > 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<typename ForwardIterator, typename Compare>
inline SPROUT_CONSTEXPR sprout::pair<ForwardIterator, sprout::pair<ForwardIterator, ForwardIterator> >
minmax_element_impl(
sprout::pair<ForwardIterator, sprout::pair<ForwardIterator, ForwardIterator> > const& current,
ForwardIterator last, Compare comp, typename std::iterator_traits<ForwardIterator>::difference_type n
)
{
typedef sprout::pair<ForwardIterator, sprout::pair<ForwardIterator, ForwardIterator> > 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<typename ForwardIterator, typename Compare>
@ -74,8 +111,9 @@ namespace sprout {
void*
)
{
return first == last ? sprout::pair<ForwardIterator, ForwardIterator>(last, last)
: sprout::detail::minmax_element_impl(sprout::next(first), last, comp, first, first)
typedef sprout::pair<ForwardIterator, sprout::pair<ForwardIterator, ForwardIterator> > type;
return first == last ? sprout::pair<ForwardIterator, ForwardIterator>(first, first)
: sprout::detail::minmax_element_impl(type(sprout::next(first), sprout::pair<ForwardIterator, ForwardIterator>(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<typename ForwardIterator, typename Compare>
inline SPROUT_CONSTEXPR sprout::pair<ForwardIterator, ForwardIterator>