From 8655e2e3b9b1b35fad3b778f2f3307cd7250ccc7 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Fri, 13 Dec 2019 12:28:43 -0500 Subject: [PATCH] r & lvalue ref-qualified overloads of TranslatableString functions... ... and moves of TranslatableString arguments where possible --- include/audacity/Types.h | 31 ++++++++++++++++++++++--------- src/Internat.cpp | 10 ++++++---- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/include/audacity/Types.h b/include/audacity/Types.h index 841784e99..41117f615 100644 --- a/include/audacity/Types.h +++ b/include/audacity/Types.h @@ -380,7 +380,7 @@ public: // Any format arguments that are also of type TranslatableString will be // translated too at substitution time, for non-debug formatting template< typename... Args > - TranslatableString &&Format( Args &&...args ) && + TranslatableString &Format( Args &&...args ) & { auto prevFormatter = mFormatter; this->mFormatter = [prevFormatter, args...] @@ -399,7 +399,12 @@ public: } } }; - return std::move( *this ); + return *this; + } + template< typename... Args > + TranslatableString &&Format( Args &&...args ) && + { + return std::move( Format( std::forward(args)... ) ); } // Choose a non-default and non-null disambiguating context for lookups @@ -407,7 +412,7 @@ public: // This is meant to be the first of chain-call modifications of the // TranslatableString object; it will destroy any previously captured // information - TranslatableString &&Context( const wxString &context ) && + TranslatableString &Context( const wxString &context ) & { this->mFormatter = [context] (const wxString &str, Request request) -> wxString { @@ -418,17 +423,25 @@ public: return str; } }; - return std::move( *this ); + return *this; + } + TranslatableString &&Context( const wxString &context ) && + { + return std::move( Context( context ) ); } // Append another translatable string; lookup of msgids for // this and for the argument are both delayed until Translate() is invoked // on this, and then the formatter concatenates the translations + TranslatableString &Join( + TranslatableString arg, const wxString &separator = {} ) &; TranslatableString &&Join( - const TranslatableString &arg, const wxString &separator = {} ) &&; - TranslatableString &operator +=( const TranslatableString &arg ) + TranslatableString arg, const wxString &separator = {} ) && + { return std::move( Join( std::move(arg), separator ) ); } + + TranslatableString &operator +=( TranslatableString arg ) { - std::move(*this).Join( arg ); + Join( std::move( arg ) ); return *this; } @@ -507,9 +520,9 @@ private: }; inline TranslatableString operator +( - const TranslatableString &x, const TranslatableString &y ) + TranslatableString x, TranslatableString y ) { - return TranslatableString{ x } += y; + return std::move(x += std::move(y)); } using TranslatableStrings = std::vector; diff --git a/src/Internat.cpp b/src/Internat.cpp index 93849eaa9..b862df3ec 100644 --- a/src/Internat.cpp +++ b/src/Internat.cpp @@ -345,12 +345,14 @@ wxString TranslatableString::DoChooseFormat( ); } -TranslatableString &&TranslatableString::Join( - const TranslatableString &arg, const wxString &separator ) && +TranslatableString &TranslatableString::Join( + const TranslatableString arg, const wxString &separator ) & { auto prevFormatter = mFormatter; mFormatter = - [prevFormatter, arg, separator](const wxString &str, Request request) + [prevFormatter, + arg /* = std::move( arg ) */, + separator](const wxString &str, Request request) -> wxString { switch ( request ) { case Request::Context: @@ -366,5 +368,5 @@ TranslatableString &&TranslatableString::Join( } } }; - return std::move( *this ); + return *this; }