nullable.hpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. //
  2. // Boost.Pointer Container
  3. //
  4. // Copyright Thorsten Ottosen 2003-2005. Use, modification and
  5. // distribution is subject to the Boost Software License, Version
  6. // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. //
  9. // For more information, see http://www.boost.org/libs/ptr_container/
  10. //
  11. #ifndef BOOST_INDIRECT_CONTAINER_NULLABLE_HPP
  12. #define BOOST_INDIRECT_CONTAINER_NULLABLE_HPP
  13. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  14. # pragma once
  15. #endif
  16. #include <boost/type_traits/detail/yes_no_type.hpp>
  17. #include <boost/type_traits/is_const.hpp>
  18. #include <boost/mpl/eval_if.hpp>
  19. #include <boost/mpl/identity.hpp>
  20. #include <boost/config.hpp>
  21. namespace boost
  22. {
  23. template< class T >
  24. struct nullable
  25. {
  26. typedef T type;
  27. };
  28. namespace ptr_container_detail
  29. {
  30. template< class T >
  31. type_traits::yes_type is_nullable( const nullable<T>* );
  32. type_traits::no_type is_nullable( ... );
  33. }
  34. template< class T >
  35. struct is_nullable
  36. {
  37. private:
  38. BOOST_STATIC_CONSTANT( T*, var );
  39. public:
  40. #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
  41. #pragma warning(push)
  42. #pragma warning(disable:6334)
  43. #endif
  44. BOOST_STATIC_CONSTANT(bool, value = sizeof( ptr_container_detail::is_nullable( var ) )
  45. == sizeof( type_traits::yes_type ) );
  46. #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
  47. #pragma warning(pop)
  48. #endif
  49. };
  50. template< class T >
  51. struct remove_nullable
  52. {
  53. typedef BOOST_DEDUCED_TYPENAME mpl::eval_if< is_nullable<T>,
  54. T,
  55. mpl::identity<T> >::type
  56. type;
  57. };
  58. namespace ptr_container_detail
  59. {
  60. template< class T >
  61. struct void_ptr
  62. {
  63. typedef BOOST_DEDUCED_TYPENAME
  64. mpl::if_c< boost::is_const<
  65. BOOST_DEDUCED_TYPENAME boost::remove_nullable<T>::type >::value,
  66. const void*, void* >::type type;
  67. };
  68. }
  69. }
  70. #endif