fix algorithm: copy for InputIterator

This commit is contained in:
bolero-MURAKAMI 2013-08-13 01:55:26 +09:00
parent 72fe72a623
commit 6ae41ef6de
4 changed files with 443 additions and 4 deletions

View file

@ -101,6 +101,249 @@ namespace testspr {
array<int, 10>{{0, 0, 3, 4, 5, 6, 7, 8, 0, 0}}
));
}
// [2 .. 8) の範囲をコピー
{
SPROUT_STATIC_CONSTEXPR auto copied = sprout::copy(
testspr::reduct_input(sprout::begin(arr1) + 2),
testspr::reduct_input(sprout::begin(arr1) + 8),
arr2
);
TESTSPR_BOTH_ASSERT(testspr::equal(
copied,
array<int, 10>{{3, 4, 5, 6, 7, 8, 0, 0, 0, 0}}
));
}
// !!!
// {
// SPROUT_STATIC_CONSTEXPR auto copied = sprout::fit::copy(
// testspr::reduct_input(sprout::begin(arr1) + 2),
// testspr::reduct_input(sprout::begin(arr1) + 8),
// arr2
// );
// TESTSPR_BOTH_ASSERT(testspr::equal(
// copied,
// array<int, 6>{{3, 4, 5, 6, 7, 8}}
// ));
// }
// [2 .. 8) の範囲をコピー
// 出力範囲をオーバーする場合
{
SPROUT_STATIC_CONSTEXPR auto copied = sprout::copy(
testspr::reduct_input(sprout::begin(arr1) + 2),
testspr::reduct_input(sprout::begin(arr1) + 8),
arr3
);
TESTSPR_BOTH_ASSERT(testspr::equal(
copied,
array<int, 4>{{3, 4, 5, 6}}
));
}
// !!!
// {
// SPROUT_STATIC_CONSTEXPR auto copied = sprout::fit::copy(
// testspr::reduct_input(sprout::begin(arr1) + 2),
// testspr::reduct_input(sprout::begin(arr1) + 8),
// arr3
// );
// TESTSPR_BOTH_ASSERT(testspr::equal(
// copied,
// array<int, 4>{{3, 4, 5, 6}}
// ));
// }
// [2 .. 8) の範囲をコピー
// 出力範囲の切り出し
{
SPROUT_STATIC_CONSTEXPR auto copied = sprout::copy(
testspr::reduct_input(sprout::begin(arr1) + 2),
testspr::reduct_input(sprout::begin(arr1) + 8),
sprout::sub(arr2, 2, 8)
);
TESTSPR_BOTH_ASSERT(testspr::equal(
copied,
array<int, 6>{{3, 4, 5, 6, 7, 8}}
));
TESTSPR_BOTH_ASSERT(testspr::equal(
sprout::get_internal(copied),
array<int, 10>{{0, 0, 3, 4, 5, 6, 7, 8, 0, 0}}
));
}
// !!!
// {
// SPROUT_STATIC_CONSTEXPR auto copied = sprout::fit::copy(
// testspr::reduct_input(sprout::begin(arr1) + 2),
// testspr::reduct_input(sprout::begin(arr1) + 8),
// sprout::sub(arr2, 2, 8)
// );
// TESTSPR_BOTH_ASSERT(testspr::equal(
// copied,
// array<int, 6>{{3, 4, 5, 6, 7, 8}}
// ));
// TESTSPR_BOTH_ASSERT(testspr::equal(
// sprout::get_internal(copied),
// array<int, 10>{{0, 0, 3, 4, 5, 6, 7, 8, 0, 0}}
// ));
// }
// [2 .. 8) の範囲をコピー
{
SPROUT_STATIC_CONSTEXPR auto copied = sprout::copy(
testspr::reduct_forward(sprout::begin(arr1) + 2),
testspr::reduct_forward(sprout::begin(arr1) + 8),
arr2
);
TESTSPR_BOTH_ASSERT(testspr::equal(
copied,
array<int, 10>{{3, 4, 5, 6, 7, 8, 0, 0, 0, 0}}
));
}
{
SPROUT_STATIC_CONSTEXPR auto copied = sprout::fit::copy(
testspr::reduct_forward(sprout::begin(arr1) + 2),
testspr::reduct_forward(sprout::begin(arr1) + 8),
arr2
);
TESTSPR_BOTH_ASSERT(testspr::equal(
copied,
array<int, 6>{{3, 4, 5, 6, 7, 8}}
));
}
// [2 .. 8) の範囲をコピー
// 出力範囲をオーバーする場合
{
SPROUT_STATIC_CONSTEXPR auto copied = sprout::copy(
testspr::reduct_forward(sprout::begin(arr1) + 2),
testspr::reduct_forward(sprout::begin(arr1) + 8),
arr3
);
TESTSPR_BOTH_ASSERT(testspr::equal(
copied,
array<int, 4>{{3, 4, 5, 6}}
));
}
{
SPROUT_STATIC_CONSTEXPR auto copied = sprout::fit::copy(
testspr::reduct_forward(sprout::begin(arr1) + 2),
testspr::reduct_forward(sprout::begin(arr1) + 8),
arr3
);
TESTSPR_BOTH_ASSERT(testspr::equal(
copied,
array<int, 4>{{3, 4, 5, 6}}
));
}
// [2 .. 8) の範囲をコピー
// 出力範囲の切り出し
{
SPROUT_STATIC_CONSTEXPR auto copied = sprout::copy(
testspr::reduct_forward(sprout::begin(arr1) + 2),
testspr::reduct_forward(sprout::begin(arr1) + 8),
sprout::sub(arr2, 2, 8)
);
TESTSPR_BOTH_ASSERT(testspr::equal(
copied,
array<int, 6>{{3, 4, 5, 6, 7, 8}}
));
TESTSPR_BOTH_ASSERT(testspr::equal(
sprout::get_internal(copied),
array<int, 10>{{0, 0, 3, 4, 5, 6, 7, 8, 0, 0}}
));
}
{
SPROUT_STATIC_CONSTEXPR auto copied = sprout::fit::copy(
testspr::reduct_forward(sprout::begin(arr1) + 2),
testspr::reduct_forward(sprout::begin(arr1) + 8),
sprout::sub(arr2, 2, 8)
);
TESTSPR_BOTH_ASSERT(testspr::equal(
copied,
array<int, 6>{{3, 4, 5, 6, 7, 8}}
));
TESTSPR_BOTH_ASSERT(testspr::equal(
sprout::get_internal(copied),
array<int, 10>{{0, 0, 3, 4, 5, 6, 7, 8, 0, 0}}
));
}
// [2 .. 8) の範囲をコピー
{
SPROUT_STATIC_CONSTEXPR auto copied = sprout::copy(
testspr::reduct_random_access(sprout::begin(arr1) + 2),
testspr::reduct_random_access(sprout::begin(arr1) + 8),
arr2
);
TESTSPR_BOTH_ASSERT(testspr::equal(
copied,
array<int, 10>{{3, 4, 5, 6, 7, 8, 0, 0, 0, 0}}
));
}
{
SPROUT_STATIC_CONSTEXPR auto copied = sprout::fit::copy(
testspr::reduct_random_access(sprout::begin(arr1) + 2),
testspr::reduct_random_access(sprout::begin(arr1) + 8),
arr2
);
TESTSPR_BOTH_ASSERT(testspr::equal(
copied,
array<int, 6>{{3, 4, 5, 6, 7, 8}}
));
}
// [2 .. 8) の範囲をコピー
// 出力範囲をオーバーする場合
{
SPROUT_STATIC_CONSTEXPR auto copied = sprout::copy(
testspr::reduct_random_access(sprout::begin(arr1) + 2),
testspr::reduct_random_access(sprout::begin(arr1) + 8),
arr3
);
TESTSPR_BOTH_ASSERT(testspr::equal(
copied,
array<int, 4>{{3, 4, 5, 6}}
));
}
{
SPROUT_STATIC_CONSTEXPR auto copied = sprout::fit::copy(
testspr::reduct_random_access(sprout::begin(arr1) + 2),
testspr::reduct_random_access(sprout::begin(arr1) + 8),
arr3
);
TESTSPR_BOTH_ASSERT(testspr::equal(
copied,
array<int, 4>{{3, 4, 5, 6}}
));
}
// [2 .. 8) の範囲をコピー
// 出力範囲の切り出し
{
SPROUT_STATIC_CONSTEXPR auto copied = sprout::copy(
testspr::reduct_random_access(sprout::begin(arr1) + 2),
testspr::reduct_random_access(sprout::begin(arr1) + 8),
sprout::sub(arr2, 2, 8)
);
TESTSPR_BOTH_ASSERT(testspr::equal(
copied,
array<int, 6>{{3, 4, 5, 6, 7, 8}}
));
TESTSPR_BOTH_ASSERT(testspr::equal(
sprout::get_internal(copied),
array<int, 10>{{0, 0, 3, 4, 5, 6, 7, 8, 0, 0}}
));
}
{
SPROUT_STATIC_CONSTEXPR auto copied = sprout::fit::copy(
testspr::reduct_random_access(sprout::begin(arr1) + 2),
testspr::reduct_random_access(sprout::begin(arr1) + 8),
sprout::sub(arr2, 2, 8)
);
TESTSPR_BOTH_ASSERT(testspr::equal(
copied,
array<int, 6>{{3, 4, 5, 6, 7, 8}}
));
TESTSPR_BOTH_ASSERT(testspr::equal(
sprout::get_internal(copied),
array<int, 10>{{0, 0, 3, 4, 5, 6, 7, 8, 0, 0}}
));
}
}
}
} // namespace testspr