|
|
|||
File indexing completed on 2025-12-15 09:53:05
0001 /*! 0002 @file 0003 Forward declares `boost::hana::unique`. 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_UNIQUE_HPP 0011 #define BOOST_HANA_FWD_UNIQUE_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 //! Removes all consecutive duplicate elements from a Sequence. 0020 //! @ingroup group-Sequence 0021 //! 0022 //! Given a `Sequence` and an optional binary predicate, `unique` returns 0023 //! a new sequence containing only the first element of every subrange 0024 //! of the original sequence whose elements are all equal. In other words, 0025 //! it turns a sequence of the form `[a, a, b, c, c, c, d, d, d, a]` into 0026 //! a sequence `[a, b, c, d, a]`. The equality of two elements is 0027 //! determined by the provided `predicate`, or by `equal` if no 0028 //! `predicate` is provided. 0029 //! 0030 //! 0031 //! Signature 0032 //! --------- 0033 //! Given a `Sequence` `S(T)`, a `Logical` `Bool` and a binary predicate 0034 //! \f$ T \times T \to Bool \f$, `unique` has the following signature: 0035 //! \f[ 0036 //! \mathtt{unique} : S(T) \times (T \times T \to Bool) \to S(T) 0037 //! \f] 0038 //! 0039 //! @param xs 0040 //! The sequence from which to remove consecutive duplicates. 0041 //! 0042 //! @param predicate 0043 //! A function called as `predicate(x, y)`, where `x` and `y` are adjacent 0044 //! elements of the sequence, and returning a `Logical` representing 0045 //! whether `x` and `y` should be considered equal. `predicate` should 0046 //! define an [equivalence relation][1] over the elements of the sequence. 0047 //! In the current implementation of the library, `predicate` has to 0048 //! return a compile-time `Logical`. This parameter is optional; it 0049 //! defaults to `equal` if it is not provided, which then requires the 0050 //! elements of the sequence to be compile-time `Comparable`. 0051 //! 0052 //! 0053 //! Syntactic sugar (`unique.by`) 0054 //! ----------------------------- 0055 //! `unique` can be called in an alternate way, which provides a nice 0056 //! syntax, especially in conjunction with the `comparing` combinator: 0057 //! @code 0058 //! unique.by(predicate, xs) == unique(xs, predicate) 0059 //! unique.by(predicate) == unique(-, predicate) 0060 //! @endcode 0061 //! 0062 //! where `unique(-, predicate)` denotes the partial application of 0063 //! `unique` to `predicate`. 0064 //! 0065 //! 0066 //! Example 0067 //! ------- 0068 //! @include example/unique.cpp 0069 //! 0070 //! [1]: http://en.wikipedia.org/wiki/Equivalence_relation#Definition 0071 #if defined(BOOST_HANA_DOXYGEN_INVOKED) 0072 constexpr auto unique = [](auto&& xs[, auto&& predicate]) { 0073 return tag-dispatched; 0074 }; 0075 #else 0076 template <typename S, typename = void> 0077 struct unique_impl : unique_impl<S, when<true>> { }; 0078 0079 struct unique_t : detail::nested_by<unique_t> { 0080 template <typename Xs> 0081 constexpr auto operator()(Xs&& xs) const; 0082 0083 template <typename Xs, typename Predicate> 0084 constexpr auto operator()(Xs&& xs, Predicate&& predicate) const; 0085 }; 0086 0087 BOOST_HANA_INLINE_VARIABLE constexpr unique_t unique{}; 0088 #endif 0089 }} // end namespace boost::hana 0090 0091 #endif // !BOOST_HANA_FWD_UNIQUE_HPP
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|