diff --git a/include/xtensor/xadapt.hpp b/include/xtensor/xadapt.hpp index a79788e09..56e1dd73a 100644 --- a/include/xtensor/xadapt.hpp +++ b/include/xtensor/xadapt.hpp @@ -209,7 +209,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 +219,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/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/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 {