]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/hana/include/boost/hana/fwd/range.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / hana / include / boost / hana / fwd / range.hpp
CommitLineData
7c673cae
FG
1/*!
2@file
3Forward declares `boost::hana::range`.
4
5@copyright Louis Dionne 2013-2016
6Distributed under the Boost Software License, Version 1.0.
7(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
8 */
9
10#ifndef BOOST_HANA_FWD_RANGE_HPP
11#define BOOST_HANA_FWD_RANGE_HPP
12
13#include <boost/hana/config.hpp>
14#include <boost/hana/fwd/core/make.hpp>
15#include <boost/hana/fwd/integral_constant.hpp>
16
17
18BOOST_HANA_NAMESPACE_BEGIN
19#ifdef BOOST_HANA_DOXYGEN_INVOKED
20 //! @ingroup group-datatypes
21 //! Compile-time half-open interval of `hana::integral_constant`s.
22 //!
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`.
28 //!
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
32 //! `from <= to`.
33 //!
34 //! @note
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`.
39 //!
40 //!
41 //! Modeled concepts
42 //! ----------------
43 //! 1. `Comparable`\n
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
47 //!
48 //! 2. `Foldable`\n
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
52 //!
53 //! 3. `Iterable`\n
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
60 //!
61 //! 4. `Searchable`\n
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>
66 struct range {
67 //! Equivalent to `hana::equal`
68 template <typename X, typename Y>
69 friend constexpr auto operator==(X&& x, Y&& y);
70
71 //! Equivalent to `hana::not_equal`
72 template <typename X, typename Y>
73 friend constexpr auto operator!=(X&& x, Y&& y);
74
75 //! Equivalent to `hana::at`
76 template <typename N>
77 constexpr decltype(auto) operator[](N&& n);
78 };
79#else
80 template <typename T, T from, T to>
81 struct range;
82#endif
83
84 //! Tag representing a `hana::range`.
85 //! @relates hana::range
86 struct range_tag { };
87
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
92 //!
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.
101 //!
102 //!
103 //! Example
104 //! -------
105 //! @include example/range/make.cpp
106 template <>
107 constexpr auto make<range_tag> = [](auto const& from, auto const& to) {
108 return range<implementation_defined>{implementation_defined};
109 };
110#endif
111
112 //! Alias to `make<range_tag>`; provided for convenience.
113 //! @relates hana::range
114 constexpr auto make_range = make<range_tag>;
115
116 //! Shorthand to create a `hana::range` with the given bounds.
117 //! @relates hana::range
118 //!
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
121 //! @code
122 //! range_c<T, from, to> == make_range(integral_c<T, from>, integral_c<T, to>)
123 //! @endcode
124 //!
125 //!
126 //! @tparam T
127 //! The underlying integral type of the `integral_constant`s in the
128 //! created range.
129 //!
130 //! @tparam from
131 //! The inclusive lower bound of the created range.
132 //!
133 //! @tparam to
134 //! The exclusive upper bound of the created range.
135 //!
136 //!
137 //! Example
138 //! -------
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>);
143#else
144 template <typename T, T from, T to>
145 constexpr range<T, from, to> range_c{};
146#endif
147BOOST_HANA_NAMESPACE_END
148
149#endif // !BOOST_HANA_FWD_RANGE_HPP