Browse Source

Apply clang-format.

Sam Jaffe 5 years ago
parent
commit
5bb01f870b

+ 108 - 0
.clang-format

@@ -0,0 +1,108 @@
+---
+Language:        Cpp
+# BasedOnStyle:  LLVM
+AccessModifierOffset: -2
+AlignAfterOpenBracket: Align
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+AlignEscapedNewlines: Right
+AlignOperands:   true
+AlignTrailingComments: true
+AllowAllParametersOfDeclarationOnNextLine: true
+AllowShortBlocksOnASingleLine: true
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: All
+AllowShortIfStatementsOnASingleLine: true
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: false
+BinPackArguments: true
+BinPackParameters: true
+BraceWrapping:   
+  AfterClass:      false
+  AfterControlStatement: false
+  AfterEnum:       false
+  AfterFunction:   false
+  AfterNamespace:  false
+  AfterObjCDeclaration: false
+  AfterStruct:     false
+  AfterUnion:      false
+  BeforeCatch:     false
+  BeforeElse:      false
+  IndentBraces:    false
+  SplitEmptyFunction: true
+  SplitEmptyRecord: true
+  SplitEmptyNamespace: true
+BreakBeforeBinaryOperators: None
+BreakBeforeBraces: Attach
+BreakBeforeInheritanceComma: false
+BreakBeforeTernaryOperators: true
+BreakConstructorInitializersBeforeComma: false
+BreakConstructorInitializers: BeforeColon
+BreakAfterJavaFieldAnnotations: false
+BreakStringLiterals: true
+ColumnLimit:     80
+CommentPragmas:  '^ IWYU pragma:'
+CompactNamespaces: true
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerIndentWidth: 4
+ContinuationIndentWidth: 4
+Cpp11BracedListStyle: true
+DerivePointerAlignment: false
+DisableFormat:   false
+ExperimentalAutoDetectBinPacking: false
+FixNamespaceComments: false
+ForEachMacros:   
+  - foreach
+  - Q_FOREACH
+  - BOOST_FOREACH
+IncludeCategories: 
+  - Regex:           '^"(llvm|llvm-c|clang|clang-c)/'
+    Priority:        2
+  - Regex:           '^(<|"(gtest|gmock|isl|json)/)'
+    Priority:        3
+  - Regex:           '.*'
+    Priority:        1
+IncludeIsMainRegex: '(Test)?$'
+IndentCaseLabels: false
+IndentWidth:     2
+IndentWrappedFunctionNames: false
+JavaScriptQuotes: Leave
+JavaScriptWrapImports: true
+KeepEmptyLinesAtTheStartOfBlocks: true
+MacroBlockBegin: ''
+MacroBlockEnd:   ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: All
+ObjCBlockIndentWidth: 2
+ObjCSpaceAfterProperty: false
+ObjCSpaceBeforeProtocolList: true
+PenaltyBreakAssignment: 2
+PenaltyBreakBeforeFirstCallParameter: 19
+PenaltyBreakComment: 300
+PenaltyBreakFirstLessLess: 120
+PenaltyBreakString: 1000
+PenaltyExcessCharacter: 1000000
+PenaltyReturnTypeOnItsOwnLine: 60
+PointerAlignment: Middle
+ReflowComments:  true
+SortIncludes:    true
+SortUsingDeclarations: true
+SpaceAfterCStyleCast: false
+SpaceAfterTemplateKeyword: true
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeParens: ControlStatements
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles:  false
+SpacesInContainerLiterals: true
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+Standard:        Cpp11
+TabWidth:        8
+UseTab:          Never
+...
+

+ 40 - 29
include/pointers/const_propogating_ptr.hpp

@@ -11,57 +11,68 @@
 #include "pointer_fwd.hpp"
 #include "ptr_compare.hpp"
 
