pointer_fwd.hpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. //
  2. // pointer_fwd.hpp
  3. // memory
  4. //
  5. // Created by Sam Jaffe on 8/8/16.
  6. //
  7. #pragma once
  8. #include <stdexcept>
  9. template <typename> class not_null;
  10. template <typename> class maybe_null;
  11. template <typename> class owner;
  12. template <typename> class const_propogating_ptr;
  13. template <typename> class const_ptr;
  14. class unchecked_pointer_exception;
  15. class null_pointer_exception : public std::invalid_argument {
  16. using std::invalid_argument::invalid_argument;
  17. };
  18. namespace detail {
  19. template <typename P>
  20. using is_nt_cc = std::is_nothrow_copy_constructible<P>;
  21. template <typename P>
  22. using is_nt_ca = std::is_nothrow_copy_assignable<P>;
  23. template <typename P>
  24. using is_nt_mc = std::is_nothrow_move_constructible<P>;
  25. template <typename P>
  26. using is_nt_ma = std::is_nothrow_move_assignable<P>;
  27. template <typename P, typename Y>
  28. using is_nt_c = std::is_nothrow_constructible<P, Y>;
  29. template <typename P, typename Y>
  30. using is_nt_a = std::is_nothrow_assignable<P, Y>;
  31. template <typename P, typename = void>
  32. struct get_ptr {
  33. decltype(std::declval<P>().get()) get( P const & ptr ) const { return std::addressof(*ptr); }
  34. };
  35. template <typename T>
  36. struct get_ptr<T*> {
  37. T* get( T* ptr ) const { return ptr; }
  38. };
  39. template <typename P>
  40. struct get_ptr<P, typename std::enable_if<!std::is_void<decltype(std::declval<P>().get())>::value>::type> {
  41. decltype(std::declval<P>().get()) get( P const & ptr ) const { return ptr.get(); }
  42. };
  43. }