3 Defines `boost::hana::detail::array`.
5 @copyright Louis Dionne 2013-2016
6 Distributed under the Boost Software License, Version 1.0.
7 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
10 #ifndef BOOST_HANA_DETAIL_ARRAY_HPP
11 #define BOOST_HANA_DETAIL_ARRAY_HPP
13 #include <boost/hana/config.hpp>
14 #include <boost/hana/detail/algorithm.hpp>
15 #include <boost/hana/functional/placeholder.hpp>
20 BOOST_HANA_NAMESPACE_BEGIN namespace detail {
22 constexpr N factorial(N n) {
29 //! @ingroup group-details
30 //! A minimal `std::array` with better `constexpr` support.
32 //! We also provide some algorithms from the `constexpr/algorithm.hpp`
33 //! header as member functions to make them easier to use in constexpr
34 //! contexts, since a `constexpr` `array` can't be mutated in place.
35 template <typename T, std::size_t Size>
37 T elems_[Size > 0 ? Size : 1];
39 constexpr T& operator[](std::size_t n)
42 constexpr T const& operator[](std::size_t n) const
45 constexpr std::size_t size() const noexcept
48 constexpr T* begin() noexcept { return elems_; }
49 constexpr T const* begin() const noexcept { return elems_; }
50 constexpr T* end() noexcept { return elems_ + Size; }
51 constexpr T const* end() const noexcept { return elems_ + Size; }
53 // Algorithms from constexpr/algorithm.hpp
54 constexpr array reverse() const {
56 detail::reverse(result.begin(), result.end());
60 template <typename BinaryPred>
61 constexpr auto permutations(BinaryPred pred) const {
62 array<array<T, Size>, detail::factorial(Size)> result{};
63 auto out = result.begin();
67 while (detail::next_permutation(copy.begin(), copy.end(), pred));
72 constexpr auto permutations() const
73 { return this->permutations(hana::_ < hana::_); }
76 template <typename BinaryPred>
77 constexpr auto sort(BinaryPred pred) const {
79 detail::sort(result.begin(), result.end(), pred);
83 constexpr auto sort() const
84 { return this->sort(hana::_ < hana::_); }
87 constexpr auto iota(U value) const {
89 detail::iota(result.begin(), result.end(), value);
94 template <typename T, std::size_t M, typename U, std::size_t N>
95 constexpr bool operator==(array<T, M> a, array<U, N> b)
96 { return M == N && detail::equal(a.begin(), a.end(), b.begin(), b.end()); }
98 template <typename T, std::size_t M, typename U, std::size_t N>
99 constexpr bool operator<(array<T, M> a, array<U, N> b) {
100 return M < N || detail::lexicographical_compare(a.begin(), a.end(), b.begin(), b.end());
103 } BOOST_HANA_NAMESPACE_END
105 #endif // !BOOST_HANA_DETAIL_ARRAY_HPP