Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-13 09:00:45

0001 // Copyright (c) 2016-2025 Antony Polukhin
0002 //
0003 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0004 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0005 
0006 #ifndef BOOST_PFR_FUNCTORS_HPP
0007 #define BOOST_PFR_FUNCTORS_HPP
0008 #pragma once
0009 
0010 #include <boost/pfr/detail/config.hpp>
0011 
0012 #include <boost/pfr/ops.hpp>
0013 
0014 #include <boost/pfr/detail/functional.hpp>
0015 
0016 /// \file boost/pfr/functors.hpp
0017 /// Contains functors that are close to the Standard Library ones.
0018 /// Each functor calls corresponding Boost.PFR function from boost/pfr/ops.hpp
0019 ///
0020 /// \b Example:
0021 /// \code
0022 ///     #include <boost/pfr/functors.hpp>
0023 ///     struct my_struct {      // No operators defined for that structure
0024 ///         int i; short s; char data[7]; bool bl; int a,b,c,d,e,f;
0025 ///     };
0026 ///     // ...
0027 ///
0028 ///     std::unordered_set<
0029 ///         my_struct,
0030 ///         boost::pfr::hash<>,
0031 ///         boost::pfr::equal_to<>
0032 ///     > my_set;
0033 /// \endcode
0034 ///
0035 /// \b Synopsis:
0036 namespace boost { namespace pfr {
0037 
0038 BOOST_PFR_BEGIN_MODULE_EXPORT
0039 
0040 ///////////////////// Comparisons
0041 
0042 /// \brief std::equal_to like comparator that returns \forcedlink{eq}(x, y)
0043 template <class T = void> struct equal_to {
0044     /// \return \b true if each field of \b x equals the field with same index of \b y.
0045     bool operator()(const T& x, const T& y) const {
0046         return boost::pfr::eq(x, y);
0047     }
0048 
0049 #ifdef BOOST_PFR_DOXYGEN_INVOKED
0050     /// This typedef exists only if T \b is void
0051     typedef std::true_type is_transparent;
0052 
0053     /// This operator allows comparison of \b x and \b y that have different type.
0054     /// \pre Exists only if T \b is void.
0055     template <class V, class U> bool operator()(const V& x, const U& y) const;
0056 #endif
0057 };
0058 
0059 /// @cond
0060 template <> struct equal_to<void> {
0061     template <class T, class U>
0062     bool operator()(const T& x, const U& y) const {
0063         return boost::pfr::eq(x, y);
0064     }
0065 
0066     typedef std::true_type is_transparent;
0067 };
0068 /// @endcond
0069 
0070 /// \brief std::not_equal like comparator that returns \forcedlink{ne}(x, y)
0071 template <class T = void> struct not_equal {
0072     /// \return \b true if at least one field \b x not equals the field with same index of \b y.
0073     bool operator()(const T& x, const T& y) const {
0074         return boost::pfr::ne(x, y);
0075     }
0076 
0077 #ifdef BOOST_PFR_DOXYGEN_INVOKED
0078     /// This typedef exists only if T \b is void
0079     typedef std::true_type is_transparent;
0080 
0081     /// This operator allows comparison of \b x and \b y that have different type.
0082     /// \pre Exists only if T \b is void.
0083     template <class V, class U> bool operator()(const V& x, const U& y) const;
0084 #endif
0085 };
0086 
0087 /// @cond
0088 template <> struct not_equal<void> {
0089     template <class T, class U>
0090     bool operator()(const T& x, const U& y) const {
0091         return boost::pfr::ne(x, y);
0092     }
0093 
0094     typedef std::true_type is_transparent;
0095 };
0096 /// @endcond
0097 
0098 /// \brief std::greater like comparator that returns \forcedlink{gt}(x, y)
0099 template <class T = void> struct greater {
0100     /// \return \b true if field of \b x greater than the field with same index of \b y and all previous fields of \b x equal to the same fields of \b y.
0101     bool operator()(const T& x, const T& y) const {
0102         return boost::pfr::gt(x, y);
0103     }
0104 
0105 #ifdef BOOST_PFR_DOXYGEN_INVOKED
0106     /// This typedef exists only if T \b is void
0107     typedef std::true_type is_transparent;
0108 
0109     /// This operator allows comparison of \b x and \b y that have different type.
0110     /// \pre Exists only if T \b is void.
0111     template <class V, class U> bool operator()(const V& x, const U& y) const;
0112 #endif
0113 };
0114 
0115 /// @cond
0116 template <> struct greater<void> {
0117     template <class T, class U>
0118     bool operator()(const T& x, const U& y) const {
0119         return boost::pfr::gt(x, y);
0120     }
0121 
0122     typedef std::true_type is_transparent;
0123 };
0124 /// @endcond
0125 
0126 /// \brief std::less like comparator that returns \forcedlink{lt}(x, y)
0127 template <class T = void> struct less {
0128     /// \return \b true if field of \b x less than the field with same index of \b y and all previous fields of \b x equal to the same fields of \b y.
0129     bool operator()(const T& x, const T& y) const {
0130         return boost::pfr::lt(x, y);
0131     }
0132 
0133 #ifdef BOOST_PFR_DOXYGEN_INVOKED
0134     /// This typedef exists only if T \b is void
0135     typedef std::true_type is_transparent;
0136 
0137     /// This operator allows comparison of \b x and \b y that have different type.
0138     /// \pre Exists only if T \b is void.
0139     template <class V, class U> bool operator()(const V& x, const U& y) const;
0140 #endif
0141 };
0142 
0143 /// @cond
0144 template <> struct less<void> {
0145     template <class T, class U>
0146     bool operator()(const T& x, const U& y) const {
0147         return boost::pfr::lt(x, y);
0148     }
0149 
0150     typedef std::true_type is_transparent;
0151 };
0152 /// @endcond
0153 
0154 /// \brief std::greater_equal like comparator that returns \forcedlink{ge}(x, y)
0155 template <class T = void> struct greater_equal {
0156     /// \return \b true if field of \b x greater than the field with same index of \b y and all previous fields of \b x equal to the same fields of \b y;
0157     /// or if each field of \b x equals the field with same index of \b y.
0158     bool operator()(const T& x, const T& y) const {
0159         return boost::pfr::ge(x, y);
0160     }
0161 
0162 #ifdef BOOST_PFR_DOXYGEN_INVOKED
0163     /// This typedef exists only if T \b is void
0164     typedef std::true_type is_transparent;
0165 
0166     /// This operator allows comparison of \b x and \b y that have different type.
0167     /// \pre Exists only if T \b is void.
0168     template <class V, class U> bool operator()(const V& x, const U& y) const;
0169 #endif
0170 };
0171 
0172 /// @cond
0173 template <> struct greater_equal<void> {
0174     template <class T, class U>
0175     bool operator()(const T& x, const U& y) const {
0176         return boost::pfr::ge(x, y);
0177     }
0178 
0179     typedef std::true_type is_transparent;
0180 };
0181 /// @endcond
0182 
0183 /// \brief std::less_equal like comparator that returns \forcedlink{le}(x, y)
0184 template <class T = void> struct less_equal {
0185     /// \return \b true if field of \b x less than the field with same index of \b y and all previous fields of \b x equal to the same fields of \b y;
0186     /// or if each field of \b x equals the field with same index of \b y.
0187     bool operator()(const T& x, const T& y) const {
0188         return boost::pfr::le(x, y);
0189     }
0190 
0191 #ifdef BOOST_PFR_DOXYGEN_INVOKED
0192     /// This typedef exists only if T \b is void
0193     typedef std::true_type is_transparent;
0194 
0195     /// This operator allows comparison of \b x and \b y that have different type.
0196     /// \pre Exists only if T \b is void.
0197     template <class V, class U> bool operator()(const V& x, const U& y) const;
0198 #endif
0199 };
0200 
0201 /// @cond
0202 template <> struct less_equal<void> {
0203     template <class T, class U>
0204     bool operator()(const T& x, const U& y) const {
0205         return boost::pfr::le(x, y);
0206     }
0207 
0208     typedef std::true_type is_transparent;
0209 };
0210 /// @endcond
0211 
0212 
0213 /// \brief std::hash like functor that returns \forcedlink{hash_value}(x)
0214 template <class T> struct hash {
0215     /// \return hash value of \b x.
0216     std::size_t operator()(const T& x) const {
0217         return boost::pfr::hash_value(x);
0218     }
0219 };
0220 
0221 BOOST_PFR_END_MODULE_EXPORT
0222 
0223 }} // namespace boost::pfr
0224 
0225 #endif // BOOST_PFR_FUNCTORS_HPP