[glibmm/wip/dboles/ustring_format_fold_and_test] ustring: Avoid un(necessary|clear) ptr @ Stringify



commit c4de7256ad414e31c00cafda3b98ab7757188f0e
Author: Daniel Boles <dboles src gnome org>
Date:   Sun Oct 14 14:27:36 2018 +0100

    ustring: Avoid un(necessary|clear) ptr @ Stringify
    
    Rather than storing a pointer in the temporary Stringify objects, we can
    instead store a reference, which is clearer about it being non-optional
    and makes for nicer syntax. Then we return that and use operator& when
    forwarding it to compose_private() in the std::initializer_list, since
    containers can't hold references, so we do need a pointer there. Unless:
    
    We could perhaps go a step further and make that an initializer_list of
    std::reference_wrapper, avoiding pointers altogether while probably not
    incurring overhead as it is a simple wrapper, but that's one for later.

 glib/glibmm/ustring.h | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
---
diff --git a/glib/glibmm/ustring.h b/glib/glibmm/ustring.h
index 145e2d52..e7b91b69 100644
--- a/glib/glibmm/ustring.h
+++ b/glib/glibmm/ustring.h
@@ -1081,7 +1081,7 @@ public:
   Stringify(const ustring::Stringify<T>&) = delete;
   Stringify<T>& operator=(const ustring::Stringify<T>&) = delete;
 
-  inline const ustring* ptr() const { return &string_; }
+  inline const ustring& ref() const { return string_; }
 };
 
 /// A template specialization for Stringify<ustring>:
@@ -1098,7 +1098,7 @@ public:
   Stringify(const ustring::Stringify<ustring>&) = delete;
   Stringify<ustring>& operator=(const ustring::Stringify<ustring>&) = delete;
 
-  inline const ustring* ptr() const { return &string_; }
+  inline const ustring& ref() const { return string_; }
 };
 
 /** A template specialization for Stringify<const char*>,
@@ -1117,7 +1117,7 @@ public:
   Stringify(const ustring::Stringify<const char*>&) = delete;
   Stringify<ustring>& operator=(const ustring::Stringify<const char*>&) = delete;
 
-  inline const ustring* ptr() const { return &string_; }
+  inline const ustring& ref() const { return string_; }
 };
 
 /** A template specialization for Stringify<char[N]> (for string literals),
@@ -1136,7 +1136,7 @@ public:
   Stringify(const ustring::Stringify<char[N]>&) = delete;
   Stringify<ustring>& operator=(const ustring::Stringify<char[N]>&) = delete;
 
-  inline const ustring* ptr() const { return &string_; }
+  inline const ustring& ref() const { return string_; }
 };
 
 /** A template specialization for Stringify<const char[N]> (for string literals),
@@ -1156,7 +1156,7 @@ public:
   Stringify(const ustring::Stringify<const char[N]>&) = delete;
   Stringify<ustring>& operator=(const ustring::Stringify<const char[N]>&) = delete;
 
-  inline const ustring* ptr() const { return &string_; }
+  inline const ustring& ref() const { return string_; }
 };
 
 inline // static
@@ -1174,7 +1174,7 @@ inline // static
   static_assert(sizeof...(Ts) <= 9,
                 "ustring::compose only supports up to 9 placeholders.");
 
-  return compose_private(fmt, { Stringify<Ts>(args).ptr()... });
+  return compose_private(fmt, {&Stringify<Ts>(args).ref()...});
 }
 
 #endif /* DOXYGEN_SHOULD_SKIP_THIS */


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