pointer_fwd.hpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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> using is_nt_cc = std::is_nothrow_copy_constructible<P>;
  20. template <typename P> using is_nt_ca = std::is_nothrow_copy_assignable<P>;
  21. template <typename P> using is_nt_mc = std::is_nothrow_move_constructible<P>;
  22. template <typename P> using is_nt_ma = std::is_nothrow_move_assignable<P>;
  23. template <typename P, typename Y>
  24. using is_nt_c = std::is_nothrow_constructible<P, Y>;
  25. template <typename P, typename Y>
  26. using is_nt_a = std::is_nothrow_assignable<P, Y>;
  27. template <typename P, typename = void> struct get_ptr {
  28. decltype(std::declval<P>().get()) get(P const & ptr) const {
  29. return std::addressof(*ptr);
  30. }
  31. };
  32. template <typename T> struct get_ptr<std::weak_ptr<T>> {
  33. void get(std::weak_ptr<T> const & ptr) throw();
  34. };
  35. template <typename T> struct get_ptr<T *> {
  36. T * get(T * ptr) const { return ptr; }
  37. };
  38. template <typename P>
  39. struct get_ptr<P, typename std::enable_if<!std::is_void<decltype(
  40. std::declval<P>().get())>::value>::type> {
  41. decltype(std::declval<P>().get()) get(P const & ptr) const {
  42. return ptr.get();
  43. }
  44. };
  45. }