]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/multiprecision/detail/min_max.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / multiprecision / detail / min_max.hpp
CommitLineData
7c673cae
FG
1///////////////////////////////////////////////////////////////////////////////
2// Copyright 2016 John Maddock. Distributed under the Boost
3// Software License, Version 1.0. (See accompanying file
4// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6#ifndef BOOST_MP_MIN_MAX_HPP
7#define BOOST_MP_MIN_MAX_HPP
8
9#include <boost/multiprecision/traits/is_backend.hpp>
10
92f5a8d4 11namespace boost { namespace multiprecision {
7c673cae
FG
12
13//
14// Expression template overloads for (min) and (max):
15//
16// Introduced in response to https://svn.boost.org/trac/boost/ticket/11149
17// note that these can not legally be injected into namespace std, and that doing so
18// may break future enhancements to the standard. None the less adding
19// namespace std{ using boost::multiprecision::(min); using boost::multiprecision::(max); }
20// to your code may get some generic code working that wouldn't work otherwise.
21//
22// The use of enable_if on the return type is to avoid poisoning std::min/max,
23// otherwise attempting to make an explicit call to min<long>(a, b) when these and std
24// versions are in scope, will cause the compiler to try to instantiate the signatures
25// for our versions as well as the std ones, which in turn instantiates number<long>
26// which fails to compile as "long" is not a valid backend type.
27//
28template <class Backend>
92f5a8d4 29inline typename boost::enable_if_c<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)
7c673cae
FG
30{
31 return a < b ? a : b;
32}
33template <class Backend, class tag, class A1, class A2, class A3, class A4>
92f5a8d4 34inline typename boost::enable_if_c<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)
7c673cae
FG
35{
36 number<Backend, et_on> t(b);
92f5a8d4 37 if (a < t)
7c673cae
FG
38 return a;
39 return BOOST_MP_MOVE(t);
40}
41template <class tag, class A1, class A2, class A3, class A4, class Backend>
92f5a8d4 42inline typename boost::enable_if_c<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)
7c673cae
FG
43{
44 number<Backend, et_on> t(a);
92f5a8d4 45 if (t < b)
7c673cae
FG
46 return BOOST_MP_MOVE(t);
47 return b;
48}
49template <class tag, class A1, class A2, class A3, class A4, class tagb, class A1b, class A2b, class A3b, class A4b>
92f5a8d4 50inline 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)
7c673cae
FG
51{
52 typename detail::expression<tag, A1, A2, A3, A4>::result_type t1(a), t2(b);
92f5a8d4 53 if (t1 < t2)
7c673cae
FG
54 return BOOST_MP_MOVE(t1);
55 return BOOST_MP_MOVE(t2);
56}
57template <class tag, class A1, class A2, class A3, class A4>
92f5a8d4 58inline 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)
7c673cae
FG
59{
60 typename detail::expression<tag, A1, A2, A3, A4>::result_type t1(a), t2(b);
92f5a8d4 61 if (t1 < t2)
7c673cae
FG
62 return BOOST_MP_MOVE(t1);
63 return BOOST_MP_MOVE(t2);
64}
65
66template <class Backend>
92f5a8d4 67inline typename boost::enable_if_c<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)
7c673cae
FG
68{
69 return a > b ? a : b;
70}
71template <class Backend, class tag, class A1, class A2, class A3, class A4>
92f5a8d4 72inline typename boost::enable_if_c<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)
7c673cae
FG
73{
74 number<Backend, et_on> t(b);
92f5a8d4 75 if (a > t)
7c673cae
FG
76 return a;
77 return BOOST_MP_MOVE(t);
78}
79template <class tag, class A1, class A2, class A3, class A4, class Backend>
92f5a8d4 80inline typename boost::enable_if_c<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)
7c673cae
FG
81{
82 number<Backend, et_on> t(a);
92f5a8d4 83 if (t > b)
7c673cae
FG
84 return BOOST_MP_MOVE(t);
85 return b;
86}
87template <class tag, class A1, class A2, class A3, class A4, class tagb, class A1b, class A2b, class A3b, class A4b>
92f5a8d4 88inline 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)
7c673cae
FG
89{
90 typename detail::expression<tag, A1, A2, A3, A4>::result_type t1(a), t2(b);
92f5a8d4 91 if (t1 > t2)
7c673cae
FG
92 return BOOST_MP_MOVE(t1);
93 return BOOST_MP_MOVE(t2);
94}
95template <class tag, class A1, class A2, class A3, class A4>
92f5a8d4 96inline 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)
7c673cae
FG
97{
98 typename detail::expression<tag, A1, A2, A3, A4>::result_type t1(a), t2(b);
92f5a8d4 99 if (t1 > t2)
7c673cae
FG
100 return BOOST_MP_MOVE(t1);
101 return BOOST_MP_MOVE(t2);
102}
103
92f5a8d4 104}} // namespace boost::multiprecision
7c673cae
FG
105
106#endif