Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:42:22

0001 ///////////////////////////////////////////////////////////////////////////////
0002 //  Copyright 2016 John Maddock. Distributed under the Boost
0003 //  Software License, Version 1.0. (See accompanying file
0004 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0005 
0006 #ifndef BOOST_MP_MIN_MAX_HPP
0007 #define BOOST_MP_MIN_MAX_HPP
0008 
0009 #include <boost/multiprecision/traits/is_backend.hpp>
0010 
0011 namespace boost { namespace multiprecision {
0012 
0013 //
0014 // Expression template overloads for (min) and (max):
0015 //
0016 // Introduced in response to https://svn.boost.org/trac/boost/ticket/11149
0017 // note that these can not legally be injected into namespace std, and that doing so
0018 // may break future enhancements to the standard.  None the less adding
0019 // namespace std{ using boost::multiprecision::(min); using boost::multiprecision::(max); }
0020 // to your code may get some generic code working that wouldn't work otherwise.
0021 //
0022 // The use of enable_if on the return type is to avoid poisoning std::min/max,
0023 // otherwise attempting to make an explicit call to min<long>(a, b) when these and std
0024 // versions are in scope, will cause the compiler to try to instantiate the signatures
0025 // for our versions as well as the std ones, which in turn instantiates number<long>
0026 // which fails to compile as "long" is not a valid backend type.
0027 //
0028 template <class Backend>
0029 inline typename std::enable_if<boost::multiprecision::detail::is_backend<Backend>::value, const number<Backend, et_on>&>::type(min)(const number<Backend, et_on>& a, const number<Backend, et_on>& b)
0030 {
0031    return a < b ? a : b;
0032 }
0033 template <class Backend, class tag, class A1, class A2, class A3, class A4>
0034 inline typename std::enable_if<boost::multiprecision::detail::is_backend<Backend>::value, const number<Backend, et_on> >::type(min)(const number<Backend, et_on>& a, const detail::expression<tag, A1, A2, A3, A4>& b)
0035 {
0036    number<Backend, et_on> t(b);
0037    if (a < t)
0038       return a;
0039    return std::move(t);
0040 }
0041 template <class tag, class A1, class A2, class A3, class A4, class Backend>
0042 inline typename std::enable_if<boost::multiprecision::detail::is_backend<Backend>::value, const number<Backend, et_on> >::type(min)(const detail::expression<tag, A1, A2, A3, A4>& a, const number<Backend, et_on>& b)
0043 {
0044    number<Backend, et_on> t(a);
0045    if (t < b)
0046       return std::move(t);
0047    return b;
0048 }
0049 template <class tag, class A1, class A2, class A3, class A4, class tagb, class A1b, class A2b, class A3b, class A4b>
0050 inline typename detail::expression<tag, A1, A2, A3, A4>::result_type(min)(const detail::expression<tag, A1, A2, A3, A4>& a, const detail::expression<tagb, A1b, A2b, A3b, A4b>& b)
0051 {
0052    typename detail::expression<tag, A1, A2, A3, A4>::result_type t1(a), t2(b);
0053    if (t1 < t2)
0054       return std::move(t1);
0055    return std::move(t2);
0056 }
0057 template <class tag, class A1, class A2, class A3, class A4>
0058 inline typename detail::expression<tag, A1, A2, A3, A4>::result_type(min)(const detail::expression<tag, A1, A2, A3, A4>& a, const detail::expression<tag, A1, A2, A3, A4>& b)
0059 {
0060    typename detail::expression<tag, A1, A2, A3, A4>::result_type t1(a), t2(b);
0061    if (t1 < t2)
0062       return std::move(t1);
0063    return std::move(t2);
0064 }
0065 
0066 template <class Backend>
0067 inline typename std::enable_if<boost::multiprecision::detail::is_backend<Backend>::value, const number<Backend, et_on>&>::type(max)(const number<Backend, et_on>& a, const number<Backend, et_on>& b)
0068 {
0069    return a > b ? a : b;
0070 }
0071 template <class Backend, class tag, class A1, class A2, class A3, class A4>
0072 inline typename std::enable_if<boost::multiprecision::detail::is_backend<Backend>::value, const number<Backend, et_on> >::type(max)(const number<Backend, et_on>& a, const detail::expression<tag, A1, A2, A3, A4>& b)
0073 {
0074    number<Backend, et_on> t(b);
0075    if (a > t)
0076       return a;
0077    return std::move(t);
0078 }
0079 template <class tag, class A1, class A2, class A3, class A4, class Backend>
0080 inline typename std::enable_if<boost::multiprecision::detail::is_backend<Backend>::value, const number<Backend, et_on> >::type(max)(const detail::expression<tag, A1, A2, A3, A4>& a, const number<Backend, et_on>& b)
0081 {
0082    number<Backend, et_on> t(a);
0083    if (t > b)
0084       return std::move(t);
0085    return b;
0086 }
0087 template <class tag, class A1, class A2, class A3, class A4, class tagb, class A1b, class A2b, class A3b, class A4b>
0088 inline typename detail::expression<tag, A1, A2, A3, A4>::result_type(max)(const detail::expression<tag, A1, A2, A3, A4>& a, const detail::expression<tagb, A1b, A2b, A3b, A4b>& b)
0089 {
0090    typename detail::expression<tag, A1, A2, A3, A4>::result_type t1(a), t2(b);
0091    if (t1 > t2)
0092       return std::move(t1);
0093    return std::move(t2);
0094 }
0095 template <class tag, class A1, class A2, class A3, class A4>
0096 inline typename detail::expression<tag, A1, A2, A3, A4>::result_type(max)(const detail::expression<tag, A1, A2, A3, A4>& a, const detail::expression<tag, A1, A2, A3, A4>& b)
0097 {
0098    typename detail::expression<tag, A1, A2, A3, A4>::result_type t1(a), t2(b);
0099    if (t1 > t2)
0100       return std::move(t1);
0101    return std::move(t2);
0102 }
0103 
0104 }} // namespace boost::multiprecision
0105 
0106 #endif