pointee.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // Copyright David Abrahams 2004. Use, modification and distribution is
  2. // subject to the Boost Software License, Version 1.0. (See accompanying
  3. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  4. #include <boost/pointee.hpp>
  5. #include <boost/type_traits/add_const.hpp>
  6. #include "static_assert_same.hpp"
  7. #include <memory>
  8. #include <list>
  9. template <class T, class Ref>
  10. struct proxy_ptr
  11. {
  12. typedef T element_type;
  13. struct proxy
  14. {
  15. operator Ref() const;
  16. };
  17. proxy operator*() const;
  18. };
  19. template <class T>
  20. struct proxy_ref_ptr : proxy_ptr<T,T&>
  21. {
  22. };
  23. template <class T>
  24. struct proxy_value_ptr : proxy_ptr<T,T>
  25. {
  26. typedef typename boost::add_const<T>::type element_type;
  27. };
  28. struct X {
  29. template <class T> X(T const&);
  30. template <class T> operator T&() const;
  31. };
  32. int main()
  33. {
  34. STATIC_ASSERT_SAME(boost::pointee<proxy_ref_ptr<int> >::type, int);
  35. STATIC_ASSERT_SAME(boost::pointee<proxy_ref_ptr<X> >::type, X);
  36. STATIC_ASSERT_SAME(boost::pointee<proxy_ref_ptr<int const> >::type, int const);
  37. STATIC_ASSERT_SAME(boost::pointee<proxy_ref_ptr<X const> >::type, X const);
  38. STATIC_ASSERT_SAME(boost::pointee<proxy_value_ptr<int> >::type, int const);
  39. STATIC_ASSERT_SAME(boost::pointee<proxy_value_ptr<X> >::type, X const);
  40. STATIC_ASSERT_SAME(boost::pointee<proxy_value_ptr<int const> >::type, int const);
  41. STATIC_ASSERT_SAME(boost::pointee<proxy_value_ptr<X const> >::type, X const);
  42. STATIC_ASSERT_SAME(boost::pointee<int*>::type, int);
  43. STATIC_ASSERT_SAME(boost::pointee<int const*>::type, int const);
  44. STATIC_ASSERT_SAME(boost::pointee<X*>::type, X);
  45. STATIC_ASSERT_SAME(boost::pointee<X const*>::type, X const);
  46. #if defined(BOOST_NO_CXX11_SMART_PTR)
  47. STATIC_ASSERT_SAME(boost::pointee<std::auto_ptr<int> >::type, int);
  48. STATIC_ASSERT_SAME(boost::pointee<std::auto_ptr<X> >::type, X);
  49. STATIC_ASSERT_SAME(boost::pointee<std::auto_ptr<int const> >::type, int const);
  50. STATIC_ASSERT_SAME(boost::pointee<std::auto_ptr<X const> >::type, X const);
  51. #else
  52. STATIC_ASSERT_SAME(boost::pointee<std::unique_ptr<int> >::type, int);
  53. STATIC_ASSERT_SAME(boost::pointee<std::unique_ptr<X> >::type, X);
  54. STATIC_ASSERT_SAME(boost::pointee<std::unique_ptr<int const> >::type, int const);
  55. STATIC_ASSERT_SAME(boost::pointee<std::unique_ptr<X const> >::type, X const);
  56. #endif
  57. STATIC_ASSERT_SAME(boost::pointee<std::list<int>::iterator >::type, int);
  58. STATIC_ASSERT_SAME(boost::pointee<std::list<X>::iterator >::type, X);
  59. STATIC_ASSERT_SAME(boost::pointee<std::list<int>::const_iterator >::type, int const);
  60. STATIC_ASSERT_SAME(boost::pointee<std::list<X>::const_iterator >::type, X const);
  61. return 0;
  62. }