is_convertible.hpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // (C) Copyright Thorsten Ottosen 2005
  2. // (C) Copyright Howard Hinnant 2004
  3. // (C) Copyright Jonathan Turkanis 2004
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
  6. //
  7. // Contains type traits machinery for incomplete arrays. MPL compatibility
  8. // is included for completeness, but is not necessary for the current
  9. // application.
  10. //
  11. #ifndef BOOST_MOVE_PTR_ARRAYS_HPP_INCLUDED
  12. #define BOOST_MOVE_PTR_ARRAYS_HPP_INCLUDED
  13. #include <boost/config.hpp> // BOOST_STATIC_CONSTANT.
  14. #include <boost/mpl/aux_/lambda_support.hpp>
  15. #include <boost/mpl/and.hpp>
  16. #include <boost/mpl/bool.hpp>
  17. #include <boost/mpl/identity.hpp>
  18. #include <boost/mpl/if.hpp>
  19. #include <boost/type_traits/is_array.hpp>
  20. #include <boost/type_traits/is_convertible.hpp>
  21. #include <boost/type_traits/is_same.hpp>
  22. #include <boost/type_traits/remove_bounds.hpp>
  23. #include <boost/type_traits/remove_cv.hpp>
  24. #include <boost/utility/enable_if.hpp>
  25. namespace boost { namespace ptr_container_detail { namespace move_ptrs {
  26. // From Howard Hinnant.
  27. template<typename T, typename U>
  28. struct is_array_convertible {
  29. typedef typename remove_bounds<T>::type t_element;
  30. typedef typename remove_bounds<U>::type u_element;
  31. typedef typename remove_cv<t_element>::type t_base;
  32. typedef typename remove_cv<u_element>::type u_base;
  33. typedef typename
  34. mpl::and_<
  35. is_array<T>,
  36. is_array<U>,
  37. is_same<t_base, u_base>,
  38. is_convertible<t_element*, u_element*>
  39. >::type type;
  40. BOOST_STATIC_CONSTANT(bool, value = type::value);
  41. BOOST_MPL_AUX_LAMBDA_SUPPORT(2, is_array_convertible, (T, U))
  42. };
  43. template<typename T, typename U>
  44. struct is_smart_ptr_convertible
  45. : mpl::if_<
  46. is_array<T>,
  47. is_array_convertible<T, U>,
  48. is_convertible<T*, U*>
  49. >::type
  50. { };
  51. #ifndef BOOST_NO_SFINAE
  52. template<typename Src, typename Tgt, typename T = void>
  53. struct enable_if_convertible
  54. : enable_if<
  55. is_smart_ptr_convertible<Src, Tgt>,
  56. T
  57. >
  58. { };
  59. #else
  60. template<typename Src, typename Tgt, class T >
  61. struct enable_if_convertible : mpl::identity<T> { };
  62. #endif
  63. } } } // End namespaces ptr_container_detail, move_ptrs, boost.
  64. #endif // #ifndef BOOST_MOVE_PTR_ARRAYS_HPP_INCLUDED