diff options
author | Kjell Ahlstedt <kjellahlstedt@gmail.com> | 2020-03-16 10:18:24 +0100 |
---|---|---|
committer | Kjell Ahlstedt <kjellahlstedt@gmail.com> | 2020-03-16 10:18:24 +0100 |
commit | 36e765338a11897e3c22814086685ab406fbed79 (patch) | |
tree | 5fa3e5f4e11189d741b08c69e4eb9b29d1dc5200 | |
parent | 3eb7904b573985355093557081b70de6fe72f6f3 (diff) | |
download | glibmm-36e765338a11897e3c22814086685ab406fbed79.tar.gz |
Add a templated Glib::build_filename() overload
that uses Glib::StdStringView. It avoids some unnecessary string copies.
Fixes #34
-rw-r--r-- | glib/src/miscutils.hg | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/glib/src/miscutils.hg b/glib/src/miscutils.hg index 2d7b0df3..a606447d 100644 --- a/glib/src/miscutils.hg +++ b/glib/src/miscutils.hg @@ -362,6 +362,26 @@ std::string path_get_dirname(const std::string& filename); GLIBMM_API std::string build_filename(const Glib::ArrayHandle<std::string>& elements); +/** Creates a filename from one or more elements using the correct separator for filenames. + * No attempt is made to force the resulting filename to be an absolute path. + * If the first element is a relative path, the result will be a relative path. + * @tparam Strings std::string or const char*. + * @param strings The path elements. + * @return The resulting path. + * + * @newin{2,64} + */ +template <typename... Strings> +std::string build_filename(const Strings&... strings) +{ + return Glib::convert_return_gchar_ptr_to_stdstring( + g_build_filename(StdStringView(strings).c_str()..., nullptr)); +} + +// When the templated build_filename() overload was added, the following +// build_filename() overloads became unnecessary. +//TODO: They can be removed when we can break ABI. + /** Creates a filename from two elements using the correct separator for filenames. * No attempt is made to force the resulting filename to be an absolute path. * If the first element is a relative path, the result will be a relative path. |