Fix std::array remapping

This commit is contained in:
Denis Blank 2018-02-09 03:36:12 +01:00
parent 0982748ad6
commit a5640a5d35
2 changed files with 23 additions and 39 deletions

View File

@ -227,8 +227,14 @@ constexpr auto pack_size_of(identity<std::pair<First, Second>>) noexcept {
return size_of_t<First, Second>{}; return size_of_t<First, Second>{};
} }
/// Returns the pack size of the given type /// Returns the pack size of the given type
template <typename T, std::size_t Size>
constexpr auto pack_size_of(identity<std::array<T, Size>>) noexcept {
return size_constant<Size>{};
}
/// Returns the pack size of the given type
template <typename... Args> template <typename... Args>
constexpr auto pack_size_of(identity<Args...>) noexcept { constexpr auto pack_size_of(identity<Args...>) noexcept {
// TODO Replace this through the generic std::tuple_size
return size_of_t<Args...>{}; return size_of_t<Args...>{};
} }

View File

@ -642,6 +642,14 @@ void test_strategic_container_traverse() {
} }
} }
TEST(traverse_single_test, test_strategic_tuple_like_traverse_homogeneous) {
// Fixed size homogeneous container
std::array<int, 3> values{{1, 2, 3}};
std::array<float, 3> res = map_pack([](int) { return 1.f; }, values);
EXPECT_TRUE((res == std::array<float, 3>{{1.f, 1.f, 1.f}}));
}
void test_strategic_tuple_like_traverse() { void test_strategic_tuple_like_traverse() {
// Every element in the tuple like type is visited // Every element in the tuple like type is visited
{ {
@ -685,15 +693,6 @@ void test_strategic_tuple_like_traverse() {
EXPECT_TRUE((res == expected)); EXPECT_TRUE((res == expected));
} }
// Fixed size homogeneous container
// TODO Fix this test
//{
// std::array<int, 3> values{{1, 2, 3}};
// std::array<float, 3> res = map_pack([](int) { return 1.f; }, values);
// EXPECT_TRUE((res == std::array<float, 3>{{1.f, 1.f, 1.f}}));
//}
// Make it possible to pass tuples containing move only objects // Make it possible to pass tuples containing move only objects
// in as reference, while returning those as reference. // in as reference, while returning those as reference.
{ {
@ -769,6 +768,15 @@ void test_spread_container_traverse() {
} }
} }
// 1:2 mappings (multiple arguments)
TEST(traverse_single_test, test_spread_container_traverse_multiple_args) {
auto res = map_pack(duplicate_mapper{}, std::array<int, 2>{{1, 2}});
std::array<int, 4> expected{{1, 1, 2, 2}};
EXPECT_TRUE((res == expected));
}
void test_spread_tuple_like_traverse() { void test_spread_tuple_like_traverse() {
// 1:2 mappings (multiple arguments) // 1:2 mappings (multiple arguments)
{ {
@ -788,16 +796,6 @@ void test_spread_tuple_like_traverse() {
static_assert(std::is_void<Result>::value, "Failed..."); static_assert(std::is_void<Result>::value, "Failed...");
} }
// 1:2 mappings (multiple arguments)
//{
// std::array<int, 4> res =
// map_pack(duplicate_mapper{}, std::array<int, 2>{{1, 2}});
// std::array<int, 4> expected{{1, 1, 2, 2}};
// EXPECT_TRUE((res == expected));
//}
// 1:0 mappings // 1:0 mappings
{ {
using Result = using Result =
@ -805,23 +803,3 @@ void test_spread_tuple_like_traverse() {
static_assert(std::is_void<Result>::value, "Failed..."); static_assert(std::is_void<Result>::value, "Failed...");
} }
} }
/*
TODO Convert this to gtest
int main(int, char**) {
test_mixed_traversal();
test_mixed_early_unwrapping();
test_mixed_container_remap();
test_mixed_fall_through();
test_strategic_traverse();
test_strategic_container_traverse();
test_strategic_tuple_like_traverse();
test_spread_traverse();
test_spread_container_traverse();
test_spread_tuple_like_traverse();
return report_errors();
}
*/