diff --git a/include/boost/integer_sequence.hpp b/include/boost/integer_sequence.hpp new file mode 100644 index 0000000..3fc5175 --- /dev/null +++ b/include/boost/integer_sequence.hpp @@ -0,0 +1,85 @@ +#ifndef BOOST_INTEGER_SEQUENCE_HPP_INCLUDED +#define BOOST_INTEGER_SEQUENCE_HPP_INCLUDED + +#include + +namespace boost +{ + +// integer_sequence +template struct integer_sequence +{ +}; + +// detail::make_integer_sequence_impl +namespace detail +{ + +// iseq_if_c +template struct iseq_if_c_impl; + +template struct iseq_if_c_impl +{ + using type = T; +}; + +template struct iseq_if_c_impl +{ + using type = E; +}; + +template using iseq_if_c = typename iseq_if_c_impl::type; + +// iseq_identity +template struct iseq_identity +{ + using type = T; +}; + +template struct append_integer_sequence; + +template struct append_integer_sequence, integer_sequence> +{ + using type = integer_sequence< T, I..., ( J + sizeof...(I) )... >; +}; + +template struct make_integer_sequence_impl; + +template struct make_integer_sequence_impl_ +{ +private: + + static T const M = N / 2; + static T const R = N % 2; + + using S1 = typename make_integer_sequence_impl::type; + using S2 = typename append_integer_sequence::type; + using S3 = typename make_integer_sequence_impl::type; + using S4 = typename append_integer_sequence::type; + +public: + + using type = S4; +}; + +template struct make_integer_sequence_impl: iseq_if_c>, iseq_if_c>, make_integer_sequence_impl_>> +{ +}; + +} // namespace detail + +// make_integer_sequence +template using make_integer_sequence = typename detail::make_integer_sequence_impl::type; + +// index_sequence +template using index_sequence = integer_sequence; + +// make_index_sequence +template using make_index_sequence = make_integer_sequence; + +// index_sequence_for +template using index_sequence_for = make_integer_sequence; + +} // namespace boost + +#endif // #ifndef BOOST_INTEGER_SEQUENCE_HPP_INCLUDED diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index ec31f1c..de0a1ce 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -43,3 +43,6 @@ run mp_identity.cpp : : : $(REQ) ; run mp_inherit.cpp : : : $(REQ) ; run mp_if.cpp : : : $(REQ) ; run mp_eval_if.cpp : : : $(REQ) ; + +# integer_sequence +run integer_sequence.cpp : : : $(REQ) ; diff --git a/test/integer_sequence.cpp b/test/integer_sequence.cpp new file mode 100644 index 0000000..190b985 --- /dev/null +++ b/test/integer_sequence.cpp @@ -0,0 +1,53 @@ + +// Copyright 2015 Peter Dimov. +// +// Distributed under the Boost Software License, Version 1.0. +// +// See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt + + +#include +#include +#include + +int main() +{ + BOOST_TEST_TRAIT_TRUE((std::is_same, boost::integer_sequence>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, boost::integer_sequence>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, boost::integer_sequence>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, boost::integer_sequence>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, boost::integer_sequence>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, boost::integer_sequence>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, boost::integer_sequence>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, boost::integer_sequence>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, boost::integer_sequence>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, boost::integer_sequence>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, boost::integer_sequence>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, boost::integer_sequence>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, boost::integer_sequence>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, boost::integer_sequence>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, boost::integer_sequence>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, boost::integer_sequence>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, boost::integer_sequence>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, boost::integer_sequence>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, boost::integer_sequence>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, boost::integer_sequence>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, boost::index_sequence<>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, boost::index_sequence<0>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, boost::index_sequence<0, 1>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, boost::index_sequence<0, 1, 2>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, boost::index_sequence<0, 1, 2, 3>>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, boost::index_sequence<>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, boost::index_sequence<0>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, boost::index_sequence<0, 1>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, boost::index_sequence<0, 1, 2>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, boost::index_sequence<0, 1, 2, 3>>)); + + return boost::report_errors(); +}