diff --git a/include/xtensor/xadapt.hpp b/include/xtensor/xadapt.hpp index a79788e09..5a366dd16 100644 --- a/include/xtensor/xadapt.hpp +++ b/include/xtensor/xadapt.hpp @@ -35,6 +35,12 @@ namespace xt static constexpr std::size_t value = N; }; + template + struct array_size_impl> + { + static constexpr std::size_t value = N; + }; + template using array_size = array_size_impl>; @@ -209,7 +215,8 @@ namespace xt * @param container the container to adapt * @param l the layout_type of the xtensor_adaptor */ - template + template >)> inline xtensor_adaptor adapt(C&& container, layout_type l = L) { @@ -218,6 +225,22 @@ namespace xt return return_type(std::forward(container), shape, l); } + /** + * Constructs a 1-D xtensor_adaptor of the given stl-like container, + * with the specified layout_type. + * @param container the container to adapt + * @param l the layout_type of the xtensor_adaptor + */ + template >)> + inline auto + adapt(C&& container) + { + // const std::array::size_type, 1> shape{container.size()}; + using return_type = xfixed_adaptor, fixed_shape>::value>, L>; + return return_type(std::forward(container)); + } + /** * Constructs an xtensor_adaptor of the given stl-like container, * with the specified shape and layout_type. diff --git a/include/xtensor/xcontainer.hpp b/include/xtensor/xcontainer.hpp index d6d3c9b82..b457b8049 100644 --- a/include/xtensor/xcontainer.hpp +++ b/include/xtensor/xcontainer.hpp @@ -52,6 +52,14 @@ namespace xt { using type = std::allocator; // fake allocator for testing }; + + + template + struct allocator_type_impl> + { + using type = std::allocator; // fake allocator for testing + }; + } template diff --git a/include/xtensor/xfixed.hpp b/include/xtensor/xfixed.hpp index 265ba481d..4b6d14084 100644 --- a/include/xtensor/xfixed.hpp +++ b/include/xtensor/xfixed.hpp @@ -400,7 +400,7 @@ namespace xt struct xcontainer_inner_types> { using storage_type = std::remove_reference_t; - using reference = typename storage_type::reference; + using reference = inner_reference_t; using const_reference = typename storage_type::const_reference; using size_type = typename storage_type::size_type; using shape_type = S; diff --git a/include/xtensor/xshape.hpp b/include/xtensor/xshape.hpp index e9ee57826..119c6b089 100644 --- a/include/xtensor/xshape.hpp +++ b/include/xtensor/xshape.hpp @@ -351,6 +351,12 @@ namespace xt { static constexpr bool value = true; }; + + template + struct is_array> + { + static constexpr bool value = true; + }; template struct is_fixed : std::false_type diff --git a/test/test_xadapt.cpp b/test/test_xadapt.cpp index b966dd166..a7dbfca91 100644 --- a/test/test_xadapt.cpp +++ b/test/test_xadapt.cpp @@ -418,6 +418,23 @@ namespace xt } } + TEST(xtensor_fixed_adaptor, array) + { + std::array a({1,2,3,4,5,6,7,8}); + auto xa = adapt(a); + xa(0) = 100; + xa(3) = 1000; + EXPECT_EQ(a[0], 100); + EXPECT_EQ(a[3], 1000); + bool truthy = std::is_same>::value; + EXPECT_TRUE(truthy); + + const std::array b({5,5,19,5}); + auto xb = adapt(b); + EXPECT_EQ(xb(2), 19); + EXPECT_EQ(xb(0), 5); + } + namespace xadapt_test { struct Buffer {