aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2022-02-20 22:04:19 -0800
committerChris Robinson <[email protected]>2022-02-20 22:04:19 -0800
commit6c643e59e94ee14d6c8509d46a39ed6a53f72a76 (patch)
tree55d15ed688cf69ac0243911dcc01d938ad9560f4 /common
parent023ad6320be73d1cee3facad1722e94d7258f2bb (diff)
Make a couple more operator bools explicit
Diffstat (limited to 'common')
-rw-r--r--common/comptr.h2
-rw-r--r--common/intrusive_ptr.h2
-rw-r--r--common/opthelpers.h14
3 files changed, 12 insertions, 6 deletions
diff --git a/common/comptr.h b/common/comptr.h
index c238991a..ab9d4c53 100644
--- a/common/comptr.h
+++ b/common/comptr.h
@@ -49,7 +49,7 @@ public:
return *this;
}
- operator bool() const noexcept { return mPtr != nullptr; }
+ explicit operator bool() const noexcept { return mPtr != nullptr; }
T& operator*() const noexcept { return *mPtr; }
T* operator->() const noexcept { return mPtr; }
diff --git a/common/intrusive_ptr.h b/common/intrusive_ptr.h
index cc82dea5..e1fc1f7b 100644
--- a/common/intrusive_ptr.h
+++ b/common/intrusive_ptr.h
@@ -74,7 +74,7 @@ public:
return *this;
}
- operator bool() const noexcept { return mPtr != nullptr; }
+ explicit operator bool() const noexcept { return mPtr != nullptr; }
T& operator*() const noexcept { return *mPtr; }
T* operator->() const noexcept { return mPtr; }
diff --git a/common/opthelpers.h b/common/opthelpers.h
index 5e6f54cf..0b8b8210 100644
--- a/common/opthelpers.h
+++ b/common/opthelpers.h
@@ -12,16 +12,22 @@
* is not required to be true, but it can result in more optimal code for the
* true path at the expense of a less optimal false path.
*/
-constexpr bool likely(bool expr) { return __builtin_expect(expr, true); }
+template<typename T>
+constexpr bool likely(T&& expr) noexcept
+{ return __builtin_expect(static_cast<bool>(expr), true); }
/* The opposite of likely(), optimizing for the case where the condition is
* false.
*/
-constexpr bool unlikely(bool expr) { return __builtin_expect(expr, false); }
+template<typename T>
+constexpr bool unlikely(T&& expr) noexcept
+{ return __builtin_expect(static_cast<bool>(expr), false); }
#else
-constexpr bool likely(bool expr) { return expr; }
-constexpr bool unlikely(bool expr) { return expr; }
+template<typename T>
+constexpr bool likely(T&& expr) noexcept { return static_cast<bool>(expr); }
+template<typename T>
+constexpr bool unlikely(T&& expr) noexcept { return static_cast<bool>(expr); }
#endif
#define LIKELY(x) (likely(x))
#define UNLIKELY(x) (unlikely(x))