-template <typename P>
-class const_propogating_ptr : private detail::get_ptr<P> {
+template <typename P> class const_propogating_ptr : private detail::get_ptr<P> {
 public:
   using element_type = typename std::pointer_traits<P>::element_type;
-  using pointer = element_type  *;
+  using pointer = element_type *;
   using reference = element_type &;
   using const_pointer = element_type const *;
   using const_reference = element_type const &;
 
   const_propogating_ptr() noexcept : _ptr() {}
-  const_propogating_ptr(P const & p) noexcept(detail::is_nt_cc<P>::value) : _ptr(p) {}
-  const_propogating_ptr(P && p) noexcept(detail::is_nt_mc<P>::value) : _ptr(std::move(p)) {}
-  template <typename Y, typename = typename std::enable_if<std::is_constructible<P, Y>::value>::type>
-  const_propogating_ptr(Y const & p) : _ptr(p) { }
-  template <typename Y, typename = typename std::enable_if<std::is_constructible<P, Y>::value>::type>
-  const_propogating_ptr(Y && p) : _ptr(std::forward<Y>(p)) { }
+  const_propogating_ptr(P const & p) noexcept(detail::is_nt_cc<P>::value)
+      : _ptr(p) {}
+  const_propogating_ptr(P && p) noexcept(detail::is_nt_mc<P>::value)
+      : _ptr(std::move(p)) {}
+  template <typename Y, typename = typename std::enable_if<
+                            std::is_constructible<P, Y>::value>::type>
+  const_propogating_ptr(Y const & p) : _ptr(p) {}
+  template <typename Y, typename = typename std::enable_if<
+                            std::is_constructible<P, Y>::value>::type>
+  const_propogating_ptr(Y && p) : _ptr(std::forward<Y>(p)) {}
 
-  const_propogating_ptr(const_propogating_ptr &) noexcept(detail::is_nt_cc<P>::value) = default;
-  const_propogating_ptr(const_propogating_ptr &&) noexcept(detail::is_nt_mc<P>::value) = default;
+  const_propogating_ptr(const_propogating_ptr &) noexcept(
+      detail::is_nt_cc<P>::value) = default;
+  const_propogating_ptr(const_propogating_ptr &&) noexcept(
+      detail::is_nt_mc<P>::value) = default;
   const_propogating_ptr(const_propogating_ptr const &) = delete;
-  const_propogating_ptr& operator=(const_propogating_ptr &) noexcept(detail::is_nt_ca<P>::value) = default;
-  const_propogating_ptr& operator=(const_propogating_ptr &&) noexcept(detail::is_nt_ma<P>::value) = default;
-  const_propogating_ptr& operator=(const_propogating_ptr const &) = delete;
-  
+  const_propogating_ptr & operator=(const_propogating_ptr &) noexcept(
+      detail::is_nt_ca<P>::value) = default;
+  const_propogating_ptr & operator=(const_propogating_ptr &&) noexcept(
+      detail::is_nt_ma<P>::value) = default;
+  const_propogating_ptr & operator=(const_propogating_ptr const &) = delete;
+
   template <typename Y>
-  explicit operator const_propogating_ptr<Y>() & noexcept(detail::is_nt_c<P, Y>::value) {
+      explicit operator const_propogating_ptr<Y>() &
+      noexcept(detail::is_nt_c<P, Y>::value) {
     return _ptr;
   }
-  
+
   template <typename Y>
-  explicit operator const_ptr<Y>() const noexcept(detail::is_nt_c<P, Y>::value) {
+  explicit operator const_ptr<Y>() const
+      noexcept(detail::is_nt_c<P, Y>::value) {
     return _ptr;
   }
-  
+
   template <typename Y>
   explicit operator const_propogating_ptr<Y>() const & = delete;
-  
-  operator bool() const noexcept {
-    return static_cast<bool>(_ptr);
-  }
-  
+
+  operator bool() const noexcept { return static_cast<bool>(_ptr); }
+
   reference operator*() noexcept(noexcept(*_ptr)) { return *_ptr; }
-  pointer get() noexcept(noexcept(detail::get_ptr<P>::get(_ptr))) { return detail::get_ptr<P>::get(_ptr); }
+  pointer get() noexcept(noexcept(detail::get_ptr<P>::get(_ptr))) {
+    return detail::get_ptr<P>::get(_ptr);
+  }
   pointer operator->() noexcept(noexcept(get())) { return get(); }
-  
+
   const_reference operator*() const noexcept(noexcept(*_ptr)) { return *_ptr; }
-  const_pointer get() const noexcept(noexcept(detail::get_ptr<P>::get(_ptr))) { return detail::get_ptr<P>::get(_ptr); }
+  const_pointer get() const noexcept(noexcept(detail::get_ptr<P>::get(_ptr))) {
+    return detail::get_ptr<P>::get(_ptr);
+  }
   const_pointer operator->() const noexcept(noexcept(get())) { return get(); }
-  
+
 private:
   P _ptr;
 };
 
-POINTER_TEMPLATE_COMPARE( const_propogating_ptr )
+POINTER_TEMPLATE_COMPARE(const_propogating_ptr)

+ 16 - 13
include/pointers/const_ptr.hpp

@@ -11,8 +11,7 @@
 #include "pointer_fwd.hpp"
 #include "ptr_compare.hpp"
 
-template <typename P>
-class const_ptr : private detail::get_ptr<P> {
+template <typename P> class const_ptr : private detail::get_ptr<P> {
 public:
   using element_type = typename std::pointer_traits<P>::element_type;
   using pointer = element_type const *;
@@ -21,25 +20,29 @@ public:
   const_ptr() noexcept : _ptr(nullptr) {}
   const_ptr(P const & p) noexcept(detail::is_nt_cc<P>::value) : _ptr(p) {}
   const_ptr(P && p) noexcept(detail::is_nt_mc<P>::value) : _ptr(std::move(p)) {}
-  template <typename Y, typename = typename std::enable_if<std::is_constructible<P, Y>::value>::type>
-  const_ptr(Y const & p) : _ptr(p) { }
-  template <typename Y, typename = typename std::enable_if<std::is_constructible<P, Y>::value>::type>
-  const_ptr(Y && p) : _ptr(std::forward<Y>(p)) { }
+  template <typename Y, typename = typename std::enable_if<
+                            std::is_constructible<P, Y>::value>::type>
+  const_ptr(Y const & p) : _ptr(p) {}
+  template <typename Y, typename = typename std::enable_if<
+                            std::is_constructible<P, Y>::value>::type>
+  const_ptr(Y && p) : _ptr(std::forward<Y>(p)) {}
 
   template <typename Y>
-  explicit operator const_ptr<Y>() const noexcept(detail::is_nt_c<P, Y>::value) {
+  explicit operator const_ptr<Y>() const
+      noexcept(detail::is_nt_c<P, Y>::value) {
     return _ptr;
   }
-  
-  operator bool() const noexcept {
-    return static_cast<bool>(_ptr);
-  }
+
+  operator bool() const noexcept { return static_cast<bool>(_ptr); }
 
   reference operator*() const noexcept(noexcept(*_ptr)) { return *_ptr; }
-  pointer get() const noexcept(noexcept(detail::get_ptr<P>::get(_ptr))) { return detail::get_ptr<P>::get(_ptr); }
+  pointer get() const noexcept(noexcept(detail::get_ptr<P>::get(_ptr))) {
+    return detail::get_ptr<P>::get(_ptr);
+  }
   pointer operator->() const noexcept(noexcept(get())) { return get(); }
+
 private:
   P _ptr;
 };
 
-POINTER_TEMPLATE_COMPARE( const_ptr )
+POINTER_TEMPLATE_COMPARE(const_ptr)

+ 43 - 29
include/pointers/maybe_null.hpp

@@ -19,61 +19,75 @@ class unchecked_pointer_exception : public std::logic_error {
 
 template <typename P> class maybe_null<not_null<P>>; // not permitted
 
-#if defined( DEBUG )
-#define set_tested( value ) tested_ = value
+#if defined(DEBUG)
+#define set_tested(value) tested_ = value
 #else
-#define set_tested( _ )
+#define set_tested(_)
 #endif
 
-template <typename P>
-class maybe_null : private detail::get_ptr<P> {
+template <typename P> class maybe_null : private detail::get_ptr<P> {
 public:
   using element_type = typename std::pointer_traits<P>::element_type;
   using pointer = element_type *;
   using reference = element_type &;
-  
+
   maybe_null() noexcept : _ptr(nullptr) {}
-  maybe_null(P const & p) noexcept(detail::is_nt_cc<P>::value) : _ptr(p) { }
-  maybe_null(P && p) noexcept(detail::is_nt_mc<P>::value) : _ptr(std::move(p)) { }
-  template <typename Y, typename = typename std::enable_if<std::is_constructible<P, Y>::value>::type>
-  maybe_null(Y const & p) : _ptr(p) { }
-  template <typename Y, typename = typename std::enable_if<std::is_constructible<P, Y>::value>::type>
-  maybe_null(Y && p) : _ptr(std::forward<Y>(p)) { }
-  maybe_null(maybe_null const&) noexcept(detail::is_nt_cc<P>::value) = default;
+  maybe_null(P const & p) noexcept(detail::is_nt_cc<P>::value) : _ptr(p) {}
+  maybe_null(P && p) noexcept(detail::is_nt_mc<P>::value)
+      : _ptr(std::move(p)) {}
+  template <typename Y, typename = typename std::enable_if<
+                            std::is_constructible<P, Y>::value>::type>
+  maybe_null(Y const & p) : _ptr(p) {}
+  template <typename Y, typename = typename std::enable_if<
+                            std::is_constructible<P, Y>::value>::type>
+  maybe_null(Y && p) : _ptr(std::forward<Y>(p)) {}
+  maybe_null(maybe_null const &) noexcept(detail::is_nt_cc<P>::value) = default;
   maybe_null(maybe_null &&) noexcept(detail::is_nt_mc<P>::value) = default;
   template <typename Y>
-  maybe_null(maybe_null<Y> const&other) noexcept(detail::is_nt_c<P, Y>::value)
-  : _ptr(other._ptr) { set_tested(other.tested_); }
-  
-  maybe_null& operator=(maybe_null const&) noexcept(detail::is_nt_ca<P>::value) = default;
-  maybe_null& operator=(maybe_null &&) noexcept(detail::is_nt_ma<P>::value) = default;
-  
+  maybe_null(maybe_null<Y> const & other) noexcept(detail::is_nt_c<P, Y>::value)
+      : _ptr(other._ptr) {
+    set_tested(other.tested_);
+  }
+
+  maybe_null &
+  operator=(maybe_null const &) noexcept(detail::is_nt_ca<P>::value) = default;
+  maybe_null &
+  operator=(maybe_null &&) noexcept(detail::is_nt_ma<P>::value) = default;
+
   operator bool() const noexcept {
     set_tested(true);
     return static_cast<bool>(_ptr);
   }
-  
-  pointer get() const noexcept(noexcept(detail::get_ptr<P>::get(_ptr))) { return detail::get_ptr<P>::get(_ptr); }
+
+  pointer get() const noexcept(noexcept(detail::get_ptr<P>::get(_ptr))) {
+    return detail::get_ptr<P>::get(_ptr);
+  }
   pointer operator->() const /*throw(unchecked_pointer_exception)*/ {
     return std::addressof(operator*());
   }
   reference operator*() const /*throw(unchecked_pointer_exception)*/ {
-#if defined( DEBUG )
-    if ( ! tested_ ) { throw unchecked_pointer_exception{"did not verify that pointer was non-null"}; }
+#if defined(DEBUG)
+    if (!tested_) {
+      throw unchecked_pointer_exception{
+          "did not verify that pointer was non-null"};
+    }
 #endif
-    if ( ! _ptr ) { throw null_pointer_exception{"dereferencing maybe_null in null state"}; }
+    if (!_ptr) {
+      throw null_pointer_exception{"dereferencing maybe_null in null state"};
+    }
     return *_ptr;
   }
-  
-  void reset( P const & p ) { operator=(maybe_null(p)); }
-  void reset( P && p = P() ) { operator=(maybe_null(std::move(p))); }
+
+  void reset(P const & p) { operator=(maybe_null(p)); }
+  void reset(P && p = P()) { operator=(maybe_null(std::move(p))); }
+
 private:
   template <typename Y> friend class maybe_null;
   P _ptr;
-#if defined( DEBUG )
+#if defined(DEBUG)
   mutable bool tested_ = false;
 #endif
 };
 
 #undef set_tested
-POINTER_TEMPLATE_COMPARE( maybe_null )
+POINTER_TEMPLATE_COMPARE(maybe_null)

+ 30 - 21
include/pointers/not_null.hpp

@@ -10,32 +10,39 @@
 
 #include <memory>
 
+#include "maybe_null.hpp"
 #include "pointer_fwd.hpp"
 #include "ptr_compare.hpp"
-#include "maybe_null.hpp"
-
-template <typename P> class not_null<std::weak_ptr<P>>; // A weak_ptr cannot be a not_null
 
 template <typename P>
-class not_null {
+class not_null<std::weak_ptr<P>>; // A weak_ptr cannot be a not_null
+
+template <typename P> class not_null {
 public:
   using element_type = typename std::pointer_traits<P>::element_type;
   using pointer = element_type *;
   using reference = element_type &;
-  
+
   explicit not_null(std::nullptr_t) = delete;
   explicit not_null(int) = delete;
   not_null(P const & p) : _ptr(p) { validate(); }
   not_null(P && p) : _ptr(std::move(p)) { validate(); }
-  template <typename Y, typename = typename std::enable_if<std::is_constructible<P, Y>::value>::type>
-  not_null(Y const & p) : _ptr(p) { validate(); }
-  template <typename Y, typename = typename std::enable_if<std::is_constructible<P, Y>::value>::type>
-  not_null(Y && p) : _ptr(std::forward<Y>(p)) { validate(); }
-  not_null(not_null const&) noexcept(detail::is_nt_cc<P>::value) = default;
-//  not_null(not_null &&) = delete;
-  
+  template <typename Y, typename = typename std::enable_if<
+                            std::is_constructible<P, Y>::value>::type>
+  not_null(Y const & p) : _ptr(p) {
+    validate();
+  }
+  template <typename Y, typename = typename std::enable_if<
+                            std::is_constructible<P, Y>::value>::type>
+  not_null(Y && p) : _ptr(std::forward<Y>(p)) {
+    validate();
+  }
+  not_null(not_null const &) noexcept(detail::is_nt_cc<P>::value) = default;
+  not_null(not_null &&) = delete;
+
   template <typename Y>
-  explicit operator maybe_null<Y>() const noexcept(detail::is_nt_c<Y, P>::value) {
+  explicit operator maybe_null<Y>() const
+      noexcept(detail::is_nt_c<Y, P>::value) {
     return _ptr;
   }
   template <typename Y>
@@ -43,17 +50,19 @@ public:
     return _ptr;
   }
 
-  not_null& operator=(not_null const&) noexcept(detail::is_nt_ca<P>::value) = default;
-//  not_null& operator=(not_null &&) = delete;
-  
+  not_null &
+  operator=(not_null const &) noexcept(detail::is_nt_ca<P>::value) = default;
+  not_null & operator=(not_null &&) = delete;
+
   operator bool() const noexcept { return true; }
-  
+
   pointer get() const noexcept { return detail::get_ptr<P>().get(_ptr); }
   reference operator*() const noexcept { return *_ptr; }
   pointer operator->() const noexcept { return get(); }
-  
-  void reset( P const & p ) { operator=(not_null(p)); }
-  void reset( P && p ) { operator=(not_null(std::forward(p))); }
+
+  void reset(P const & p) { operator=(not_null(p)); }
+  void reset(P && p) { operator=(not_null(std::forward(p))); }
+
 private:
   void validate() {
     if (get() == nullptr) {
@@ -63,4 +72,4 @@ private:
   P _ptr;
 };
 
-POINTER_TEMPLATE_COMPARE( not_null )
+POINTER_TEMPLATE_COMPARE(not_null)

+ 19 - 21
include/pointers/pointer_fwd.hpp

@@ -22,36 +22,34 @@ class null_pointer_exception : public std::invalid_argument {
 };
 
 namespace detail {
-  template <typename P>
-  using is_nt_cc = std::is_nothrow_copy_constructible<P>;
-  template <typename P>
-  using is_nt_ca = std::is_nothrow_copy_assignable<P>;
-  template <typename P>
-  using is_nt_mc = std::is_nothrow_move_constructible<P>;
-  template <typename P>
-  using is_nt_ma = std::is_nothrow_move_assignable<P>;
+  template <typename P> using is_nt_cc = std::is_nothrow_copy_constructible<P>;
+  template <typename P> using is_nt_ca = std::is_nothrow_copy_assignable<P>;
+  template <typename P> using is_nt_mc = std::is_nothrow_move_constructible<P>;
+  template <typename P> using is_nt_ma = std::is_nothrow_move_assignable<P>;
   template <typename P, typename Y>
   using is_nt_c = std::is_nothrow_constructible<P, Y>;
   template <typename P, typename Y>
   using is_nt_a = std::is_nothrow_assignable<P, Y>;
-  
-  template <typename P, typename = void>
-  struct get_ptr {
-    decltype(std::declval<P>().get()) get( P const & ptr ) const { return std::addressof(*ptr); }
+
+  template <typename P, typename = void> struct get_ptr {
+    decltype(std::declval<P>().get()) get(P const & ptr) const {
+      return std::addressof(*ptr);
+    }
   };
-  
-  template <typename T>
-  struct get_ptr<std::weak_ptr<T>> {
-    void get( std::weak_ptr<T> const & ptr ) throw();
+
+  template <typename T> struct get_ptr<std::weak_ptr<T>> {
+    void get(std::weak_ptr<T> const & ptr) throw();
   };
 
-  template <typename T>
-  struct get_ptr<T*> {
-    T* get( T* ptr ) const { return ptr; }
+  template <typename T> struct get_ptr<T *> {
+    T * get(T * ptr) const { return ptr; }
   };
 
   template <typename P>
-  struct get_ptr<P, typename std::enable_if<!std::is_void<decltype(std::declval<P>().get())>::value>::type> {
-    decltype(std::declval<P>().get()) get( P const & ptr ) const { return ptr.get(); }
+  struct get_ptr<P, typename std::enable_if<!std::is_void<decltype(
+                        std::declval<P>().get())>::value>::type> {
+    decltype(std::declval<P>().get()) get(P const & ptr) const {
+      return ptr.get();
+    }
   };
 }

+ 104 - 98
include/pointers/ptr_compare.hpp

@@ -7,103 +7,109 @@
 
 #pragma once
 
-#define POINTER_TEMPLATE_COMPARE( ptr_t ) \
-  POINTER_TEMPLATE_COMPARE_FULL( ptr_t, (typename T), (T), (typename U), (U) )
+#define POINTER_TEMPLATE_COMPARE(ptr_t)                                        \
+  POINTER_TEMPLATE_COMPARE_FULL(ptr_t, (typename T), (T), (typename U), (U))
 
-#define EXPAND( ... ) __VA_ARGS__
+#define EXPAND(...) __VA_ARGS__
 
-#define POINTER_TEMPLATE_COMPARE_FULL( ptr_t, T_tname, T, U_tname, U ) \
-template <EXPAND T_tname, EXPAND U_tname> \
-bool operator==(ptr_t< EXPAND T > const&lhs, ptr_t< EXPAND U > const&rhs) noexcept { \
-  return lhs.get() == rhs.get(); \
-} \
-\
-template <EXPAND T_tname, EXPAND U_tname> \
-bool operator!=(ptr_t< EXPAND T > const&lhs, ptr_t< EXPAND U > const&rhs) noexcept { \
-  return !(lhs == rhs); \
-} \
-\
-template <EXPAND T_tname, EXPAND U_tname> \
-bool operator< (ptr_t< EXPAND T > const&lhs, ptr_t< EXPAND U > const&rhs) noexcept { \
-  typedef typename std::common_type< \
-  typename ptr_t< EXPAND T >::pointer, \
-  typename ptr_t< EXPAND U >::pointer>::type V; \
-  return std::less<V>(lhs.get(), rhs.get()); \
-} \
-\
-template <EXPAND T_tname, EXPAND U_tname> \
-bool operator> (ptr_t< EXPAND T > const&lhs, ptr_t< EXPAND U > const&rhs) noexcept { \
-  return rhs < lhs; \
-} \
-\
-template <EXPAND T_tname, EXPAND U_tname> \
-bool operator<=(ptr_t< EXPAND T > const&lhs, ptr_t< EXPAND U > const&rhs) noexcept { \
-  return !(rhs < lhs); \
-} \
-\
-template <EXPAND T_tname, EXPAND U_tname> \
-bool operator>=(ptr_t< EXPAND T > const&lhs, ptr_t< EXPAND U > const&rhs) noexcept { \
-  return !(lhs < rhs); \
-} \
-\
-template <EXPAND T_tname> \
-bool operator==(ptr_t< EXPAND T > const&lhs, std::nullptr_t) noexcept { \
-  return !lhs; \
-} \
-\
-template <EXPAND T_tname> \
-bool operator==(std::nullptr_t, ptr_t< EXPAND T > const&rhs) noexcept { \
-  return !rhs; \
-} \
-\
-template <EXPAND T_tname> \
-bool operator!=(ptr_t< EXPAND T > const&lhs, std::nullptr_t) noexcept { \
-  return static_cast<bool>(lhs); \
-} \
-\
-template <EXPAND T_tname> \
-bool operator!=(std::nullptr_t, ptr_t< EXPAND T > const&rhs) noexcept { \
-  return static_cast<bool>(rhs); \
-} \
-\
-template <EXPAND T_tname> \
-bool operator< (ptr_t< EXPAND T > const&lhs, std::nullptr_t) noexcept { \
-  typedef typename ptr_t< EXPAND T >::pointer V; \
-  return std::less<V>(lhs.get(), nullptr); \
-} \
-\
-template <EXPAND T_tname> \
-bool operator< (std::nullptr_t, ptr_t< EXPAND T > const&rhs) noexcept { \
-  typedef typename ptr_t< EXPAND T >::pointer V; \
-  return std::less<V>(nullptr, rhs.get()); \
-} \
-\
-template <EXPAND T_tname> \
-bool operator> (ptr_t< EXPAND T > const&lhs, std::nullptr_t) noexcept { \
-  return nullptr < lhs; \
-} \
-\
-template <EXPAND T_tname> \
-bool operator> (std::nullptr_t, ptr_t< EXPAND T > const&rhs) noexcept { \
-  return rhs < nullptr; \
-} \
-\
-template <EXPAND T_tname> \
-bool operator<=(ptr_t< EXPAND T > const&lhs, std::nullptr_t) noexcept { \
-  return !(nullptr < lhs); \
-} \
-\
-template <EXPAND T_tname> \
-bool operator<=(std::nullptr_t, ptr_t< EXPAND T > const&rhs) noexcept { \
-  return !(rhs < nullptr); \
-} \
-\
-template <EXPAND T_tname> \
-bool operator>=(ptr_t< EXPAND T > const&lhs, std::nullptr_t) noexcept { \
-  return !(lhs < nullptr); \
-} \
-\
-template <EXPAND T_tname> \
-bool operator>=(std::nullptr_t, ptr_t< EXPAND T > const&rhs) noexcept { \
-  return !(nullptr < rhs); \
-}
+#define POINTER_TEMPLATE_COMPARE_FULL(ptr_t, T_tname, T, U_tname, U)           \
+  template <EXPAND T_tname, EXPAND U_tname>                                    \
+  bool operator==(ptr_t<EXPAND T> const & lhs,                                 \
+                  ptr_t<EXPAND U> const & rhs) noexcept {                      \
+    return lhs.get() == rhs.get();                                             \
+  }                                                                            \
+                                                                               \
+  template <EXPAND T_tname, EXPAND U_tname>                                    \
+  bool operator!=(ptr_t<EXPAND T> const & lhs,                                 \
+                  ptr_t<EXPAND U> const & rhs) noexcept {                      \
+    return !(lhs == rhs);                                                      \
+  }                                                                            \
+                                                                               \
+  template <EXPAND T_tname, EXPAND U_tname>                                    \
+  bool operator<(ptr_t<EXPAND T> const & lhs,                                  \
+                 ptr_t<EXPAND U> const & rhs) noexcept {                       \
+    typedef                                                                    \
+        typename std::common_type<typename ptr_t<EXPAND T>::pointer,           \
+                                  typename ptr_t<EXPAND U>::pointer>::type V;  \
+    return std::less<V>(lhs.get(), rhs.get());                                 \
+  }                                                                            \
+                                                                               \
+  template <EXPAND T_tname, EXPAND U_tname>                                    \
+  bool operator>(ptr_t<EXPAND T> const & lhs,                                  \
+                 ptr_t<EXPAND U> const & rhs) noexcept {                       \
+    return rhs < lhs;                                                          \
+  }                                                                            \
+                                                                               \
+  template <EXPAND T_tname, EXPAND U_tname>                                    \
+  bool operator<=(ptr_t<EXPAND T> const & lhs,                                 \
+                  ptr_t<EXPAND U> const & rhs) noexcept {                      \
+    return !(rhs < lhs);                                                       \
+  }                                                                            \
+                                                                               \
+  template <EXPAND T_tname, EXPAND U_tname>                                    \
+  bool operator>=(ptr_t<EXPAND T> const & lhs,                                 \
+                  ptr_t<EXPAND U> const & rhs) noexcept {                      \
+    return !(lhs < rhs);                                                       \
+  }                                                                            \
+                                                                               \
+  template <EXPAND T_tname>                                                    \
+  bool operator==(ptr_t<EXPAND T> const & lhs, std::nullptr_t) noexcept {      \
+    return !lhs;                                                               \
+  }                                                                            \
+                                                                               \
+  template <EXPAND T_tname>                                                    \
+  bool operator==(std::nullptr_t, ptr_t<EXPAND T> const & rhs) noexcept {      \
+    return !rhs;                                                               \
+  }                                                                            \
+                                                                               \
+  template <EXPAND T_tname>                                                    \
+  bool operator!=(ptr_t<EXPAND T> const & lhs, std::nullptr_t) noexcept {      \
+    return static_cast<bool>(lhs);                                             \
+  }                                                                            \
+                                                                               \
+  template <EXPAND T_tname>                                                    \
+  bool operator!=(std::nullptr_t, ptr_t<EXPAND T> const & rhs) noexcept {      \
+    return static_cast<bool>(rhs);                                             \
+  }                                                                            \
+                                                                               \
+  template <EXPAND T_tname>                                                    \
+  bool operator<(ptr_t<EXPAND T> const & lhs, std::nullptr_t) noexcept {       \
+    typedef typename ptr_t<EXPAND T>::pointer V;                               \
+    return std::less<V>(lhs.get(), nullptr);                                   \
+  }                                                                            \
+                                                                               \
+  template <EXPAND T_tname>                                                    \
+  bool operator<(std::nullptr_t, ptr_t<EXPAND T> const & rhs) noexcept {       \
+    typedef typename ptr_t<EXPAND T>::pointer V;                               \
+    return std::less<V>(nullptr, rhs.get());                                   \
+  }                                                                            \
+                                                                               \
+  template <EXPAND T_tname>                                                    \
+  bool operator>(ptr_t<EXPAND T> const & lhs, std::nullptr_t) noexcept {       \
+    return nullptr < lhs;                                                      \
+  }                                                                            \
+                                                                               \
+  template <EXPAND T_tname>                                                    \
+  bool operator>(std::nullptr_t, ptr_t<EXPAND T> const & rhs) noexcept {       \
+    return rhs < nullptr;                                                      \
+  }                                                                            \
+                                                                               \
+  template <EXPAND T_tname>                                                    \
+  bool operator<=(ptr_t<EXPAND T> const & lhs, std::nullptr_t) noexcept {      \
+    return !(nullptr < lhs);                                                   \
+  }                                                                            \
+                                                                               \
+  template <EXPAND T_tname>                                                    \
+  bool operator<=(std::nullptr_t, ptr_t<EXPAND T> const & rhs) noexcept {      \
+    return !(rhs < nullptr);                                                   \
+  }                                                                            \
+                                                                               \
+  template <EXPAND T_tname>                                                    \
+  bool operator>=(ptr_t<EXPAND T> const & lhs, std::nullptr_t) noexcept {      \
+    return !(lhs < nullptr);                                                   \
+  }                                                                            \
+                                                                               \
+  template <EXPAND T_tname>                                                    \
+  bool operator>=(std::nullptr_t, ptr_t<EXPAND T> const & rhs) noexcept {      \
+    return !(nullptr < rhs);                                                   \
+  }

+ 37 - 35
include/pointers/value_ptr.hpp

@@ -13,53 +13,56 @@
 #include "ptr_compare.hpp"
 
 namespace detail {
+  template <typename T> using clone_func = T * (T::*)() const;
+
+  template <typename T, typename = void> class value_ptr_copy;
+
   template <typename T>
-  using clone_func = T* (T::*)() const;
-  
-  template <typename T, typename = void>
-  class value_ptr_copy;
-  
-  template <typename T>
-  struct value_ptr_copy<T, typename std::enable_if<!std::is_polymorphic<T>::value>::type> {
-    T * Copy( T * ptr ) const { return ptr ? new T(*ptr) : nullptr; }
+  struct value_ptr_copy<T, std::enable_if_t<!std::is_polymorphic<T>::value>> {
+    T * Copy(T * ptr) const { return ptr ? new T(*ptr) : nullptr; }
   };
 
-#define POLYMORPHIC_VALUE_PTR_GROUP_FROM_CLONE_FUNCTION( fclone ) \
-  template <typename T> \
-  struct value_ptr_copy<T, typename std::enable_if<std::is_polymorphic<T>::value \
-      && std::is_same<clone_func<T>, decltype(&T::fclone)>::value>::type> { \
-    T * Copy( T * ptr ) const { return ptr ? ptr->fclone() : nullptr; } \
+#define POLYMORPHIC_VALUE_PTR_GROUP_FROM_CLONE_FUNCTION(fclone)                \
+  template <typename T>                                                        \
+  struct value_ptr_copy<                                                       \
+      T, std::enable_if_t<                                                     \
+             std::is_polymorphic<T>::value &&                                  \
+             std::is_same<clone_func<T>, decltype(&T::fclone)>::value>> {      \
+    T * Copy(T * ptr) const { return ptr ? ptr->fclone() : nullptr; }          \
   }
 
-  POLYMORPHIC_VALUE_PTR_GROUP_FROM_CLONE_FUNCTION( Clone );
-  POLYMORPHIC_VALUE_PTR_GROUP_FROM_CLONE_FUNCTION( clone );
-  POLYMORPHIC_VALUE_PTR_GROUP_FROM_CLONE_FUNCTION( Copy );
-  POLYMORPHIC_VALUE_PTR_GROUP_FROM_CLONE_FUNCTION( copy );
+  POLYMORPHIC_VALUE_PTR_GROUP_FROM_CLONE_FUNCTION(Clone);
+  POLYMORPHIC_VALUE_PTR_GROUP_FROM_CLONE_FUNCTION(clone);
+  POLYMORPHIC_VALUE_PTR_GROUP_FROM_CLONE_FUNCTION(Copy);
+  POLYMORPHIC_VALUE_PTR_GROUP_FROM_CLONE_FUNCTION(copy);
 }
 
-template <typename T>
-class value_ptr : private detail::value_ptr_copy<T> {
+template <typename T> class value_ptr : private detail::value_ptr_copy<T> {
 public:
   using element_type = T;
   using pointer = element_type *;
   using reference = element_type &;
-  
+
   value_ptr() noexcept : _ptr(nullptr) {}
   value_ptr(T * const & p) = delete;
-  value_ptr(T * && p) noexcept(detail::is_nt_mc<T>::value) : _ptr(std::move(p)) {}
-  value_ptr(value_ptr const & other) : _ptr(detail::value_ptr_copy<T>::Copy(other._ptr)) {}
-  value_ptr(value_ptr && other) noexcept(noexcept(std::swap(_ptr, other._ptr))) : _ptr(nullptr) { std::swap(_ptr, other._ptr); }
+  value_ptr(T *&& p) noexcept(detail::is_nt_mc<T>::value)
+      : _ptr(std::move(p)) {}
+  value_ptr(value_ptr const & other)
+      : _ptr(detail::value_ptr_copy<T>::Copy(other._ptr)) {}
+  value_ptr(value_ptr && other) noexcept(noexcept(std::swap(_ptr, other._ptr)))
+      : _ptr(nullptr) {
+    std::swap(_ptr, other._ptr);
+  }
   static value_ptr copy_of(T * const & p) {
     return detail::value_ptr_copy<T>().Copy(p);
   }
-  
-  template <typename Y>
-  explicit operator value_ptr<Y>() const {
+
+  template <typename Y> explicit operator value_ptr<Y>() const {
     return Copy(_ptr);
   }
-  
+
   ~value_ptr() { delete _ptr; }
-  
+
   value_ptr & operator=(value_ptr const & other) {
     swap(_ptr, value_ptr{other}._ptr);
     return *this;
@@ -68,16 +71,15 @@ public:
     swap(_ptr, other._ptr);
     return *this;
   }
-  
-  operator bool() const noexcept {
-    return static_cast<bool>(_ptr);
-  }
-  
+
+  operator bool() const noexcept { return static_cast<bool>(_ptr); }
+
   pointer get() const noexcept { return _ptr; }
   pointer operator->() const noexcept { return get(); }
   reference operator*() const noexcept { return *get(); }
+
 private:
-  static void swap( T * a, T * b ) {
+  static void swap(T * a, T * b) {
     T * tmp = a;
     a = b;
     b = tmp;
@@ -90,4 +92,4 @@ value_ptr<T> make_value(Args &&... args) {
   return value_ptr<T>(new T(std::forward<Args>(args)...));
 }
 
-POINTER_TEMPLATE_COMPARE( value_ptr )
+POINTER_TEMPLATE_COMPARE(value_ptr)

+ 1 - 1
test/const_ptr_test.cxx

@@ -5,8 +5,8 @@
 //  Created by Sam Jaffe on 1/5/17.
 //
 
-#include "pointers/const_ptr.hpp"
 #include "pointers/const_propogating_ptr.hpp"
+#include "pointers/const_ptr.hpp"
 
 #include <gmock/gmock.h>
 

+ 2 - 2
test/maybe_null_test.cxx

@@ -45,8 +45,8 @@ TEST(MaybeNullPtrTest, UpcastedPointerStillEqual) {
   struct base {};
   struct derived : public base {};
   derived d;
-  maybe_null<derived*> m{&d};
-  maybe_null<base*> b = m;
+  maybe_null<derived *> m{&d};
+  maybe_null<base *> b = m;
   EXPECT_THAT(b.get(), m.get());
 }
 

+ 11 - 11
test/value_ptr_test.cxx

@@ -17,7 +17,7 @@ struct copy_me {};
 struct copy_me_throw {};
 
 namespace detail {
-  template<> class value_ptr_copy<copy_me_throw> {
+  template <> class value_ptr_copy<copy_me_throw> {
   protected:
     copy_me_throw * Copy(copy_me_throw const * p) const {
       if (p == nullptr) { throw std::runtime_error{"NULL"}; }
@@ -29,7 +29,7 @@ namespace detail {
 class base {
 public:
   virtual ~base() {}
-  virtual base* clone() const = 0;
+  virtual base * clone() const = 0;
   virtual int id() const = 0;
 };
 
@@ -48,8 +48,8 @@ public:
 };
 
 TEST(ValuePtrTest, CanCopySimpleObject) {
-  value_ptr<copy_me> c1 {new copy_me};
-  value_ptr<copy_me> c2 {c1};
+  value_ptr<copy_me> c1{new copy_me};
+  value_ptr<copy_me> c2{c1};
   EXPECT_THAT(c1.get(), testing::Not(c2.get()));
 }
 
@@ -62,8 +62,8 @@ TEST(ValuePtrTest, CopyCtorIsNullSafe) {
 
 TEST(ValuePtrCustomTest, CanCopyWithCustomFunction) {
   using ptr_t = value_ptr<copy_me_throw>;
-  value_ptr<copy_me_throw> c1 {new copy_me_throw};
-  value_ptr<copy_me_throw> c2 {c1};
+  value_ptr<copy_me_throw> c1{new copy_me_throw};
+  value_ptr<copy_me_throw> c2{c1};
   EXPECT_THAT(c1.get(), testing::Not(c2.get()));
 }
 
@@ -73,7 +73,7 @@ TEST(ValuePtrCustomTest, CustomCopyFunctionCanThrow) {
 }
 
 TEST(ValuePtrTest, CopiedValueDeeplyEqualButNotSameAddress) {
-  std::vector<int> my_vec = { 1, 3, 5, 3, 6, 1, 2, -1, 0 };
+  std::vector<int> my_vec = {1, 3, 5, 3, 6, 1, 2, -1, 0};
   value_ptr<std::vector<int>> c1{new std::vector<int>{my_vec}};
   EXPECT_THAT(*c1, my_vec);
   value_ptr<std::vector<int>> c2{c1};
@@ -89,8 +89,8 @@ TEST(ValuePtrPolymorphicTest, CanConstructPtrToBaseFromDerivedClasses) {
 }
 
 TEST(ValuePtrPolymorphicTest, CanConstructFromNullptr) {
-  value_ptr<base> c1 {nullptr};
-  value_ptr<base> c2 {c1};
+  value_ptr<base> c1{nullptr};
+  value_ptr<base> c2{c1};
   EXPECT_THAT(c1.get(), testing::IsNull());
   EXPECT_THAT(c1.get(), c2.get());
 }
@@ -105,8 +105,8 @@ TEST(ValuePtrTest, OwnsGivenObject) {
 
 TEST(ValuePtrTest, OwnsTemporaryObject) {
   bool has_delete{false};
-  EXPECT_NO_THROW(value_ptr<destructor_sentinal>{
-    new destructor_sentinal{has_delete}});
+  EXPECT_NO_THROW(
+      value_ptr<destructor_sentinal>{new destructor_sentinal{has_delete}});
   EXPECT_TRUE(has_delete);
 }