|
|
|||
File indexing completed on 2025-12-15 09:53:04
0001 /*! 0002 @file 0003 Forward declares `boost::hana::lexicographical_compare`. 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_LEXICOGRAPHICAL_COMPARE_HPP 0011 #define BOOST_HANA_FWD_LEXICOGRAPHICAL_COMPARE_HPP 0012 0013 #include <boost/hana/config.hpp> 0014 #include <boost/hana/core/when.hpp> 0015 0016 0017 namespace boost { namespace hana { 0018 //! Short-circuiting lexicographical comparison of two `Iterable`s with 0019 //! an optional custom predicate, by default `hana::less`. 0020 //! @ingroup group-Iterable 0021 //! 0022 //! Given two `Iterable`s `xs` and `ys` and a binary predicate `pred`, 0023 //! `lexicographical_compare` returns whether `xs` is to be considered 0024 //! less than `ys` in a lexicographical ordering. Specifically, let's 0025 //! denote the linearizations of `xs` and `ys` by `[x1, x2, ...]` and 0026 //! `[y1, y2, ...]`, respectively. If the first couple satisfying the 0027 //! predicate is of the form `xi, yi`, `lexicographical_compare` returns 0028 //! true. Otherwise, if the first couple to satisfy the predicate is of 0029 //! the form `yi, xi`, `lexicographical_compare` returns false. If no 0030 //! such couple can be found, `lexicographical_compare` returns whether 0031 //! `xs` has fewer elements than `ys`. 0032 //! 0033 //! @note 0034 //! This algorithm will short-circuit as soon as it can determine that one 0035 //! sequence is lexicographically less than the other. Hence, it can be 0036 //! used to compare infinite sequences. However, for the procedure to 0037 //! terminate on infinite sequences, the predicate has to be satisfied 0038 //! at a finite index. 0039 //! 0040 //! 0041 //! Signature 0042 //! --------- 0043 //! Given two `Iterable`s `It1(T)` and `It2(T)` and a predicate 0044 //! \f$ pred : T \times T \to Bool \f$ (where `Bool` is some `Logical`), 0045 //! `lexicographical_compare` has the following signatures. For the 0046 //! variant with a provided predicate, 0047 //! \f[ 0048 //! \mathtt{lexicographical\_compare} 0049 //! : It1(T) \times It2(T) \times (T \times T \to Bool) \to Bool 0050 //! \f] 0051 //! 0052 //! for the variant without a custom predicate, `T` is required to be 0053 //! `Orderable`. The signature is then 0054 //! \f[ 0055 //! \mathtt{lexicographical\_compare} : It1(T) \times It2(T) \to Bool 0056 //! \f] 0057 //! 0058 //! @param xs, ys 0059 //! Two `Iterable`s to compare lexicographically. 0060 //! 0061 //! @param pred 0062 //! A binary function called as `pred(x, y)` and `pred(y, x)`, where `x` 0063 //! and `y` are elements of `xs` and `ys`, respectively. `pred` must 0064 //! return a `Logical` representing whether its first argument is to be 0065 //! considered as less than its second argument. Also note that `pred` 0066 //! must define a total ordering as defined by the `Orderable` concept. 0067 //! When `pred` is not provided, it defaults to `less`. 0068 //! 0069 //! 0070 //! Example 0071 //! ------- 0072 //! @include example/lexicographical_compare.cpp 0073 #ifdef BOOST_HANA_DOXYGEN_INVOKED 0074 constexpr auto lexicographical_compare = [](auto const& xs, auto const& ys, auto const& pred = hana::less) { 0075 return tag-dispatched; 0076 }; 0077 #else 0078 template <typename T, typename = void> 0079 struct lexicographical_compare_impl : lexicographical_compare_impl<T, when<true>> { }; 0080 0081 struct lexicographical_compare_t { 0082 template <typename Xs, typename Ys> 0083 constexpr auto operator()(Xs const& xs, Ys const& ys) const; 0084 0085 template <typename Xs, typename Ys, typename Pred> 0086 constexpr auto operator()(Xs const& xs, Ys const& ys, Pred const& pred) const; 0087 }; 0088 0089 BOOST_HANA_INLINE_VARIABLE constexpr lexicographical_compare_t lexicographical_compare{}; 0090 #endif 0091 }} // end namespace boost::hana 0092 0093 #endif // !BOOST_HANA_FWD_LEXICOGRAPHICAL_COMPARE_HPP
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|