Boost.Hana  1.7.0
Your standard library for metaprogramming
std::array< T, N > Struct Template Reference

Description

template<typename T, std::size_t N>
struct std::array< T, N >

Adaptation of std::array for Hana.

Modeled concepts

  1. Comparable
    std::arrays are compared as per std::equal, except that two arrays with different sizes compare unequal instead of triggering an error and the result of the comparison is constexpr if both arrays are constexpr.
    // Copyright Louis Dionne 2013-2017
    // 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 <array>
    namespace hana = boost::hana;
    constexpr std::array<int, 4> xs = {{1, 2, 3, 4}};
    constexpr std::array<int, 5> ys = {{1, 2, 3, 4, 5}};
    // arrays have different constexpr contents; result is a constexpr bool
    static_assert(hana::equal(xs, xs), "");
    // arrays have different lengths; result is an integral_constant
    int main() { }
  2. Orderable
    std::arrays are ordered with the usual lexicographical ordering, except that two arrays with different size can be ordered instead of triggering an error and the result of the comparison is constexpr if both arrays are constexpr.
    // Copyright Louis Dionne 2013-2017
    // 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 <array>
    namespace hana = boost::hana;
    constexpr std::array<int, 4> evens = {{2, 4, 6, 8}};
    constexpr std::array<int, 4> odds = {{1, 3, 5, 7}};
    constexpr std::array<int, 5> up_to_5 = {{1, 2, 3, 4, 5}};
    // arrays with same length
    static_assert(hana::less(odds, evens), "");
    // arrays with different lengths
    static_assert(hana::less(up_to_5, odds), "");
    int main() { }
  3. Foldable
    Folding an array from the left is equivalent to calling std::accumulate on it, except it can be constexpr.
    // Copyright Louis Dionne 2013-2017
    // 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 <array>
    namespace hana = boost::hana;
    int main() {
    std::array<int, 5> a = {{0, 1, 2, 3, 4}};
    auto b = hana::unpack(a, [](auto ...i) {
    return std::array<int, sizeof...(i)>{{(i + 10)...}};
    });
    BOOST_HANA_RUNTIME_CHECK(b == std::array<int, 5>{{10, 11, 12, 13, 14}});
    }
  4. Iterable
    Iterating over a std::array is equivalent to iterating over it with a normal for loop.
    // Copyright Louis Dionne 2013-2017
    // 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 <array>
    namespace hana = boost::hana;
    constexpr std::array<int, 5> a = {{0, 1, 2, 3, 4}};
    static_assert(hana::at_c<2>(a) == 2, "");
    static_assert(hana::equal(hana::drop_front(a), std::array<int, 4>{{1, 2, 3, 4}}), "");
    int main() { }
less.hpp
Defines boost::hana::less.
equal.hpp
Defines boost::hana::equal.
drop_front.hpp
Defines boost::hana::drop_front.
boost::hana::less
constexpr auto less
Returns a Logical representing whether x is less than y.
Definition: less.hpp:37
BOOST_HANA_CONSTANT_CHECK
#define BOOST_HANA_CONSTANT_CHECK(...)
Equivalent to BOOST_HANA_CONSTANT_ASSERT, but not influenced by the BOOST_HANA_CONFIG_DISABLE_ASSERTI...
Definition: assert.hpp:239
boost::hana
Namespace containing everything in the library.
Definition: accessors.hpp:20
boost::hana::unpack
constexpr auto unpack
Invoke a function with the elements of a Foldable as arguments.
Definition: unpack.hpp:79
assert.hpp
Defines macros to perform different kinds of assertions.
array.hpp
Adapts std::array for use with Hana.
boost::hana::drop_front
constexpr auto drop_front
Drop the first n elements of an iterable, and return the rest.
Definition: drop_front.hpp:47
not_equal.hpp
Defines boost::hana::not_equal.
at.hpp
Defines boost::hana::at and boost::hana::at_c.
BOOST_HANA_RUNTIME_CHECK
#define BOOST_HANA_RUNTIME_CHECK(...)
Equivalent to BOOST_HANA_RUNTIME_ASSERT, but not influenced by the BOOST_HANA_CONFIG_DISABLE_ASSERTIO...
Definition: assert.hpp:209
boost::hana::not_equal
constexpr auto not_equal
Returns a Logical representing whether x is not equal to y.
Definition: not_equal.hpp:54
std::array
Adaptation of std::array for Hana.
Definition: array.hpp:64
boost::hana::equal
constexpr auto equal
Returns a Logical representing whether x is equal to y.
Definition: equal.hpp:64
unpack.hpp
Defines boost::hana::unpack.