is_backend.hpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Copyright 2015 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. #ifndef BOOST_MP_IS_BACKEND_HPP
  6. #define BOOST_MP_IS_BACKEND_HPP
  7. #include <boost/mpl/has_xxx.hpp>
  8. #include <boost/type_traits/conditional.hpp>
  9. #include <boost/type_traits/is_convertible.hpp>
  10. #include <boost/multiprecision/detail/number_base.hpp>
  11. namespace boost { namespace multiprecision { namespace detail {
  12. BOOST_MPL_HAS_XXX_TRAIT_DEF(signed_types)
  13. BOOST_MPL_HAS_XXX_TRAIT_DEF(unsigned_types)
  14. BOOST_MPL_HAS_XXX_TRAIT_DEF(float_types)
  15. template <class T>
  16. struct is_backend
  17. {
  18. static const bool value = has_signed_types<T>::value && has_unsigned_types<T>::value && has_float_types<T>::value;
  19. };
  20. template <class Backend>
  21. struct other_backend
  22. {
  23. typedef typename boost::conditional<
  24. boost::is_same<number<Backend>, number<Backend, et_on> >::value,
  25. number<Backend, et_off>, number<Backend, et_on> >::type type;
  26. };
  27. template <class B, class V>
  28. struct number_from_backend
  29. {
  30. typedef typename boost::conditional<
  31. boost::is_convertible<V, number<B> >::value,
  32. number<B>,
  33. typename other_backend<B>::type>::type type;
  34. };
  35. template <bool b, class T, class U>
  36. struct is_first_backend_imp
  37. {
  38. static const bool value = false;
  39. };
  40. template <class T, class U>
  41. struct is_first_backend_imp<true, T, U>
  42. {
  43. static const bool value = is_convertible<U, number<T, et_on> >::value || is_convertible<U, number<T, et_off> >::value;
  44. };
  45. template <class T, class U>
  46. struct is_first_backend : is_first_backend_imp<is_backend<T>::value, T, U>
  47. {};
  48. template <bool b, class T, class U>
  49. struct is_second_backend_imp
  50. {
  51. static const bool value = false;
  52. };
  53. template <class T, class U>
  54. struct is_second_backend_imp<true, T, U>
  55. {
  56. static const bool value = (is_convertible<T, number<U, et_on> >::value || is_convertible<T, number<U, et_off> >::value) && !is_first_backend<T, U>::value;
  57. };
  58. template <class T, class U>
  59. struct is_second_backend : is_second_backend_imp<is_backend<U>::value, T, U>
  60. {};
  61. }
  62. }
  63. } // namespace boost::multiprecision::detail
  64. #endif // BOOST_MP_IS_BACKEND_HPP