]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/hana/include/boost/hana/fwd/unique.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / hana / include / boost / hana / fwd / unique.hpp
1 /*!
2 @file
3 Forward declares `boost::hana::unique`.
4
5 @copyright Louis Dionne 2013-2016
6 Distributed under the Boost Software License, Version 1.0.
7 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
8 */
9
10 #ifndef BOOST_HANA_FWD_UNIQUE_HPP
11 #define BOOST_HANA_FWD_UNIQUE_HPP
12
13 #include <boost/hana/config.hpp>
14 #include <boost/hana/core/when.hpp>
15 #include <boost/hana/detail/nested_by_fwd.hpp>
16
17
18 BOOST_HANA_NAMESPACE_BEGIN
19 //! Removes all consecutive duplicate elements from a Sequence.
20 //! @ingroup group-Sequence
21 //!
22 //! Given a `Sequence` and an optional binary predicate, `unique` returns
23 //! a new sequence containing only the first element of every subrange
24 //! of the original sequence whose elements are all equal. In other words,
25 //! it turns a sequence of the form `[a, a, b, c, c, c, d, d, d, a]` into
26 //! a sequence `[a, b, c, d, a]`. The equality of two elements is
27 //! determined by the provided `predicate`, or by `equal` if no
28 //! `predicate` is provided.
29 //!
30 //!
31 //! Signature
32 //! ---------
33 //! Given a `Sequence` `S(T)`, a `Logical` `Bool` and a binary predicate
34 //! \f$ T \times T \to Bool \f$, `unique` has the following signature:
35 //! \f[
36 //! \mathtt{unique} : S(T) \times (T \times T \to Bool) \to S(T)
37 //! \f]
38 //!
39 //! @param xs
40 //! The sequence from which to remove consecutive duplicates.
41 //!
42 //! @param predicate
43 //! A function called as `predicate(x, y)`, where `x` and `y` are adjacent
44 //! elements of the sequence, and returning a `Logical` representing
45 //! whether `x` and `y` should be considered equal. `predicate` should
46 //! define an [equivalence relation][1] over the elements of the sequence.
47 //! In the current implementation of the library, `predicate` has to
48 //! return a compile-time `Logical`. This parameter is optional; it
49 //! defaults to `equal` if it is not provided, which then requires the
50 //! elements of the sequence to be compile-time `Comparable`.
51 //!
52 //!
53 //! Syntactic sugar (`unique.by`)
54 //! -----------------------------
55 //! `unique` can be called in an alternate way, which provides a nice
56 //! syntax, especially in conjunction with the `comparing` combinator:
57 //! @code
58 //! unique.by(predicate, xs) == unique(xs, predicate)
59 //! unique.by(predicate) == unique(-, predicate)
60 //! @endcode
61 //!
62 //! where `unique(-, predicate)` denotes the partial application of
63 //! `unique` to `predicate`.
64 //!
65 //!
66 //! Example
67 //! -------
68 //! @include example/unique.cpp
69 //!
70 //! [1]: http://en.wikipedia.org/wiki/Equivalence_relation#Definition
71 #if defined(BOOST_HANA_DOXYGEN_INVOKED)
72 constexpr auto unique = [](auto&& xs[, auto&& predicate]) {
73 return tag-dispatched;
74 };
75 #else
76 template <typename S, typename = void>
77 struct unique_impl : unique_impl<S, when<true>> { };
78
79 struct unique_t : detail::nested_by<unique_t> {
80 template <typename Xs>
81 constexpr auto operator()(Xs&& xs) const;
82
83 template <typename Xs, typename Predicate>
84 constexpr auto operator()(Xs&& xs, Predicate&& predicate) const;
85 };
86
87 constexpr unique_t unique{};
88 #endif
89 BOOST_HANA_NAMESPACE_END
90
91 #endif // !BOOST_HANA_FWD_UNIQUE_HPP