Merge pull request #75 from kariya-mitsuru/fix-rotate

fix rotate_copy
This commit is contained in:
Bolero MURAKAMI 2015-04-28 09:39:50 +09:00
commit 1cb62e6250
3 changed files with 119 additions and 31 deletions

View file

@ -24,21 +24,21 @@ namespace testspr {
{
SPROUT_STATIC_CONSTEXPR auto rotated = sprout::rotate(
arr1,
sprout::begin(arr1) + 5
sprout::begin(arr1) + 4
);
TESTSPR_BOTH_ASSERT(testspr::equal(
rotated,
array<int, 10>{{6, 7, 8, 9, 10, 1, 2, 3, 4, 5}}
array<int, 10>{{5, 6, 7, 8, 9, 10, 1, 2, 3, 4}}
));
}
{
SPROUT_STATIC_CONSTEXPR auto rotated = sprout::fit::rotate(
arr1,
sprout::begin(arr1) + 5
sprout::begin(arr1) + 4
);
TESTSPR_BOTH_ASSERT(testspr::equal(
rotated,
array<int, 10>{{6, 7, 8, 9, 10, 1, 2, 3, 4, 5}}
array<int, 10>{{5, 6, 7, 8, 9, 10, 1, 2, 3, 4}}
));
}
// rotate
@ -46,29 +46,29 @@ namespace testspr {
{
SPROUT_STATIC_CONSTEXPR auto rotated = sprout::rotate(
sprout::sub(arr1, 2, 8),
sprout::begin(arr1) + 5
sprout::begin(arr1) + 4
);
TESTSPR_BOTH_ASSERT(testspr::equal(
rotated,
array<int, 6>{{6, 7, 8, 3, 4, 5}}
array<int, 6>{{5, 6, 7, 8, 3, 4}}
));
TESTSPR_BOTH_ASSERT(testspr::equal(
sprout::get_internal(rotated),
array<int, 10>{{1, 2, 6, 7, 8, 3, 4, 5, 9, 10}}
array<int, 10>{{1, 2, 5, 6, 7, 8, 3, 4, 9, 10}}
));
}
{
SPROUT_STATIC_CONSTEXPR auto rotated = sprout::fit::rotate(
sprout::sub(arr1, 2, 8),
sprout::begin(arr1) + 5
sprout::begin(arr1) + 4
);
TESTSPR_BOTH_ASSERT(testspr::equal(
rotated,
array<int, 6>{{6, 7, 8, 3, 4, 5}}
array<int, 6>{{5, 6, 7, 8, 3, 4}}
));
TESTSPR_BOTH_ASSERT(testspr::equal(
sprout::get_internal(rotated),
array<int, 10>{{1, 2, 6, 7, 8, 3, 4, 5, 9, 10}}
array<int, 10>{{1, 2, 5, 6, 7, 8, 3, 4, 9, 10}}
));
}
}

View file

@ -26,25 +26,25 @@ namespace testspr {
{
SPROUT_STATIC_CONSTEXPR auto rotated = sprout::rotate_copy(
sprout::begin(arr1) + 2,
sprout::begin(arr1) + 5,
sprout::begin(arr1) + 4,
sprout::begin(arr1) + 8,
arr2
);
TESTSPR_BOTH_ASSERT(testspr::equal(
rotated,
array<int, 10>{{6, 7, 8, 3, 4, 5, 0, 0, 0, 0}}
array<int, 10>{{5, 6, 7, 8, 3, 4, 0, 0, 0, 0}}
));
}
{
SPROUT_STATIC_CONSTEXPR auto rotated = sprout::fit::rotate_copy(
sprout::begin(arr1) + 2,
sprout::begin(arr1) + 5,
sprout::begin(arr1) + 4,
sprout::begin(arr1) + 8,
arr2
);
TESTSPR_BOTH_ASSERT(testspr::equal(
rotated,
array<int, 6>{{6, 7, 8, 3, 4, 5}}
array<int, 6>{{5, 6, 7, 8, 3, 4}}
));
}
// rotate in range [2 .. 8)
@ -52,25 +52,25 @@ namespace testspr {
{
SPROUT_STATIC_CONSTEXPR auto rotated = sprout::rotate_copy(
sprout::begin(arr1) + 2,
sprout::begin(arr1) + 5,
sprout::begin(arr1) + 8,
sprout::begin(arr1) + 4,
sprout::begin(arr1) + 7,
arr3
);
TESTSPR_BOTH_ASSERT(testspr::equal(
rotated,
array<int, 4>{{6, 7, 8, 3}}
array<int, 4>{{5, 6, 7, 3}}
));
}
{
SPROUT_STATIC_CONSTEXPR auto rotated = sprout::fit::rotate_copy(
sprout::begin(arr1) + 2,
sprout::begin(arr1) + 5,
sprout::begin(arr1) + 8,
sprout::begin(arr1) + 4,
sprout::begin(arr1) + 7,
arr3
);
TESTSPR_BOTH_ASSERT(testspr::equal(
rotated,
array<int, 4>{{6, 7, 8, 3}}
array<int, 4>{{5, 6, 7, 3}}
));
}
// rotate in range [2 .. 8)
@ -78,33 +78,119 @@ namespace testspr {
{
SPROUT_STATIC_CONSTEXPR auto rotated = sprout::rotate_copy(
sprout::begin(arr1) + 2,
sprout::begin(arr1) + 5,
sprout::begin(arr1) + 4,
sprout::begin(arr1) + 8,
sprout::sub(arr2, 2, 8)
);
TESTSPR_BOTH_ASSERT(testspr::equal(
rotated,
array<int, 6>{{6, 7, 8, 3, 4, 5}}
array<int, 6>{{5, 6, 7, 8, 3, 4}}
));
TESTSPR_BOTH_ASSERT(testspr::equal(
sprout::get_internal(rotated),
array<int, 10>{{0, 0, 6, 7, 8, 3, 4, 5, 0, 0}}
array<int, 10>{{0, 0, 5, 6, 7, 8, 3, 4, 0, 0}}
));
}
{
SPROUT_STATIC_CONSTEXPR auto rotated = sprout::fit::rotate_copy(
sprout::begin(arr1) + 2,
sprout::begin(arr1) + 5,
sprout::begin(arr1) + 4,
sprout::begin(arr1) + 8,
sprout::sub(arr2, 2, 8)
);
TESTSPR_BOTH_ASSERT(testspr::equal(
rotated,
array<int, 6>{{6, 7, 8, 3, 4, 5}}
array<int, 6>{{5, 6, 7, 8, 3, 4}}
));
TESTSPR_BOTH_ASSERT(testspr::equal(
sprout::get_internal(rotated),
array<int, 10>{{0, 0, 6, 7, 8, 3, 4, 5, 0, 0}}
array<int, 10>{{0, 0, 5, 6, 7, 8, 3, 4, 0, 0}}
));
}
// rotate in range [2 .. 8)
{
SPROUT_STATIC_CONSTEXPR auto rotated = sprout::rotate_copy(
testspr::reduct_forward(sprout::begin(arr1) + 2),
testspr::reduct_forward(sprout::begin(arr1) + 4),
testspr::reduct_forward(sprout::begin(arr1) + 8),
arr2
);
TESTSPR_BOTH_ASSERT(testspr::equal(
rotated,
array<int, 10>{{5, 6, 7, 8, 3, 4, 0, 0, 0, 0}}
));
}
{
SPROUT_STATIC_CONSTEXPR auto rotated = sprout::fit::rotate_copy(
testspr::reduct_forward(sprout::begin(arr1) + 2),
testspr::reduct_forward(sprout::begin(arr1) + 4),
testspr::reduct_forward(sprout::begin(arr1) + 8),
arr2
);
TESTSPR_BOTH_ASSERT(testspr::equal(
rotated,
array<int, 6>{{5, 6, 7, 8, 3, 4}}
));
}
// rotate in range [2 .. 8)
// overrun from output range
{
SPROUT_STATIC_CONSTEXPR auto rotated = sprout::rotate_copy(
testspr::reduct_forward(sprout::begin(arr1) + 2),
testspr::reduct_forward(sprout::begin(arr1) + 4),
testspr::reduct_forward(sprout::begin(arr1) + 7),
arr3
);
TESTSPR_BOTH_ASSERT(testspr::equal(
rotated,
array<int, 4>{{5, 6, 7, 3}}
));
}
{
SPROUT_STATIC_CONSTEXPR auto rotated = sprout::fit::rotate_copy(
testspr::reduct_forward(sprout::begin(arr1) + 2),
testspr::reduct_forward(sprout::begin(arr1) + 4),
testspr::reduct_forward(sprout::begin(arr1) + 7),
arr3
);
TESTSPR_BOTH_ASSERT(testspr::equal(
rotated,
array<int, 4>{{5, 6, 7, 3}}
));
}
// rotate in range [2 .. 8)
// to sub range
{
SPROUT_STATIC_CONSTEXPR auto rotated = sprout::rotate_copy(
testspr::reduct_forward(sprout::begin(arr1) + 2),
testspr::reduct_forward(sprout::begin(arr1) + 4),
testspr::reduct_forward(sprout::begin(arr1) + 8),
sprout::sub(arr2, 2, 8)
);
TESTSPR_BOTH_ASSERT(testspr::equal(
rotated,
array<int, 6>{{5, 6, 7, 8, 3, 4}}
));
TESTSPR_BOTH_ASSERT(testspr::equal(
sprout::get_internal(rotated),
array<int, 10>{{0, 0, 5, 6, 7, 8, 3, 4, 0, 0}}
));
}
{
SPROUT_STATIC_CONSTEXPR auto rotated = sprout::fit::rotate_copy(
testspr::reduct_forward(sprout::begin(arr1) + 2),
testspr::reduct_forward(sprout::begin(arr1) + 4),
testspr::reduct_forward(sprout::begin(arr1) + 8),
sprout::sub(arr2, 2, 8)
);
TESTSPR_BOTH_ASSERT(testspr::equal(
rotated,
array<int, 6>{{5, 6, 7, 8, 3, 4}}
));
TESTSPR_BOTH_ASSERT(testspr::equal(
sprout::get_internal(rotated),
array<int, 10>{{0, 0, 5, 6, 7, 8, 3, 4, 0, 0}}
));
}
}

View file

@ -29,7 +29,8 @@ namespace sprout {
template<typename RandomAccessIterator, typename Result, sprout::index_t... Indexes>
inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm<Result>::type
rotate_copy_impl_ra(
RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last,
RandomAccessIterator first, RandomAccessIterator middle,
typename sprout::container_traits<Result>::size_type last_half_size,
Result const& result,
sprout::index_tuple<Indexes...>,
typename sprout::container_traits<Result>::difference_type offset,
@ -41,9 +42,9 @@ namespace sprout {
result,
sprout::size(result),
(Indexes >= offset && Indexes < offset + size && Indexes < offset + input_size
? (Indexes < offset + sprout::distance(middle, last)
? (Indexes < offset + last_half_size
? middle[Indexes - offset]
: first[(Indexes - offset) - sprout::distance(first, middle)]
: first[(Indexes - offset) - last_half_size]
)
: *sprout::next(sprout::internal_begin(result), Indexes)
)...
@ -58,7 +59,8 @@ namespace sprout {
)
{
return sprout::fixed::detail::rotate_copy_impl_ra(
first, middle, last,
first, middle,
sprout::distance(middle, last),
result,
sprout::container_indexes<Result>::make(),
sprout::internal_begin_offset(result),
@ -138,7 +140,7 @@ namespace sprout {
std::forward_iterator_tag*
)
{
return sprout::fixed::detail::rotate_copy_impl(first, middle, last, result, sprout::size(result));
return sprout::fixed::detail::rotate_copy_impl(first, middle, middle, last, result, sprout::size(result));
}
template<typename ForwardIterator, typename Result>