get_ptr.hpp 700 B

123456789101112131415161718192021222324252627
  1. #pragma once
  2. namespace pointers { namespace detail {
  3. template <typename P, typename = void> struct get_ptr {
  4. decltype(std::declval<P>().get()) get(P const & ptr) const {
  5. return std::addressof(*ptr);
  6. }
  7. };
  8. template <typename T> struct get_ptr<std::weak_ptr<T>> {
  9. void get(std::weak_ptr<T> const & ptr) throw();
  10. };
  11. template <typename T> struct get_ptr<T *> {
  12. T * get(T * ptr) const { return ptr; }
  13. };
  14. template <typename P>
  15. struct get_ptr<P, typename std::enable_if<!std::is_void<decltype(
  16. std::declval<P>().get())>::value>::type> {
  17. decltype(std::declval<P>().get()) get(P const & ptr) const {
  18. return ptr.get();
  19. }
  20. };
  21. }}