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_FUNCTIONS_FOR_HPP
0007 #define BOOST_PFR_FUNCTIONS_FOR_HPP
0008 #pragma once
0009 
0010 #include <boost/pfr/detail/config.hpp>
0011 
0012 #include <boost/pfr/ops_fields.hpp>
0013 #include <boost/pfr/io_fields.hpp>
0014 
0015 /// \file boost/pfr/functions_for.hpp
0016 /// Contains BOOST_PFR_FUNCTIONS_FOR macro that defined comparison and stream operators for T along with hash_value function.
0017 /// \b Example:
0018 /// \code
0019 ///     #include <boost/pfr/functions_for.hpp>
0020 ///
0021 ///     namespace my_namespace {
0022 ///         struct my_struct {      // No operators defined for that structure
0023 ///             int i; short s; char data[7]; bool bl; int a,b,c,d,e,f;
0024 ///         };
0025 ///         BOOST_PFR_FUNCTIONS_FOR(my_struct)
0026 ///     }
0027 /// \endcode
0028 ///
0029 /// \podops for other ways to define operators and more details.
0030 ///
0031 /// \b Synopsis:
0032 
0033 /// \def BOOST_PFR_FUNCTIONS_FOR(T)
0034 /// Defines comparison and stream operators for T along with hash_value function.
0035 ///
0036 /// \b Example:
0037 /// \code
0038 ///     #include <boost/pfr/functions_for.hpp>
0039 ///     struct comparable_struct {      // No operators defined for that structure
0040 ///         int i; short s; char data[7]; bool bl; int a,b,c,d,e,f;
0041 ///     };
0042 ///     BOOST_PFR_FUNCTIONS_FOR(comparable_struct)
0043 ///     // ...
0044 ///
0045 ///     comparable_struct s1 {0, 1, "Hello", false, 6,7,8,9,10,11};
0046 ///     comparable_struct s2 {0, 1, "Hello", false, 6,7,8,9,10,11111};
0047 ///     assert(s1 < s2);
0048 ///     std::cout << s1 << std::endl; // Outputs: {0, 1, H, e, l, l, o, , , 0, 6, 7, 8, 9, 10, 11}
0049 /// \endcode
0050 ///
0051 /// \podops for other ways to define operators and more details.
0052 ///
0053 /// \b Defines \b following \b for \b T:
0054 /// \code
0055 /// bool operator==(const T& lhs, const T& rhs);
0056 /// bool operator!=(const T& lhs, const T& rhs);
0057 /// bool operator< (const T& lhs, const T& rhs);
0058 /// bool operator> (const T& lhs, const T& rhs);
0059 /// bool operator<=(const T& lhs, const T& rhs);
0060 /// bool operator>=(const T& lhs, const T& rhs);
0061 ///
0062 /// template <class Char, class Traits>
0063 /// std::basic_ostream<Char, Traits>& operator<<(std::basic_ostream<Char, Traits>& out, const T& value);
0064 ///
0065 /// template <class Char, class Traits>
0066 /// std::basic_istream<Char, Traits>& operator>>(std::basic_istream<Char, Traits>& in, T& value);
0067 ///
0068 /// // helper function for Boost unordered containers and boost::hash<>.
0069 /// std::size_t hash_value(const T& value);
0070 /// \endcode
0071 
0072 #define BOOST_PFR_FUNCTIONS_FOR(T)                                                                                                          \
0073     BOOST_PFR_MAYBE_UNUSED inline bool operator==(const T& lhs, const T& rhs) { return ::boost::pfr::eq_fields(lhs, rhs); }                 \
0074     BOOST_PFR_MAYBE_UNUSED inline bool operator!=(const T& lhs, const T& rhs) { return ::boost::pfr::ne_fields(lhs, rhs); }                 \
0075     BOOST_PFR_MAYBE_UNUSED inline bool operator< (const T& lhs, const T& rhs) { return ::boost::pfr::lt_fields(lhs, rhs); }                 \
0076     BOOST_PFR_MAYBE_UNUSED inline bool operator> (const T& lhs, const T& rhs) { return ::boost::pfr::gt_fields(lhs, rhs); }                 \
0077     BOOST_PFR_MAYBE_UNUSED inline bool operator<=(const T& lhs, const T& rhs) { return ::boost::pfr::le_fields(lhs, rhs); }                 \
0078     BOOST_PFR_MAYBE_UNUSED inline bool operator>=(const T& lhs, const T& rhs) { return ::boost::pfr::ge_fields(lhs, rhs); }                 \
0079     template <class Char, class Traits>                                                                                                     \
0080     BOOST_PFR_MAYBE_UNUSED inline ::std::basic_ostream<Char, Traits>& operator<<(::std::basic_ostream<Char, Traits>& out, const T& value) { \
0081         return out << ::boost::pfr::io_fields(value);                                                                                       \
0082     }                                                                                                                                       \
0083     template <class Char, class Traits>                                                                                                     \
0084     BOOST_PFR_MAYBE_UNUSED inline ::std::basic_istream<Char, Traits>& operator>>(::std::basic_istream<Char, Traits>& in, T& value) {        \
0085         return in >> ::boost::pfr::io_fields(value);                                                                                        \
0086     }                                                                                                                                       \
0087     BOOST_PFR_MAYBE_UNUSED inline std::size_t hash_value(const T& v) {                                                                      \
0088         return ::boost::pfr::hash_fields(v);                                                                                                \
0089     }                                                                                                                                       \
0090 /**/
0091 
0092 #endif // BOOST_PFR_FUNCTIONS_FOR_HPP
0093