diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2022-10-12 16:23:33 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2022-10-13 07:18:41 +0200 |
commit | af2879e434fa0dc6b2a626617ed865e4f66eb5ad (patch) | |
tree | bb25da5b207884ab9fd8d1c49d8dee18b9f1ad12 /include/rtl/string.hxx | |
parent | b3869749719288e6d1951030f07dc3fbccc0c222 (diff) |
Deduplicate stringconcat more
In the process, drop ToStringHelper::allowO(U)StringConcat, because
we can deduce this information from ToStringHelper's addData itself.
To do that, addData was converted to ToStringHelper::operator(),
which allows to use std::is_invocable_v on the helper class.
Change-Id: Ic77878ca0ff65ada8c0a942191bc11de15b9ad2a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141254
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'include/rtl/string.hxx')
-rw-r--r-- | include/rtl/string.hxx | 34 |
1 files changed, 14 insertions, 20 deletions
diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx index 0e0c3c75d5a9..3d9ef8ff9aa3 100644 --- a/include/rtl/string.hxx +++ b/include/rtl/string.hxx @@ -394,8 +394,8 @@ public: @overload @internal */ - template< typename T > - OString( OStringNumber< T >&& n ) + template< typename T, std::size_t N > + OString( StringNumberBase< char, T, N >&& n ) : OString( n.buf, n.length ) {} #endif @@ -548,12 +548,12 @@ public: @overload @internal */ - template< typename T > - OString& operator+=( OStringNumber< T >&& n ) & { + template< typename T, std::size_t N > + OString& operator+=( StringNumberBase< char, T, N >&& n ) & { return operator +=(std::string_view(n.buf, n.length)); } - template<typename T> void operator +=( - OStringNumber<T> &&) && = delete; + template<typename T, std::size_t N> void operator +=( + StringNumberBase<char, T, N> &&) && = delete; #endif /** @@ -2154,16 +2154,14 @@ public: // // would not compile): template<typename T> [[nodiscard]] static - typename std::enable_if_t< - ToStringHelper<T>::allowOStringConcat, OStringConcat<OStringConcatMarker, T>> + OStringConcat<OStringConcatMarker, T> Concat(T const & value) { return OStringConcat<OStringConcatMarker, T>({}, value); } // This overload is needed so that an argument of type 'char const[N]' ends up as // 'OStringConcat<rtl::OStringConcatMarker, char const[N]>' rather than as // 'OStringConcat<rtl::OStringConcatMarker, char[N]>': template<typename T, std::size_t N> [[nodiscard]] static - typename std::enable_if_t< - ToStringHelper<T[N]>::allowOStringConcat, OStringConcat<OStringConcatMarker, T[N]>> + OStringConcat<OStringConcatMarker, T[N]> Concat(T (& value)[N]) { return OStringConcat<OStringConcatMarker, T[N]>({}, value); } #endif }; @@ -2188,24 +2186,20 @@ inline bool operator !=(StringConcatenation<char> const & lhs, OString const & r */ template<> struct ToStringHelper< OString > - { +{ static std::size_t length( const OString& s ) { return s.getLength(); } - static char* addData( char* buffer, const OString& s ) { return addDataHelper( buffer, s.getStr(), s.getLength()); } - static const bool allowOStringConcat = true; - static const bool allowOUStringConcat = false; - }; + char* operator()( char* buffer, const OString& s ) const { return addDataHelper( buffer, s.getStr(), s.getLength()); } +}; /** @internal */ template<std::size_t N> struct ToStringHelper< OStringLiteral<N> > - { +{ static constexpr std::size_t length( const OStringLiteral<N>& str ) { return str.getLength(); } - static char* addData( char* buffer, const OStringLiteral<N>& str ) { return addDataHelper( buffer, str.getStr(), str.getLength() ); } - static const bool allowOStringConcat = true; - static const bool allowOUStringConcat = false; - }; + char* operator()( char* buffer, const OStringLiteral<N>& str ) const { return addDataHelper( buffer, str.getStr(), str.getLength() ); } +}; /** @internal |