summaryrefslogtreecommitdiff
path: root/glib
diff options
context:
space:
mode:
authorKjell Ahlstedt <kjellahlstedt@gmail.com>2019-10-23 20:05:01 +0200
committerKjell Ahlstedt <kjellahlstedt@gmail.com>2019-10-23 20:05:01 +0200
commitaab148b11b160001e2503859b8fe7c954bce0478 (patch)
tree246a51b6d3676b12784806ddc238d0467cd74e27 /glib
parent8d1c0209be149e6d80e9043c95466795a9f62484 (diff)
downloadglibmm-aab148b11b160001e2503859b8fe7c954bce0478.tar.gz
Glib: Replace BasicStringView with non-template StringView
A call to path_get_dirname(StdStringView filename) with a Glib::ustring fails if StdStringView does not have a constructor that takes a const Glib::ustring&. StdStringView and UStringView are now aliases of StringView, whose names show which data type is preferred. See issue #34
Diffstat (limited to 'glib')
-rw-r--r--glib/glibmm/ustring.h36
1 files changed, 20 insertions, 16 deletions
diff --git a/glib/glibmm/ustring.h b/glib/glibmm/ustring.h
index 722fe77b..6d9b7ff6 100644
--- a/glib/glibmm/ustring.h
+++ b/glib/glibmm/ustring.h
@@ -1562,15 +1562,11 @@ operator+(char lhs, const ustring& rhs)
return temp;
}
-//************* Glib::BasicStringView ********************
+//************* Glib::StringView ********************
-// It would be possible to replace StdStringView and UStringView with one
-// non-template class StringView, having 3 constructors taking a const Glib::ustring&,
-// a const std::string& and a const char*, respectively. But such a StringView
-// would give no hint to users where to use Glib::ustring, and where to use std::string.
/** Helper class to avoid unnecessary string copying in function calls.
*
- * A %BasicStringView holds a const char pointer. It can be used as an argument
+ * A %Glib::StringView holds a const char pointer. It can be used as an argument
* type in a function that passes a const char pointer to a C function.
* @code
* // Use
@@ -1588,26 +1584,34 @@ operator+(char lhs, const ustring& rhs)
*
* @newin{2,64}
*/
-template <typename T>
-class BasicStringView
+class StringView
{
public:
- BasicStringView(const T& s) : pstring_(s.c_str()) {}
- BasicStringView(const char* s) : pstring_(s) {}
+ StringView(const std::string& s) : pstring_(s.c_str()) {}
+ StringView(const Glib::ustring& s) : pstring_(s.c_str()) {}
+ StringView(const char* s) : pstring_(s) {}
const char* c_str() const { return pstring_; }
private:
const char* pstring_;
};
-/** Recommended data types: std::string, const char*
- * @relates Glib::BasicStringView
+/** %Glib::StringView alias.
+ *
+ * The name %Glib::StdStringView signals that recommended data types are
+ * std::string and const char*, but not Glib::ustring.
+ *
+ * @relates Glib::StringView
*/
-using StdStringView = BasicStringView<std::string>;
+using StdStringView = StringView;
-/** Recommended data types: Glib::ustring, const char*
- * @relates Glib::BasicStringView
+/** %Glib::StringView alias.
+ *
+ * The name %Glib::UStringView signals that recommended data types are
+ * Glib::ustring and const char*, but not std::string.
+ *
+ * @relates Glib::StringView
*/
-using UStringView = BasicStringView<Glib::ustring>;
+using UStringView = StringView;
} // namespace Glib