3 Forward declares `boost::hana::range`.
5 @copyright Louis Dionne 2013-2017
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_FWD_RANGE_HPP
11 #define BOOST_HANA_FWD_RANGE_HPP
13 #include <boost/hana/config.hpp>
14 #include <boost/hana/fwd/core/make.hpp>
15 #include <boost/hana/fwd/integral_constant.hpp>
18 BOOST_HANA_NAMESPACE_BEGIN
19 #ifdef BOOST_HANA_DOXYGEN_INVOKED
20 //! @ingroup group-datatypes
21 //! Compile-time half-open interval of `hana::integral_constant`s.
23 //! A `range` represents a half-open interval of the form `[from, to)`
24 //! containing `hana::integral_constant`s of a given type. The `[from, to)`
25 //! notation represents the values starting at `from` (inclusively) up
26 //! to but excluding `from`. In other words, it is a bit like the list
27 //! `from, from+1, ..., to-1`.
29 //! In particular, note that the bounds of the range can be any
30 //! `hana::integral_constant`s (negative numbers are allowed) and the
31 //! range does not have to start at zero. The only requirement is that
35 //! The representation of `hana::range` is implementation defined. In
36 //! particular, one should not take for granted the number and types
37 //! of template parameters. The proper way to create a `hana::range`
38 //! is to use `hana::range_c` or `hana::make_range`.
44 //! Two ranges are equal if and only if they are both empty or they both
45 //! span the same interval.
46 //! @include example/range/comparable.cpp
49 //! Folding a `range` is equivalent to folding a list of the
50 //! `integral_constant`s in the interval it spans.
51 //! @include example/range/foldable.cpp
54 //! Iterating over a `range` is equivalent to iterating over a list of
55 //! the values it spans. In other words, iterating over the range
56 //! `[from, to)` is equivalent to iterating over a list containing
57 //! `from, from+1, from+2, ..., to-1`. Also note that `operator[]` can
58 //! be used in place of the `at` function.
59 //! @include example/range/iterable.cpp
62 //! Searching a `range` is equivalent to searching a list of the values
63 //! in the range `[from, to)`, but it is much more compile-time efficient.
64 //! @include example/range/searchable.cpp
65 template <typename T, T from, T to>
67 //! Equivalent to `hana::equal`
68 template <typename X, typename Y>
69 friend constexpr auto operator==(X&& x, Y&& y);
71 //! Equivalent to `hana::not_equal`
72 template <typename X, typename Y>
73 friend constexpr auto operator!=(X&& x, Y&& y);
75 //! Equivalent to `hana::at`
77 constexpr decltype(auto) operator[](N&& n);
80 template <typename T, T from, T to>
84 //! Tag representing a `hana::range`.
85 //! @relates hana::range
88 #ifdef BOOST_HANA_DOXYGEN_INVOKED
89 //! Create a `hana::range` representing a half-open interval of
90 //! `integral_constant`s.
91 //! @relates hana::range
93 //! Given two `IntegralConstant`s `from` and `to`, `make<range_tag>`
94 //! returns a `hana::range` representing the half-open interval of
95 //! `integral_constant`s `[from, to)`. `from` and `to` must form a
96 //! valid interval, which means that `from <= to` must be true. Otherwise,
97 //! a compilation error is triggered. Also note that if `from` and `to`
98 //! are `IntegralConstant`s with different underlying integral types,
99 //! the created range contains `integral_constant`s whose underlying
100 //! type is their common type.
105 //! @include example/range/make.cpp
107 constexpr auto make<range_tag> = [](auto const& from, auto const& to) {
108 return range<implementation_defined>{implementation_defined};
112 //! Alias to `make<range_tag>`; provided for convenience.
113 //! @relates hana::range
114 constexpr auto make_range = make<range_tag>;
116 //! Shorthand to create a `hana::range` with the given bounds.
117 //! @relates hana::range
119 //! This shorthand is provided for convenience only and it is equivalent
120 //! to `make_range`. Specifically, `range_c<T, from, to>` is such that
122 //! range_c<T, from, to> == make_range(integral_c<T, from>, integral_c<T, to>)
127 //! The underlying integral type of the `integral_constant`s in the
131 //! The inclusive lower bound of the created range.
134 //! The exclusive upper bound of the created range.
139 //! @include example/range/range_c.cpp
140 #ifdef BOOST_HANA_DOXYGEN_INVOKED
141 template <typename T, T from, T to>
142 constexpr auto range_c = make_range(integral_c<T, from>, integral_c<T, to>);
144 template <typename T, T from, T to>
145 constexpr range<T, from, to> range_c{};
147 BOOST_HANA_NAMESPACE_END
149 #endif // !BOOST_HANA_FWD_RANGE_HPP