|
|
|||
File indexing completed on 2025-12-15 09:53:04
0001 /*! 0002 @file 0003 Forward declares `boost::hana::group`. 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_GROUP_HPP 0011 #define BOOST_HANA_FWD_GROUP_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 //! Group adjacent elements of a sequence that all respect a binary 0020 //! predicate, by default equality. 0021 //! @ingroup group-Sequence 0022 //! 0023 //! Given a _finite_ Sequence and an optional predicate (by default 0024 //! `equal`), `group` returns a sequence of subsequences representing 0025 //! groups of adjacent elements that are "equal" with respect to the 0026 //! predicate. In other words, the groups are such that the predicate is 0027 //! satisfied when it is applied to any two adjacent elements in that 0028 //! group. The sequence returned by `group` is such that the concatenation 0029 //! of its elements is equal to the original sequence, which is equivalent 0030 //! to saying that the order of the elements is not changed. 0031 //! 0032 //! If no predicate is provided, adjacent elements in the sequence must 0033 //! all be compile-time `Comparable`. 0034 //! 0035 //! 0036 //! Signature 0037 //! --------- 0038 //! Given a Sequence `s` with tag `S(T)`, an `IntegralConstant` `Bool` 0039 //! holding a value of type `bool`, and a predicate 0040 //! \f$ pred : T \times T \to Bool \f$, `group` has the following 0041 //! signatures. For the variant with a provided predicate, 0042 //! \f[ 0043 //! \mathtt{group} : S(T) \times (T \times T \to Bool) \to S(S(T)) 0044 //! \f] 0045 //! 0046 //! for the variant without a custom predicate, `T` is required to be 0047 //! Comparable. The signature is then 0048 //! \f[ 0049 //! \mathtt{group} : S(T) \to S(S(T)) 0050 //! \f] 0051 //! 0052 //! @param xs 0053 //! The sequence to split into groups. 0054 //! 0055 //! @param predicate 0056 //! A binary function called as `predicate(x, y)`, where `x` and `y` are 0057 //! _adjacent_ elements in the sequence, whether both elements should be 0058 //! in the same group (subsequence) of the result. In the current version 0059 //! of the library, the result returned by `predicate` must be an 0060 //! `IntegralConstant` holding a value of a type convertible to `bool`. 0061 //! Also, `predicate` has to define an equivalence relation as defined by 0062 //! the `Comparable` concept. When this predicate is not provided, it 0063 //! defaults to `equal`, which requires the comparison of any two adjacent 0064 //! elements in the sequence to return a boolean `IntegralConstant`. 0065 //! 0066 //! 0067 //! Syntactic sugar (`group.by`) 0068 //! ---------------------------- 0069 //! `group` can be called in a third way, which provides a nice syntax 0070 //! especially when working with the `comparing` combinator: 0071 //! @code 0072 //! group.by(predicate, xs) == group(xs, predicate) 0073 //! group.by(predicate) == group(-, predicate) 0074 //! @endcode 0075 //! 0076 //! where `group(-, predicate)` denotes the partial application of 0077 //! `group` to `predicate`. 0078 //! 0079 //! 0080 //! Example 0081 //! ------- 0082 //! @include example/group.cpp 0083 #ifdef BOOST_HANA_DOXYGEN_INVOKED 0084 constexpr auto group = [](auto&& xs[, auto&& predicate]) { 0085 return tag-dispatched; 0086 }; 0087 #else 0088 template <typename S, typename = void> 0089 struct group_impl : group_impl<S, when<true>> { }; 0090 0091 struct group_t : detail::nested_by<group_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 group_t group{}; 0100 #endif 0101 }} // end namespace boost::hana 0102 0103 #endif // !BOOST_HANA_FWD_GROUP_HPP
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|