[Bf-blender-cvs] [6bfa473b603] functions: simplify StringRef operator overloads

Jacques Lucke noreply at git.blender.org
Mon Jul 8 17:57:07 CEST 2019


Commit: 6bfa473b603833a01ad31d49600b6f36dfbae574
Author: Jacques Lucke
Date:   Mon Jul 8 14:02:19 2019 +0200
Branches: functions
https://developer.blender.org/rB6bfa473b603833a01ad31d49600b6f36dfbae574

simplify StringRef operator overloads

===================================================================

M	source/blender/blenlib/BLI_string_ref.hpp

===================================================================

diff --git a/source/blender/blenlib/BLI_string_ref.hpp b/source/blender/blenlib/BLI_string_ref.hpp
index b9555aed5a3..e722d9cfe98 100644
--- a/source/blender/blenlib/BLI_string_ref.hpp
+++ b/source/blender/blenlib/BLI_string_ref.hpp
@@ -87,65 +87,6 @@ class StringRefBase {
   {
     return std::string(m_data, m_size);
   }
-
-  friend std::ostream &operator<<(std::ostream &stream, StringRefBase ref)
-  {
-    stream << ref.to_std_string();
-    return stream;
-  }
-
-  friend std::string operator+(const StringRefBase a, const StringRefBase b)
-  {
-    return a.to_std_string() + b.data();
-  }
-
-  friend std::string operator+(const char *a, const StringRefBase b)
-  {
-    return a + b.to_std_string();
-  }
-
-  friend std::string operator+(const StringRefBase a, const char *b)
-  {
-    return a.to_std_string() + b;
-  }
-
-  friend std::string operator+(const std::string &a, const StringRefBase b)
-  {
-    return a + b.data();
-  }
-
-  friend std::string operator+(const StringRefBase a, const std::string &b)
-  {
-    return a.data() + b;
-  }
-
-  friend bool operator==(const StringRefBase a, const StringRefBase b)
-  {
-    if (a.size() != b.size()) {
-      return false;
-    }
-    return STREQLEN(a.data(), b.data(), a.size());
-  }
-
-  friend bool operator==(const StringRefBase a, const char *b)
-  {
-    return STREQ(a.data(), b);
-  }
-
-  friend bool operator==(const char *a, const StringRefBase b)
-  {
-    return b == a;
-  }
-
-  friend bool operator==(const StringRefBase a, const std::string &b)
-  {
-    return a == StringRefBase(b.data(), b.size());
-  }
-
-  friend bool operator==(const std::string &a, const StringRefBase b)
-  {
-    return b == a;
-  }
 };
 
 class StringRefNull : public StringRefBase {
@@ -197,6 +138,25 @@ class StringRef : public StringRefBase {
 /* More inline functions
  ***************************************/
 
+inline std::ostream &operator<<(std::ostream &stream, StringRef ref)
+{
+  stream << ref.to_std_string();
+  return stream;
+}
+
+inline std::string operator+(StringRef a, StringRef b)
+{
+  return a.to_std_string() + b.to_std_string();
+}
+
+inline bool operator==(StringRef a, StringRef b)
+{
+  if (a.size() != b.size()) {
+    return false;
+  }
+  return STREQLEN(a.data(), b.data(), a.size());
+}
+
 inline bool StringRefBase::startswith(StringRef prefix) const
 {
   if (m_size < prefix.m_size) {



More information about the Bf-blender-cvs mailing list