summaryrefslogtreecommitdiff log msg author committer range
path: root/boost/hana/fwd/group.hpp
blob: 75fb68c832a4151263a683e48f59684359fd59bf (plain)
 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103  /*! @file Forward declares boost::hana::group. @copyright Louis Dionne 2013-2016 Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) */ #ifndef BOOST_HANA_FWD_GROUP_HPP #define BOOST_HANA_FWD_GROUP_HPP #include #include #include BOOST_HANA_NAMESPACE_BEGIN //! Group adjacent elements of a sequence that all respect a binary //! predicate, by default equality. //! @ingroup group-Sequence //! //! Given a _finite_ Sequence and an optional predicate (by default //! equal), group returns a sequence of subsequences representing //! groups of adjacent elements that are "equal" with respect to the //! predicate. In other words, the groups are such that the predicate is //! satisfied when it is applied to any two adjacent elements in that //! group. The sequence returned by group is such that the concatenation //! of its elements is equal to the original sequence, which is equivalent //! to saying that the order of the elements is not changed. //! //! If no predicate is provided, adjacent elements in the sequence must //! all be compile-time Comparable. //! //! //! Signature //! --------- //! Given a Sequence s with tag S(T), an IntegralConstant Bool //! holding a value of type bool, and a predicate //! \f$pred : T \times T \to Bool \f$, group has the following //! signatures. For the variant with a provided predicate, //! \f[ //! \mathtt{group} : S(T) \times (T \times T \to Bool) \to S(S(T)) //! \f] //! //! for the variant without a custom predicate, T is required to be //! Comparable. The signature is then //! \f[ //! \mathtt{group} : S(T) \to S(S(T)) //! \f] //! //! @param xs //! The sequence to split into groups. //! //! @param predicate //! A binary function called as predicate(x, y), where x and y are //! _adjacent_ elements in the sequence, whether both elements should be //! in the same group (subsequence) of the result. In the current version //! of the library, the result returned by predicate must be an //! IntegralConstant holding a value of a type convertible to bool. //! Also, predicate has to define an equivalence relation as defined by //! the Comparable concept. When this predicate is not provided, it //! defaults to equal, which requires the comparison of any two adjacent //! elements in the sequence to return a boolean IntegralConstant. //! //! //! Syntactic sugar (group.by) //! ---------------------------- //! group can be called in a third way, which provides a nice syntax //! especially when working with the comparing combinator: //! @code //! group.by(predicate, xs) == group(xs, predicate) //! group.by(predicate) == group(-, predicate) //! @endcode //! //! where group(-, predicate) denotes the partial application of //! group to predicate. //! //! //! Example //! ------- //! @include example/group.cpp #ifdef BOOST_HANA_DOXYGEN_INVOKED constexpr auto group = [](auto&& xs[, auto&& predicate]) { return tag-dispatched; }; #else template struct group_impl : group_impl> { }; struct group_t : detail::nested_by { template constexpr auto operator()(Xs&& xs) const; template constexpr auto operator()(Xs&& xs, Predicate&& pred) const; }; constexpr group_t group{}; #endif BOOST_HANA_NAMESPACE_END #endif // !BOOST_HANA_FWD_GROUP_HPP