sp_convertible.hpp 2.1 KB

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