sp_convertible.hpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #ifndef BOOST_SMART_PTR_DETAIL_SP_CONVERTIBLE_HPP_INCLUDED
  2. #define BOOST_SMART_PTR_DETAIL_SP_CONVERTIBLE_HPP_INCLUDED
  3. // MS compatible compilers support #pragma once
  4. #if defined(_MSC_VER) && (_MSC_VER >= 1020)
  5. # pragma once
  6. #endif
  7. // detail/sp_convertible.hpp
  8. //
  9. // Copyright 2008 Peter Dimov
  10. //
  11. // Distributed under the Boost Software License, Version 1.0.
  12. // See accompanying file LICENSE_1_0.txt or copy at
  13. // http://www.boost.org/LICENSE_1_0.txt
  14. #include <boost/config.hpp>
  15. #include <cstddef>
  16. namespace boost
  17. {
  18. namespace detail
  19. {
  20. template< class Y, class T > struct sp_convertible
  21. {
  22. typedef char (&yes) [1];
  23. typedef char (&no) [2];
  24. static yes f( T* );
  25. static no f( ... );
  26. enum _vt { value = sizeof( (f)( static_cast<Y*>(0) ) ) == sizeof(yes) };
  27. };
  28. template< class Y, class T > struct sp_convertible< Y, T[] >
  29. {
  30. enum _vt { value = false };
  31. };
  32. template< class Y, class T > struct sp_convertible< Y[], T[] >
  33. {
  34. enum _vt { value = sp_convertible< Y[1], T[1] >::value };
  35. };
  36. template< class Y, std::size_t N, class T > struct sp_convertible< Y[N], T[] >
  37. {
  38. enum _vt { value = sp_convertible< Y[1], T[1] >::value };
  39. };
  40. struct sp_empty
  41. {
  42. };
  43. template< bool > struct sp_enable_if_convertible_impl;
  44. template<> struct sp_enable_if_convertible_impl<true>
  45. {
  46. typedef sp_empty type;
  47. };
  48. template<> struct sp_enable_if_convertible_impl<false>
  49. {
  50. };
  51. template< class Y, class T > struct sp_enable_if_convertible: public sp_enable_if_convertible_impl< sp_convertible< Y, T >::value >
  52. {
  53. };
  54. } // namespace detail
  55. } // namespace boost
  56. #endif // #ifndef BOOST_SMART_PTR_DETAIL_SP_CONVERTIBLE_HPP_INCLUDED