Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:43:38

0001 // Copyright (c) 2016-2023 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 ///////////////////// Comparisons
0039 
0040 /// \brief std::equal_to like comparator that returns \forcedlink{eq}(x, y)
0041 template <class T = void> struct equal_to {
0042     /// \return \b true if each field of \b x equals the field with same index of \b y.
0043     bool operator()(const T& x, const T& y) const {
0044         return boost::pfr::eq(x, y);
0045     }
0046 
0047 #ifdef BOOST_PFR_DOXYGEN_INVOKED
0048     /// This typedef exists only if T \b is void
0049     typedef std::true_type is_transparent;
0050 
0051     /// This operator allows comparison of \b x and \b y that have different type.
0052     /// \pre Exists only if T \b is void.
0053     template <class V, class U> bool operator()(const V& x, const U& y) const;
0054 #endif
0055 };
0056 
0057 /// @cond
0058 template <> struct equal_to<void> {
0059     template <class T, class U>
0060     bool operator()(const T& x, const U& y) const {
0061         return boost::pfr::eq(x, y);
0062     }
0063 
0064     typedef std::true_type is_transparent;
0065 };
0066 /// @endcond
0067 
0068 /// \brief std::not_equal like comparator that returns \forcedlink{ne}(x, y)
0069 template <class T = void> struct not_equal {
0070     /// \return \b true if at least one field \b x not equals the field with same index of \b y.
0071     bool operator()(const T& x, const T& y) const {
0072         return boost::pfr::ne(x, y);
0073     }
0074 
0075 #ifdef BOOST_PFR_DOXYGEN_INVOKED
0076     /// This typedef exists only if T \b is void
0077     typedef std::true_type is_transparent;
0078 
0079     /// This operator allows comparison of \b x and \b y that have different type.
0080     /// \pre Exists only if T \b is void.
0081     template <class V, class U> bool operator()(const V& x, const U& y) const;
0082 #endif
0083 };
0084 
0085 /// @cond
0086 template <> struct not_equal<void> {
0087     template <class T, class U>
0088     bool operator()(const T& x, const U& y) const {
0089         return boost::pfr::ne(x, y);
0090     }
0091 
0092     typedef std::true_type is_transparent;
0093 };
0094 /// @endcond
0095 
0096 /// \brief std::greater like comparator that returns \forcedlink{gt}(x, y)
0097 template <class T = void> struct greater {
0098     /// \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.
0099     bool operator()(const T& x, const T& y) const {
0100         return boost::pfr::gt(x, y);
0101     }
0102 
0103 #ifdef BOOST_PFR_DOXYGEN_INVOKED
0104     /// This typedef exists only if T \b is void
0105     typedef std::true_type is_transparent;
0106 
0107     /// This operator allows comparison of \b x and \b y that have different type.
0108     /// \pre Exists only if T \b is void.
0109     template <class V, class U> bool operator()(const V& x, const U& y) const;
0110 #endif
0111 };
0112 
0113 /// @cond
0114 template <> struct greater<void> {
0115     template <class T, class U>
0116     bool operator()(const T& x, const U& y) const {
0117         return boost::pfr::gt(x, y);
0118     }
0119 
0120     typedef std::true_type is_transparent;
0121 };
0122 /// @endcond
0123 
0124 /// \brief std::less like comparator that returns \forcedlink{lt}(x, y)
0125 template <class T = void> struct less {
0126     /// \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.
0127     bool operator()(const T& x, const T& y) const {
0128         return boost::pfr::lt(x, y);
0129     }
0130 
0131 #ifdef BOOST_PFR_DOXYGEN_INVOKED
0132     /// This typedef exists only if T \b is void
0133     typedef std::true_type is_transparent;
0134 
0135     /// This operator allows comparison of \b x and \b y that have different type.
0136     /// \pre Exists only if T \b is void.
0137     template <class V, class U> bool operator()(const V& x, const U& y) const;
0138 #endif
0139 };
0140 
0141 /// @cond
0142 template <> struct less<void> {
0143     template <class T, class U>
0144     bool operator()(const T& x, const U& y) const {
0145         return boost::pfr::lt(x, y);
0146     }
0147 
0148     typedef std::true_type is_transparent;
0149 };
0150 /// @endcond
0151 
0152 /// \brief std::greater_equal like comparator that returns \forcedlink{ge}(x, y)
0153 template <class T = void> struct greater_equal {
0154     /// \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;
0155     /// or if each field of \b x equals the field with same index of \b y.
0156     bool operator()(const T& x, const T& y) const {
0157         return boost::pfr::ge(x, y);
0158     }
0159 
0160 #ifdef BOOST_PFR_DOXYGEN_INVOKED
0161     /// This typedef exists only if T \b is void
0162     typedef std::true_type is_transparent;
0163 
0164     /// This operator allows comparison of \b x and \b y that have different type.
0165     /// \pre Exists only if T \b is void.
0166     template <class V, class U> bool operator()(const V& x, const U& y) const;
0167 #endif
0168 };
0169 
0170 /// @cond
0171 template <> struct greater_equal<void> {
0172     template <class T, class U>
0173     bool operator()(const T& x, const U& y) const {
0174         return boost::pfr::ge(x, y);
0175     }
0176 
0177     typedef std::true_type is_transparent;
0178 };
0179 /// @endcond
0180 
0181 /// \brief std::less_equal like comparator that returns \forcedlink{le}(x, y)
0182 template <class T = void> struct less_equal {
0183     /// \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;
0184     /// or if each field of \b x equals the field with same index of \b y.
0185     bool operator()(const T& x, const T& y) const {
0186         return boost::pfr::le(x, y);
0187     }
0188 
0189 #ifdef BOOST_PFR_DOXYGEN_INVOKED
0190     /// This typedef exists only if T \b is void
0191     typedef std::true_type is_transparent;
0192 
0193     /// This operator allows comparison of \b x and \b y that have different type.
0194     /// \pre Exists only if T \b is void.
0195     template <class V, class U> bool operator()(const V& x, const U& y) const;
0196 #endif
0197 };
0198 
0199 /// @cond
0200 template <> struct less_equal<void> {
0201     template <class T, class U>
0202     bool operator()(const T& x, const U& y) const {
0203         return boost::pfr::le(x, y);
0204     }
0205 
0206     typedef std::true_type is_transparent;
0207 };
0208 /// @endcond
0209 
0210 
0211 /// \brief std::hash like functor that returns \forcedlink{hash_value}(x)
0212 template <class T> struct hash {
0213     /// \return hash value of \b x.
0214     std::size_t operator()(const T& x) const {
0215         return boost::pfr::hash_value(x);
0216     }
0217 };
0218 
0219 }} // namespace boost::pfr
0220 
0221 #endif // BOOST_PFR_FUNCTORS_HPP