|
| 1 | +#include <stdx/array.hpp> |
| 2 | + |
| 3 | +#include <catch2/catch_test_macros.hpp> |
| 4 | + |
| 5 | +#include <array> |
| 6 | + |
| 7 | +TEST_CASE("make_array (variadic arguments)", "[array]") { |
| 8 | + auto arr = stdx::make_array(1, 2, 3, 4, 5); |
| 9 | + STATIC_CHECK(std::is_same_v<decltype(arr), std::array<int, 5>>); |
| 10 | + CHECK(arr == std::array{1, 2, 3, 4, 5}); |
| 11 | +} |
| 12 | + |
| 13 | +namespace { |
| 14 | +template <auto I> using V = std::integral_constant<decltype(I), I + 1>; |
| 15 | +} |
| 16 | + |
| 17 | +TEST_CASE("make_array by sequence (template with ::value)", "[array]") { |
| 18 | + auto arr = stdx::make_array<V>(std::make_integer_sequence<int, 5>{}); |
| 19 | + STATIC_CHECK(std::is_same_v<decltype(arr), std::array<int, 5>>); |
| 20 | + CHECK(arr == std::array{1, 2, 3, 4, 5}); |
| 21 | +} |
| 22 | + |
| 23 | +TEST_CASE("make_array by extent (template with ::value)", "[array]") { |
| 24 | + auto arr = stdx::make_array<V, 5>(); |
| 25 | + STATIC_CHECK(std::is_same_v<decltype(arr), std::array<int, 5>>); |
| 26 | + CHECK(arr == std::array{1, 2, 3, 4, 5}); |
| 27 | +} |
| 28 | + |
| 29 | +namespace { |
| 30 | +struct { |
| 31 | + template <auto I> auto operator()() { return I + 1; } |
| 32 | +} f; |
| 33 | +} // namespace |
| 34 | + |
| 35 | +TEST_CASE("make_array by sequence (factory function template)", "[array]") { |
| 36 | + auto arr = stdx::make_array(std::make_integer_sequence<int, 5>{}, f); |
| 37 | + STATIC_CHECK(std::is_same_v<decltype(arr), std::array<int, 5>>); |
| 38 | + CHECK(arr == std::array{1, 2, 3, 4, 5}); |
| 39 | +} |
| 40 | + |
| 41 | +TEST_CASE("make_array by extent (factory function template)", "[array]") { |
| 42 | + auto arr = stdx::make_array<5>(f); |
| 43 | + STATIC_CHECK(std::is_same_v<decltype(arr), std::array<int, 5>>); |
| 44 | + CHECK(arr == std::array{1, 2, 3, 4, 5}); |
| 45 | +} |
0 commit comments