]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/multiprecision/traits/explicit_conversion.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / multiprecision / traits / explicit_conversion.hpp
CommitLineData
7c673cae
FG
1///////////////////////////////////////////////////////////////////////////////
2// Copyright Vicente J. Botet Escriba 2009-2011
3// Copyright 2012 John Maddock. Distributed under the Boost
4// Software License, Version 1.0. (See accompanying file
5// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6
7#ifndef BOOST_MP_EXPLICIT_CONVERTIBLE_HPP
8#define BOOST_MP_EXPLICIT_CONVERTIBLE_HPP
9
92f5a8d4
TL
10#include <boost/config.hpp>
11#include <boost/type_traits/conditional.hpp>
12#include <boost/type_traits/integral_constant.hpp>
7c673cae 13#include <boost/type_traits/is_convertible.hpp>
92f5a8d4
TL
14#include <boost/type_traits/declval.hpp>
15#include <boost/multiprecision/detail/number_base.hpp> // number_category
7c673cae
FG
16
17namespace boost {
92f5a8d4
TL
18namespace multiprecision {
19namespace detail {
7c673cae 20
92f5a8d4
TL
21template <unsigned int N>
22struct dummy_size
23{};
7c673cae 24
92f5a8d4
TL
25template <typename S, typename T>
26struct has_generic_interconversion
27{
28 typedef typename boost::conditional<
29 is_number<S>::value && is_number<T>::value,
30 typename boost::conditional<
31 number_category<S>::value == number_kind_integer,
32 typename boost::conditional<
33 number_category<T>::value == number_kind_integer || number_category<T>::value == number_kind_floating_point || number_category<T>::value == number_kind_rational || number_category<T>::value == number_kind_fixed_point,
34 boost::true_type,
35 boost::false_type>::type,
36 typename boost::conditional<
7c673cae 37 number_category<S>::value == number_kind_rational,
92f5a8d4
TL
38 typename boost::conditional<
39 number_category<T>::value == number_kind_rational || number_category<T>::value == number_kind_rational,
40 boost::true_type,
41 boost::false_type>::type,
42 typename boost::conditional<
43 number_category<T>::value == number_kind_floating_point,
44 boost::true_type,
45 boost::false_type>::type>::type>::type,
46 boost::false_type>::type type;
47};
7c673cae 48
92f5a8d4
TL
49template <typename S, typename T>
50struct is_explicitly_convertible_imp
51{
7c673cae 52#ifndef BOOST_NO_SFINAE_EXPR
92f5a8d4
TL
53 template <typename S1, typename T1>
54 static type_traits::yes_type selector(dummy_size<sizeof(new T1(boost::declval<
55#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
56 S1
57#else
58 S1 const&
59#endif
60 >()))>*);
7c673cae 61
92f5a8d4
TL
62 template <typename S1, typename T1>
63 static type_traits::no_type selector(...);
7c673cae 64
92f5a8d4 65 static const bool value = sizeof(selector<S, T>(0)) == sizeof(type_traits::yes_type);
7c673cae 66
92f5a8d4 67 typedef boost::integral_constant<bool, value> type;
7c673cae 68#else
92f5a8d4
TL
69 typedef typename has_generic_interconversion<S, T>::type gen_type;
70 typedef boost::integral_constant<bool, boost::is_convertible<S, T>::value || gen_type::value> type;
7c673cae 71#endif
92f5a8d4 72};
7c673cae 73
92f5a8d4 74template <typename From, typename To>
7c673cae
FG
75struct is_explicitly_convertible : public is_explicitly_convertible_imp<From, To>::type
76{
77};
78
79#ifdef BOOST_NO_SFINAE_EXPR
92f5a8d4 80template <class Backend1, expression_template_option ExpressionTemplates1, class Backend2, expression_template_option ExpressionTemplates2>
7c673cae 81struct is_explicitly_convertible<number<Backend1, ExpressionTemplates1>, number<Backend2, ExpressionTemplates2> >
92f5a8d4 82 : public is_explicitly_convertible<Backend1, Backend2>
7c673cae
FG
83{
84};
85#endif
86
92f5a8d4 87}}} // namespace boost::multiprecision::detail
7c673cae
FG
88
89#endif