File indexing completed on 2025-01-30 09:43:40
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_HANA_UNIQUE_HPP
0011 #define BOOST_HANA_UNIQUE_HPP
0012
0013 #include <boost/hana/fwd/unique.hpp>
0014
0015 #include <boost/hana/concept/sequence.hpp>
0016 #include <boost/hana/config.hpp>
0017 #include <boost/hana/core/dispatch.hpp>
0018 #include <boost/hana/detail/nested_by.hpp> // required by fwd decl
0019 #include <boost/hana/equal.hpp>
0020 #include <boost/hana/front.hpp>
0021 #include <boost/hana/group.hpp>
0022 #include <boost/hana/transform.hpp>
0023
0024
0025 namespace boost { namespace hana {
0026
0027 template <typename Xs>
0028 constexpr auto unique_t::operator()(Xs&& xs) const {
0029 using S = typename hana::tag_of<Xs>::type;
0030 using Unique = BOOST_HANA_DISPATCH_IF(unique_impl<S>,
0031 hana::Sequence<S>::value
0032 );
0033
0034 #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
0035 static_assert(hana::Sequence<S>::value,
0036 "hana::unique(xs) requires 'xs' to be a Sequence");
0037 #endif
0038
0039 return Unique::apply(static_cast<Xs&&>(xs));
0040 }
0041
0042 template <typename Xs, typename Predicate>
0043 constexpr auto unique_t::operator()(Xs&& xs, Predicate&& predicate) const {
0044 using S = typename hana::tag_of<Xs>::type;
0045 using Unique = BOOST_HANA_DISPATCH_IF(unique_impl<S>,
0046 hana::Sequence<S>::value
0047 );
0048
0049 #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
0050 static_assert(hana::Sequence<S>::value,
0051 "hana::unique(xs, predicate) requires 'xs' to be a Sequence");
0052 #endif
0053
0054 return Unique::apply(static_cast<Xs&&>(xs),
0055 static_cast<Predicate&&>(predicate));
0056 }
0057
0058
0059 template <typename S, bool condition>
0060 struct unique_impl<S, when<condition>> : default_ {
0061 template <typename Xs, typename Pred>
0062 static constexpr auto apply(Xs&& xs, Pred&& pred) {
0063 return hana::transform(
0064 hana::group(static_cast<Xs&&>(xs), static_cast<Pred&&>(pred)),
0065 hana::front
0066 );
0067 }
0068
0069 template <typename Xs>
0070 static constexpr auto apply(Xs&& xs)
0071 { return unique_impl::apply(static_cast<Xs&&>(xs), hana::equal); }
0072 };
0073 }}
0074
0075 #endif