Browse Source

refactor: make underlying_type a reference
refactor: make cast operator explicit

Sam Jaffe 2 years ago
parent
commit
0bdbe3a64f
2 changed files with 5 additions and 5 deletions
  1. 2 2
      include/math/dyn_limit.h
  2. 3 3
      include/math/limit.h

+ 2 - 2
include/math/dyn_limit.h

@@ -15,7 +15,7 @@ namespace math {
 template <typename T, typename B = T> class DynBound final {
 public:
   using value_type = T;
-  using underlying_type = value_type;
+  using underlying_type = value_type const &;
   using bound_type = B;
 
 private:
@@ -34,7 +34,7 @@ public:
       : lower_bound_(MINIMUM_VALUE), upper_bound_(MAXIMUM_VALUE),
         value_(other) {}
 
-  operator value_type const &() const { return value_; }
+  explicit operator value_type const &() const { return value_; }
   value_type const &operator*() const { return value_; }
   value_type const *operator->() const { return &value_; }
   

+ 3 - 3
include/math/limit.h

@@ -24,7 +24,7 @@ public:
                 "The minimum value must be less than or equal to the maximum");
 
   using value_type = T;
-  using underlying_type = value_type;
+  using underlying_type = value_type const &;
   using bound_type =
       std::common_type_t<decltype(MAXIMUM_VALUE), decltype(MINIMUM_VALUE)>;
 
@@ -41,12 +41,12 @@ public:
 
   Bound(AssertBounds, value_type val) : value_(assert_in_bounds(val, min, max)) {}
 
-  operator value_type const &() const { return value_; }
+  explicit operator value_type const &() const { return value_; }
   value_type const &operator*() const { return value_; }
   value_type const *operator->() const { return &value_; }
 
   auto operator<=>(Bound const &other) const noexcept = default;
-  
+
   template <typename F> void mutate(F &&func) {
     std::forward<F>(func)(value_);
     *this = Bound(value_);