Prechádzať zdrojové kódy

Removing pointer_traits.hpp

Samuel Jaffe 9 rokov pred
rodič
commit
7bd6b96a3b
3 zmenil súbory, kde vykonal 6 pridanie a 28 odobranie
  1. 3 4
      maybe_null.hpp
  2. 3 5
      not_null.hpp
  3. 0 19
      pointer_traits.hpp

+ 3 - 4
maybe_null.hpp

@@ -13,7 +13,6 @@
 
 #include "pointer_fwd.hpp"
 
-#include "pointer_traits.hpp"
 #include "not_null.hpp"
 
 class unchecked_pointer_exception : public std::logic_error {
@@ -25,9 +24,9 @@ template <typename P> class maybe_null<not_null<P>>; // not permitted
 template <typename T>
 class maybe_null {
 public:
-  using element_type = typename detail::pointer_traits<T>::element_type;
-  using pointer = typename detail::pointer_traits<T>::pointer;
-  using reference = typename detail::pointer_traits<T>::reference;
+  using element_type = typename std::pointer_traits<T>::element_type;
+  using pointer = element_type *;
+  using reference = element_type &;
   
   maybe_null() : _ptr(nullptr) {}
   template <typename... Args> maybe_null(Args && ...args) : _ptr(std::forward<Args>(args)...) { }

+ 3 - 5
not_null.hpp

@@ -13,8 +13,6 @@
 
 #include "pointer_fwd.hpp"
 
-#include "pointer_traits.hpp"
-
 class null_pointer_exception : public std::invalid_argument {
   using std::invalid_argument::invalid_argument;
 };
@@ -24,9 +22,9 @@ template <typename P> class not_null<std::weak_ptr<P>>; // A weak_ptr cannot be
 template <typename T>
 class not_null {
 public:
-  using element_type = typename detail::pointer_traits<T>::element_type;
-  using pointer = typename detail::pointer_traits<T>::pointer;
-  using reference = typename detail::pointer_traits<T>::reference;
+  using element_type = typename std::pointer_traits<T>::element_type;
+  using pointer = element_type *;
+  using reference = element_type &;
   
   explicit not_null(std::nullptr_t) = delete;
   explicit not_null(int) = delete;

+ 0 - 19
pointer_traits.hpp

@@ -1,19 +0,0 @@
-//
-//  pointer_traits.hpp
-//  memory
-//
-//  Created by Sam Jaffe on 7/29/16.
-//
-
-#pragma once
-
-#include <type_traits>
-
-namespace detail {
-  template <typename T>
-  struct pointer_traits {
-    using element_type = typename std::remove_reference<decltype(*std::declval<T>())>::type;
-    using pointer = element_type *;
-    using reference = typename std::add_lvalue_reference<element_type>::type;
-  };
-}