diff --git a/include/boost/hana.hpp b/include/boost/hana.hpp index 6e77ba8d2..9e1361bf4 100644 --- a/include/boost/hana.hpp +++ b/include/boost/hana.hpp @@ -41,6 +41,7 @@ #include #include #include +#include #include #include diff --git a/include/boost/hana/std_integer_sequence.hpp b/include/boost/hana/std_integer_sequence.hpp new file mode 100644 index 000000000..ade8c34db --- /dev/null +++ b/include/boost/hana/std_integer_sequence.hpp @@ -0,0 +1,53 @@ +/*! + * @file + * Adapts `std::integer_sequence`. + * + * + * @copyright Louis Dionne 2014 + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE.md or copy at + * http://www.boost.org/LICENSE_1_0.txt) + */ + +#ifndef BOOST_HANA_STD_INTEGER_SEQUENCE_HPP +#define BOOST_HANA_STD_INTEGER_SEQUENCE_HPP + +#include +#include +#include +#include +#include +#include +#include + +#include + + +namespace boost { namespace hana { + template + struct Iterable> : defaults { + template + static constexpr auto head_impl(std::integer_sequence) + { return std::integral_constant{}; } + + template + static constexpr auto tail_impl(std::integer_sequence) + { return std::integer_sequence{}; } + + static constexpr auto is_empty_impl(std::integer_sequence) + { return bool_; } + }; + + template + struct Foldable> + : detail::foldable_from_iterable + { }; + + template + struct Comparable, + std::integer_sequence> + : detail::comparable_from_iterable + { }; +}} // end namespace boost::hana + +#endif // !BOOST_HANA_STD_INTEGER_SEQUENCE_HPP diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 3dde9ab61..0b5803aef 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -58,6 +58,8 @@ boost_hana_add_test(range.comparable) boost_hana_add_test(range.functor) boost_hana_add_test(range.iterable) +boost_hana_add_test(std_integer_sequence.iterable) + boost_hana_add_test(std_tuple.functor) boost_hana_add_test(std_tuple.iterable) diff --git a/test/std_integer_sequence/iterable.cpp b/test/std_integer_sequence/iterable.cpp new file mode 100644 index 000000000..10ebef0ab --- /dev/null +++ b/test/std_integer_sequence/iterable.cpp @@ -0,0 +1,27 @@ +/* + * Copyright Louis Dionne 2014 + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE.md or copy at + * http://www.boost.org/LICENSE_1_0.txt) + */ + +#include + +#include + +#include +using namespace boost::hana; + + +int main() { + BOOST_HANA_STATIC_ASSERT(is_empty(std::index_sequence<>{})); + BOOST_HANA_STATIC_ASSERT(!is_empty(std::index_sequence<0>{})); + BOOST_HANA_STATIC_ASSERT(!is_empty(std::index_sequence<1>{})); + + BOOST_HANA_STATIC_ASSERT(head(std::index_sequence<0>{}) == 0); + BOOST_HANA_STATIC_ASSERT(head(std::index_sequence<0, 1>{}) == 0); + + BOOST_HANA_STATIC_ASSERT(equal(tail(std::index_sequence<0>{}), std::index_sequence<>{})); + BOOST_HANA_STATIC_ASSERT(equal(tail(std::index_sequence<0, 1>{}), std::index_sequence<1>{})); + BOOST_HANA_STATIC_ASSERT(equal(tail(std::index_sequence<0, 1, 2>{}), std::index_sequence<1, 2>{})); +}