summaryrefslogtreecommitdiff
path: root/zen/string_base.h
diff options
context:
space:
mode:
authorB. Stack <bgstack15@gmail.com>2022-05-22 21:09:26 +0000
committerB. Stack <bgstack15@gmail.com>2022-05-22 21:09:26 +0000
commit54c2e44d7b37b2c3efc449e054eef21fa414dfde (patch)
tree3894ba7e10c78750c195381a861da5e8166a6bfd /zen/string_base.h
parentMerge branch 'b11.20' into 'master' (diff)
parentadd upstream 11.21 (diff)
downloadFreeFileSync-54c2e44d7b37b2c3efc449e054eef21fa414dfde.tar.gz
FreeFileSync-54c2e44d7b37b2c3efc449e054eef21fa414dfde.tar.bz2
FreeFileSync-54c2e44d7b37b2c3efc449e054eef21fa414dfde.zip
Merge branch 'b11.21' into 'master'11.21
add upstream 11.21 See merge request opensource-tracking/FreeFileSync!44
Diffstat (limited to 'zen/string_base.h')
-rw-r--r--zen/string_base.h18
1 files changed, 13 insertions, 5 deletions
diff --git a/zen/string_base.h b/zen/string_base.h
index 693ce118..ace870b9 100644
--- a/zen/string_base.h
+++ b/zen/string_base.h
@@ -7,8 +7,8 @@
#ifndef STRING_BASE_H_083217454562342526
#define STRING_BASE_H_083217454562342526
-#include <algorithm>
#include <atomic>
+#include <utility> //std::exchange
#include "string_tools.h"
@@ -377,8 +377,8 @@ Zbase<Char, SP>::Zbase(const Zbase<Char, SP>& str)
template <class Char, template <class> class SP> inline
Zbase<Char, SP>::Zbase(Zbase<Char, SP>&& tmp) noexcept
{
- rawStr_ = tmp.rawStr_;
- tmp.rawStr_ = nullptr; //usually nullptr would violate the class invarants, but it is good enough for the destructor!
+ rawStr_ = std::exchange(tmp.rawStr_, nullptr);
+ //usually nullptr would violate the class invarants, but it is good enough for the destructor!
//caveat: do not increment ref-count of an unshared string! We'd lose optimization opportunity of reusing its memory!
}
@@ -637,8 +637,8 @@ Zbase<Char, SP>& Zbase<Char, SP>::operator=(Zbase<Char, SP>&& tmp) noexcept
{
//don't use swap() but end rawStr_ life time immediately
this->destroy(rawStr_);
- rawStr_ = tmp.rawStr_;
- tmp.rawStr_ = nullptr;
+
+ rawStr_ = std::exchange(tmp.rawStr_, nullptr);
return *this;
}
@@ -653,4 +653,12 @@ void Zbase<Char, SP>::pop_back()
}
}
+
+//std::hash specialization in global namespace
+template <class Char, template <class> class SP>
+struct std::hash<zen::Zbase<Char, SP>>
+{
+ size_t operator()(const zen::Zbase<Char, SP>& str) const { return zen::hashString<size_t>(str); }
+};
+
#endif //STRING_BASE_H_083217454562342526
bgstack15