diff --git a/include/boost/hana/adapted/std_array.hpp b/include/boost/hana/adapted/std_array.hpp index 325509044..294829a10 100644 --- a/include/boost/hana/adapted/std_array.hpp +++ b/include/boost/hana/adapted/std_array.hpp @@ -10,10 +10,10 @@ Distributed under the Boost Software License, Version 1.0. #ifndef BOOST_HANA_ADAPTED_STD_ARRAY_HPP #define BOOST_HANA_ADAPTED_STD_ARRAY_HPP -#include #include #include #include +#include #include #include @@ -52,7 +52,25 @@ namespace boost { namespace hana { }; template <> - constexpr bool comparable_from_iterable = true; + struct List::instance : List::mcd { + struct anything { }; + + static constexpr auto nil_impl() { + return std::array{}; + } + + template + static constexpr auto cons_impl(X x, std::array arr) { + auto make_array = [=](auto ...indices) -> std::array + { return {{x, arr[indices]...}}; }; + return unpack(make_array, range(size_t<0>, size_t)); + } + + template + static constexpr auto cons_impl(X x, std::array) { + return cons_impl(x, std::array{}); + } + }; }} // end namespace boost::hana #endif // !BOOST_HANA_ADAPTED_STD_ARRAY_HPP diff --git a/test/adapted/std_array/iterable/head.cpp b/test/adapted/std_array/iterable/head.cpp new file mode 100644 index 000000000..25bba72c3 --- /dev/null +++ b/test/adapted/std_array/iterable/head.cpp @@ -0,0 +1,22 @@ +/* +@copyright Louis Dionne 2014 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + */ + +#include + +#include + +#include +using namespace boost::hana; + + +template +constexpr auto array = std::array{{i...}}; + +int main() { + BOOST_HANA_STATIC_ASSERT(head(array<0>) == 0); + BOOST_HANA_STATIC_ASSERT(head(array<0, 1>) == 0); + BOOST_HANA_STATIC_ASSERT(head(array<0, 1, 2>) == 0); +} diff --git a/test/adapted/std_array/iterable/is_empty.cpp b/test/adapted/std_array/iterable/is_empty.cpp new file mode 100644 index 000000000..8aa69e68e --- /dev/null +++ b/test/adapted/std_array/iterable/is_empty.cpp @@ -0,0 +1,22 @@ +/* +@copyright Louis Dionne 2014 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + */ + +#include + +#include + +#include +using namespace boost::hana; + + +template + auto array = std::array{{i...}}; + +int main() { + BOOST_HANA_STATIC_ASSERT(is_empty(array<>)); + BOOST_HANA_STATIC_ASSERT(!is_empty(array<0>)); + BOOST_HANA_STATIC_ASSERT(!is_empty(array<0, 1>)); +} diff --git a/test/adapted/std_array/iterable.cpp b/test/adapted/std_array/iterable/tail.cpp similarity index 62% rename from test/adapted/std_array/iterable.cpp rename to test/adapted/std_array/iterable/tail.cpp index ef59ea5e2..47fac2766 100644 --- a/test/adapted/std_array/iterable.cpp +++ b/test/adapted/std_array/iterable/tail.cpp @@ -13,17 +13,9 @@ using namespace boost::hana; template - auto array = std::array{{i...}}; +constexpr auto array = std::array{{i...}}; int main() { - BOOST_HANA_STATIC_ASSERT(is_empty(array<>)); - BOOST_HANA_STATIC_ASSERT(!is_empty(array<0>)); - BOOST_HANA_STATIC_ASSERT(!is_empty(array<0, 1>)); - - BOOST_HANA_STATIC_ASSERT(head(array<0>) == 0); - BOOST_HANA_STATIC_ASSERT(head(array<0, 1>) == 0); - BOOST_HANA_STATIC_ASSERT(head(array<0, 1, 2>) == 0); - BOOST_HANA_STATIC_ASSERT(tail(array<0>) == array<>); BOOST_HANA_STATIC_ASSERT(tail(array<0, 1>) == array<1>); BOOST_HANA_STATIC_ASSERT(tail(array<0, 1, 2>) == array<1, 2>); diff --git a/test/adapted/std_array/list/cons.cpp b/test/adapted/std_array/list/cons.cpp new file mode 100644 index 000000000..f5ee54b6c --- /dev/null +++ b/test/adapted/std_array/list/cons.cpp @@ -0,0 +1,26 @@ +/* +@copyright Louis Dionne 2014 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + */ + +#include + +#include + +#include +using namespace boost::hana; + + +template +constexpr auto array = std::array{{i...}}; + +int main() { + using operators::operator==; + BOOST_HANA_STATIC_ASSERT(cons(0, array<>) == array<0>); + BOOST_HANA_STATIC_ASSERT(cons(0, array<1>) == array<0, 1>); + BOOST_HANA_STATIC_ASSERT(cons(0, array<1, 2>) == array<0, 1, 2>); + BOOST_HANA_STATIC_ASSERT(cons(0, array<1, 2, 3>) == array<0, 1, 2, 3>); + + BOOST_HANA_STATIC_ASSERT(cons(0, nil) == array<0>); +} diff --git a/test/adapted/std_array/list/nil.cpp b/test/adapted/std_array/list/nil.cpp new file mode 100644 index 000000000..544bd0dab --- /dev/null +++ b/test/adapted/std_array/list/nil.cpp @@ -0,0 +1,20 @@ +/* +@copyright Louis Dionne 2014 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + */ + +#include + +#include + +#include +using namespace boost::hana; + + +int main() { + using operators::operator==; + BOOST_HANA_STATIC_ASSERT(nil == std::array{}); + BOOST_HANA_STATIC_ASSERT(nil == std::array{}); + BOOST_HANA_STATIC_ASSERT(nil == std::array{}); +}