sp_convertible.hpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. #if !defined( BOOST_SP_NO_SP_CONVERTIBLE ) && defined( BOOST_NO_SFINAE )
  16. # define BOOST_SP_NO_SP_CONVERTIBLE
  17. #endif
  18. #if !defined( BOOST_SP_NO_SP_CONVERTIBLE ) && defined( __GNUC__ ) && ( __GNUC__ * 100 + __GNUC_MINOR__ < 303 )
  19. # define BOOST_SP_NO_SP_CONVERTIBLE
  20. #endif
  21. #if !defined( BOOST_SP_NO_SP_CONVERTIBLE ) && defined( __BORLANDC__ ) && ( __BORLANDC__ < 0x630 )
  22. # define BOOST_SP_NO_SP_CONVERTIBLE
  23. #endif
  24. #if !defined( BOOST_SP_NO_SP_CONVERTIBLE )
  25. namespace boost
  26. {
  27. namespace detail
  28. {
  29. template< class Y, class T > struct sp_convertible
  30. {
  31. typedef char (&yes) [1];
  32. typedef char (&no) [2];
  33. static yes f( T* );
  34. static no f( ... );
  35. enum _vt { value = sizeof( (f)( static_cast<Y*>(0) ) ) == sizeof(yes) };
  36. };
  37. template< class Y, class T > struct sp_convertible< Y, T[] >
  38. {
  39. enum _vt { value = false };
  40. };
  41. template< class Y, class T > struct sp_convertible< Y[], T[] >
  42. {
  43. enum _vt { value = sp_convertible< Y[1], T[1] >::value };
  44. };
  45. template< class Y, std::size_t N, class T > struct sp_convertible< Y[N], T[] >
  46. {
  47. enum _vt { value = sp_convertible< Y[1], T[1] >::value };
  48. };
  49. struct sp_empty
  50. {
  51. };
  52. template< bool > struct sp_enable_if_convertible_impl;
  53. template<> struct sp_enable_if_convertible_impl<true>
  54. {
  55. typedef sp_empty type;
  56. };
  57. template<> struct sp_enable_if_convertible_impl<false>
  58. {
  59. };
  60. template< class Y, class T > struct sp_enable_if_convertible: public sp_enable_if_convertible_impl< sp_convertible< Y, T >::value >
  61. {
  62. };
  63. } // namespace detail
  64. } // namespace boost
  65. #endif // !defined( BOOST_SP_NO_SP_CONVERTIBLE )
  66. #endif // #ifndef BOOST_SMART_PTR_DETAIL_SP_CONVERTIBLE_HPP_INCLUDED