|
||||
File indexing completed on 2024-11-15 09:13:44
0001 /*! 0002 @file 0003 Forward declares `boost::hana::range`. 0004 0005 Copyright Louis Dionne 2013-2022 0006 Distributed under the Boost Software License, Version 1.0. 0007 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) 0008 */ 0009 0010 #ifndef BOOST_HANA_FWD_RANGE_HPP 0011 #define BOOST_HANA_FWD_RANGE_HPP 0012 0013 #include <boost/hana/config.hpp> 0014 #include <boost/hana/fwd/core/make.hpp> 0015 #include <boost/hana/fwd/integral_constant.hpp> 0016 0017 0018 namespace boost { namespace hana { 0019 #ifdef BOOST_HANA_DOXYGEN_INVOKED 0020 //! @ingroup group-datatypes 0021 //! Compile-time half-open interval of `hana::integral_constant`s. 0022 //! 0023 //! A `range` represents a half-open interval of the form `[from, to)` 0024 //! containing `hana::integral_constant`s of a given type. The `[from, to)` 0025 //! notation represents the values starting at `from` (inclusively) up 0026 //! to but excluding `from`. In other words, it is a bit like the list 0027 //! `from, from+1, ..., to-1`. 0028 //! 0029 //! In particular, note that the bounds of the range can be any 0030 //! `hana::integral_constant`s (negative numbers are allowed) and the 0031 //! range does not have to start at zero. The only requirement is that 0032 //! `from <= to`. 0033 //! 0034 //! @note 0035 //! The representation of `hana::range` is implementation defined. In 0036 //! particular, one should not take for granted the number and types 0037 //! of template parameters. The proper way to create a `hana::range` 0038 //! is to use `hana::range_c` or `hana::make_range`. More details 0039 //! [in the tutorial](@ref tutorial-containers-types). 0040 //! 0041 //! 0042 //! Modeled concepts 0043 //! ---------------- 0044 //! 1. `Comparable`\n 0045 //! Two ranges are equal if and only if they are both empty or they both 0046 //! span the same interval. 0047 //! @include example/range/comparable.cpp 0048 //! 0049 //! 2. `Foldable`\n 0050 //! Folding a `range` is equivalent to folding a list of the 0051 //! `integral_constant`s in the interval it spans. 0052 //! @include example/range/foldable.cpp 0053 //! 0054 //! 3. `Iterable`\n 0055 //! Iterating over a `range` is equivalent to iterating over a list of 0056 //! the values it spans. In other words, iterating over the range 0057 //! `[from, to)` is equivalent to iterating over a list containing 0058 //! `from, from+1, from+2, ..., to-1`. Also note that `operator[]` can 0059 //! be used in place of the `at` function. 0060 //! @include example/range/iterable.cpp 0061 //! 0062 //! 4. `Searchable`\n 0063 //! Searching a `range` is equivalent to searching a list of the values 0064 //! in the range `[from, to)`, but it is much more compile-time efficient. 0065 //! @include example/range/searchable.cpp 0066 template <typename T, T from, T to> 0067 struct range { 0068 //! Equivalent to `hana::equal` 0069 template <typename X, typename Y> 0070 friend constexpr auto operator==(X&& x, Y&& y); 0071 0072 //! Equivalent to `hana::not_equal` 0073 template <typename X, typename Y> 0074 friend constexpr auto operator!=(X&& x, Y&& y); 0075 0076 //! Equivalent to `hana::at` 0077 template <typename N> 0078 constexpr decltype(auto) operator[](N&& n); 0079 }; 0080 #else 0081 template <typename T, T from, T to> 0082 struct range; 0083 #endif 0084 0085 //! Tag representing a `hana::range`. 0086 //! @relates hana::range 0087 struct range_tag { }; 0088 0089 #ifdef BOOST_HANA_DOXYGEN_INVOKED 0090 //! Create a `hana::range` representing a half-open interval of 0091 //! `integral_constant`s. 0092 //! @relates hana::range 0093 //! 0094 //! Given two `IntegralConstant`s `from` and `to`, `make<range_tag>` 0095 //! returns a `hana::range` representing the half-open interval of 0096 //! `integral_constant`s `[from, to)`. `from` and `to` must form a 0097 //! valid interval, which means that `from <= to` must be true. Otherwise, 0098 //! a compilation error is triggered. Also note that if `from` and `to` 0099 //! are `IntegralConstant`s with different underlying integral types, 0100 //! the created range contains `integral_constant`s whose underlying 0101 //! type is their common type. 0102 //! 0103 //! 0104 //! Example 0105 //! ------- 0106 //! @include example/range/make.cpp 0107 template <> 0108 constexpr auto make<range_tag> = [](auto const& from, auto const& to) { 0109 return range<implementation_defined>{implementation_defined}; 0110 }; 0111 #endif 0112 0113 //! Alias to `make<range_tag>`; provided for convenience. 0114 //! @relates hana::range 0115 BOOST_HANA_INLINE_VARIABLE constexpr auto make_range = make<range_tag>; 0116 0117 //! Shorthand to create a `hana::range` with the given bounds. 0118 //! @relates hana::range 0119 //! 0120 //! This shorthand is provided for convenience only and it is equivalent 0121 //! to `make_range`. Specifically, `range_c<T, from, to>` is such that 0122 //! @code 0123 //! range_c<T, from, to> == make_range(integral_c<T, from>, integral_c<T, to>) 0124 //! @endcode 0125 //! 0126 //! 0127 //! @tparam T 0128 //! The underlying integral type of the `integral_constant`s in the 0129 //! created range. 0130 //! 0131 //! @tparam from 0132 //! The inclusive lower bound of the created range. 0133 //! 0134 //! @tparam to 0135 //! The exclusive upper bound of the created range. 0136 //! 0137 //! 0138 //! Example 0139 //! ------- 0140 //! @include example/range/range_c.cpp 0141 #ifdef BOOST_HANA_DOXYGEN_INVOKED 0142 template <typename T, T from, T to> 0143 constexpr auto range_c = make_range(integral_c<T, from>, integral_c<T, to>); 0144 #else 0145 template <typename T, T from, T to> 0146 BOOST_HANA_INLINE_VARIABLE constexpr range<T, from, to> range_c{}; 0147 #endif 0148 }} // end namespace boost::hana 0149 0150 #endif // !BOOST_HANA_FWD_RANGE_HPP
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |