[gjs: 9/12] jsapi-util: Mark some GjsAutoPointer operations as constexpr




commit 7f8cd63e7adfac3c0843406af4a93249e5a94705
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Wed Sep 2 22:22:58 2020 +0200

    jsapi-util: Mark some GjsAutoPointer operations as constexpr
    
    Most of them are just acces operators, so we can mark it clearer to the
    compiler.

 gjs/jsapi-util.h | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
---
diff --git a/gjs/jsapi-util.h b/gjs/jsapi-util.h
index 19a31802..315f3248 100644
--- a/gjs/jsapi-util.h
+++ b/gjs/jsapi-util.h
@@ -68,15 +68,17 @@ struct GjsAutoPointer : std::unique_ptr<T, decltype(free_func)> {
         this->reset(ptr && ref ? reinterpret_cast<T*>(ref(ptr)) : ptr);
     }
 
-    operator T*() const { return this->get(); }
-    T& operator[](size_t i) const { return static_cast<T*>(*this)[i]; }
+    constexpr operator T*() const { return this->get(); }
+    constexpr T& operator[](size_t i) const {
+        return static_cast<T*>(*this)[i];
+    }
 
-    [[nodiscard]] T* copy() const {
+    [[nodiscard]] constexpr T* copy() const {
         return reinterpret_cast<T*>(ref_func(this->get()));
     }
 
     template <typename C>
-    [[nodiscard]] C* as() const {
+    [[nodiscard]] constexpr C* as() const {
         return const_cast<C*>(reinterpret_cast<const C*>(this->get()));
     }
 };


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]