diff options
author | Gleb Mazovetskiy <glebm@google.com> | 2018-10-03 13:29:52 +0100 |
---|---|---|
committer | Gleb Mazovetskiy <glebm@google.com> | 2018-10-03 13:29:52 +0100 |
commit | d081cf3abae5bfbc28b7a2fb213fa4336af6bf11 (patch) | |
tree | b59083ace18067f7b11ec21bf2a528c7ae180293 /include | |
parent | cd9cd6d78065bbfe68d2755587d71d0440d9b61a (diff) | |
download | marisa-trie-d081cf3abae5bfbc28b7a2fb213fa4336af6bf11.tar.gz |
Fix `swap` overload
Use `std::swap` instead of a custom version to avoid "ambiguous call"
errors.
Previously, this code broke:
std::unique_ptr<marisa::Trie> a;
// Here, unique_ptr calls `swap` internally using ADL.
// Previously, this failed to compile:
a.reset(new marisa::Trie());
Diffstat (limited to 'include')
-rw-r--r-- | include/marisa/base.h | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/include/marisa/base.h b/include/marisa/base.h index 17606c0..7b1caf3 100644 --- a/include/marisa/base.h +++ b/include/marisa/base.h @@ -162,6 +162,13 @@ typedef enum marisa_config_mask_ { #endif // __cplusplus #ifdef __cplusplus + +// `std::swap` is in <utility> since C++ 11 but in <algorithm> in C++ 98: +#if __cplusplus>=201103L +#include <utility> +#else +#include <algorithm> +#endif namespace marisa { typedef ::marisa_uint8 UInt8; @@ -175,12 +182,7 @@ typedef ::marisa_cache_level CacheLevel; typedef ::marisa_tail_mode TailMode; typedef ::marisa_node_order NodeOrder; -template <typename T> -inline void swap(T &lhs, T &rhs) { - T temp = lhs; - lhs = rhs; - rhs = temp; -} +using std::swap; } // namespace marisa #endif // __cplusplus |