123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 |
- // Copyright (c) 2016-2024 Antony Polukhin
- //
- // Distributed under the Boost Software License, Version 1.0. (See accompanying
- // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
- #ifndef BOOST_PFR_FUNCTORS_HPP
- #define BOOST_PFR_FUNCTORS_HPP
- #pragma once
- #include <boost/pfr/detail/config.hpp>
- #include <boost/pfr/ops.hpp>
- #include <boost/pfr/detail/functional.hpp>
- /// \file boost/pfr/functors.hpp
- /// Contains functors that are close to the Standard Library ones.
- /// Each functor calls corresponding Boost.PFR function from boost/pfr/ops.hpp
- ///
- /// \b Example:
- /// \code
- /// #include <boost/pfr/functors.hpp>
- /// struct my_struct { // No operators defined for that structure
- /// int i; short s; char data[7]; bool bl; int a,b,c,d,e,f;
- /// };
- /// // ...
- ///
- /// std::unordered_set<
- /// my_struct,
- /// boost::pfr::hash<>,
- /// boost::pfr::equal_to<>
- /// > my_set;
- /// \endcode
- ///
- /// \b Synopsis:
- namespace boost { namespace pfr {
- ///////////////////// Comparisons
- /// \brief std::equal_to like comparator that returns \forcedlink{eq}(x, y)
- template <class T = void> struct equal_to {
- /// \return \b true if each field of \b x equals the field with same index of \b y.
- bool operator()(const T& x, const T& y) const {
- return boost::pfr::eq(x, y);
- }
- #ifdef BOOST_PFR_DOXYGEN_INVOKED
- /// This typedef exists only if T \b is void
- typedef std::true_type is_transparent;
- /// This operator allows comparison of \b x and \b y that have different type.
- /// \pre Exists only if T \b is void.
- template <class V, class U> bool operator()(const V& x, const U& y) const;
- #endif
- };
- /// @cond
- template <> struct equal_to<void> {
- template <class T, class U>
- bool operator()(const T& x, const U& y) const {
- return boost::pfr::eq(x, y);
- }
- typedef std::true_type is_transparent;
- };
- /// @endcond
- /// \brief std::not_equal like comparator that returns \forcedlink{ne}(x, y)
- template <class T = void> struct not_equal {
- /// \return \b true if at least one field \b x not equals the field with same index of \b y.
- bool operator()(const T& x, const T& y) const {
- return boost::pfr::ne(x, y);
- }
- #ifdef BOOST_PFR_DOXYGEN_INVOKED
- /// This typedef exists only if T \b is void
- typedef std::true_type is_transparent;
- /// This operator allows comparison of \b x and \b y that have different type.
- /// \pre Exists only if T \b is void.
- template <class V, class U> bool operator()(const V& x, const U& y) const;
- #endif
- };
- /// @cond
- template <> struct not_equal<void> {
- template <class T, class U>
- bool operator()(const T& x, const U& y) const {
- return boost::pfr::ne(x, y);
- }
- typedef std::true_type is_transparent;
- };
- /// @endcond
- /// \brief std::greater like comparator that returns \forcedlink{gt}(x, y)
- template <class T = void> struct greater {
- /// \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.
- bool operator()(const T& x, const T& y) const {
- return boost::pfr::gt(x, y);
- }
- #ifdef BOOST_PFR_DOXYGEN_INVOKED
- /// This typedef exists only if T \b is void
- typedef std::true_type is_transparent;
- /// This operator allows comparison of \b x and \b y that have different type.
- /// \pre Exists only if T \b is void.
- template <class V, class U> bool operator()(const V& x, const U& y) const;
- #endif
- };
- /// @cond
- template <> struct greater<void> {
- template <class T, class U>
- bool operator()(const T& x, const U& y) const {
- return boost::pfr::gt(x, y);
- }
- typedef std::true_type is_transparent;
- };
- /// @endcond
- /// \brief std::less like comparator that returns \forcedlink{lt}(x, y)
- template <class T = void> struct less {
- /// \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.
- bool operator()(const T& x, const T& y) const {
- return boost::pfr::lt(x, y);
- }
- #ifdef BOOST_PFR_DOXYGEN_INVOKED
- /// This typedef exists only if T \b is void
- typedef std::true_type is_transparent;
- /// This operator allows comparison of \b x and \b y that have different type.
- /// \pre Exists only if T \b is void.
- template <class V, class U> bool operator()(const V& x, const U& y) const;
- #endif
- };
- /// @cond
- template <> struct less<void> {
- template <class T, class U>
- bool operator()(const T& x, const U& y) const {
- return boost::pfr::lt(x, y);
- }
- typedef std::true_type is_transparent;
- };
- /// @endcond
- /// \brief std::greater_equal like comparator that returns \forcedlink{ge}(x, y)
- template <class T = void> struct greater_equal {
- /// \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;
- /// or if each field of \b x equals the field with same index of \b y.
- bool operator()(const T& x, const T& y) const {
- return boost::pfr::ge(x, y);
- }
- #ifdef BOOST_PFR_DOXYGEN_INVOKED
- /// This typedef exists only if T \b is void
- typedef std::true_type is_transparent;
- /// This operator allows comparison of \b x and \b y that have different type.
- /// \pre Exists only if T \b is void.
- template <class V, class U> bool operator()(const V& x, const U& y) const;
- #endif
- };
- /// @cond
- template <> struct greater_equal<void> {
- template <class T, class U>
- bool operator()(const T& x, const U& y) const {
- return boost::pfr::ge(x, y);
- }
- typedef std::true_type is_transparent;
- };
- /// @endcond
- /// \brief std::less_equal like comparator that returns \forcedlink{le}(x, y)
- template <class T = void> struct less_equal {
- /// \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;
- /// or if each field of \b x equals the field with same index of \b y.
- bool operator()(const T& x, const T& y) const {
- return boost::pfr::le(x, y);
- }
- #ifdef BOOST_PFR_DOXYGEN_INVOKED
- /// This typedef exists only if T \b is void
- typedef std::true_type is_transparent;
- /// This operator allows comparison of \b x and \b y that have different type.
- /// \pre Exists only if T \b is void.
- template <class V, class U> bool operator()(const V& x, const U& y) const;
- #endif
- };
- /// @cond
- template <> struct less_equal<void> {
- template <class T, class U>
- bool operator()(const T& x, const U& y) const {
- return boost::pfr::le(x, y);
- }
- typedef std::true_type is_transparent;
- };
- /// @endcond
- /// \brief std::hash like functor that returns \forcedlink{hash_value}(x)
- template <class T> struct hash {
- /// \return hash value of \b x.
- std::size_t operator()(const T& x) const {
- return boost::pfr::hash_value(x);
- }
- };
- }} // namespace boost::pfr
- #endif // BOOST_PFR_FUNCTORS_HPP
|