|
|
|||
File indexing completed on 2025-12-15 09:53:05
0001 /*! 0002 @file 0003 Forward declares `boost::hana::sort`. 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_SORT_HPP 0011 #define BOOST_HANA_FWD_SORT_HPP 0012 0013 #include <boost/hana/config.hpp> 0014 #include <boost/hana/core/when.hpp> 0015 #include <boost/hana/detail/nested_by_fwd.hpp> 0016 0017 0018 namespace boost { namespace hana { 0019 //! Sort a sequence, optionally based on a custom `predicate`. 0020 //! @ingroup group-Sequence 0021 //! 0022 //! Given a Sequence and an optional predicate (by default `less`), `sort` 0023 //! returns a new sequence containing the same elements as the original, 0024 //! except they are ordered in such a way that if `x` comes before `y` in 0025 //! the sequence, then either `predicate(x, y)` is true, or both 0026 //! `predicate(x, y)` and `predicate(y, x)` are false. 0027 //! 0028 //! Also note that the sort is guaranteed to be stable. Hence, if `x` 0029 //! comes before `y` in the original sequence and both `predicate(x, y)` 0030 //! and `predicate(y, x)` are false, then `x` will come before `y` in the 0031 //! resulting sequence. 0032 //! 0033 //! If no predicate is provided, the elements in the sequence must all be 0034 //! compile-time `Orderable`. 0035 //! 0036 //! Signature 0037 //! --------- 0038 //! Given a `Sequence` `S(T)`, a boolean `IntegralConstant` `Bool` and a 0039 //! binary predicate \f$ T \times T \to Bool \f$, `sort` has the following 0040 //! signatures. For the variant with a provided predicate, 0041 //! \f[ 0042 //! \mathtt{sort} : S(T) \times (T \times T \to Bool) \to S(T) 0043 //! \f] 0044 //! 0045 //! for the variant without a custom predicate, `T` is required to be 0046 //! `Orderable`. The signature is then 0047 //! \f[ 0048 //! \mathtt{sort} : S(T) \to S(T) 0049 //! \f] 0050 //! 0051 //! @param xs 0052 //! The sequence to sort. 0053 //! 0054 //! @param predicate 0055 //! A function called as `predicate(x, y)` for two elements `x` and `y` of 0056 //! the sequence, and returning a boolean `IntegralConstant` representing 0057 //! whether `x` is to be considered _less_ than `y`, i.e. whether `x` should 0058 //! appear _before_ `y` in the resulting sequence. More specifically, 0059 //! `predicate` must define a [strict weak ordering][1] on the elements 0060 //! of the sequence. When the predicate is not specified, this defaults 0061 //! to `less`. In the current version of the library, the predicate has 0062 //! to return an `IntegralConstant` holding a value convertible to a `bool`. 0063 //! 0064 //! 0065 //! Syntactic sugar (`sort.by`) 0066 //! --------------------------- 0067 //! `sort` can be called in a third way, which provides a nice syntax 0068 //! especially when working with the `ordering` combinator: 0069 //! @code 0070 //! sort.by(predicate, xs) == sort(xs, predicate) 0071 //! sort.by(predicate) == sort(-, predicate) 0072 //! @endcode 0073 //! 0074 //! where `sort(-, predicate)` denotes the partial application of 0075 //! `sort` to `predicate`. 0076 //! 0077 //! 0078 //! Example 0079 //! ------- 0080 //! @include example/sort.cpp 0081 //! 0082 //! [1]: http://en.wikipedia.org/wiki/Strict_weak_ordering 0083 #ifdef BOOST_HANA_DOXYGEN_INVOKED 0084 constexpr auto sort = [](auto&& xs[, auto&& predicate]) { 0085 return tag-dispatched; 0086 }; 0087 #else 0088 template <typename S, typename = void> 0089 struct sort_impl : sort_impl<S, when<true>> { }; 0090 0091 struct sort_t : detail::nested_by<sort_t> { 0092 template <typename Xs> 0093 constexpr auto operator()(Xs&& xs) const; 0094 0095 template <typename Xs, typename Predicate> 0096 constexpr auto operator()(Xs&& xs, Predicate&& pred) const; 0097 }; 0098 0099 BOOST_HANA_INLINE_VARIABLE constexpr sort_t sort{}; 0100 #endif 0101 }} // end namespace boost::hana 0102 0103 #endif // !BOOST_HANA_FWD_SORT_HPP
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|