From 850d20093a9f04eb5acaf773ae101d1dc7f72765 Mon Sep 17 00:00:00 2001 From: q66 Date: Sun, 14 Jun 2015 02:36:20 +0100 Subject: [PATCH] string equality + tweaks --- octa/functional.h | 2 +- octa/memory.h | 6 ++++++ octa/string.h | 28 ++++++++++++++++++++++++++++ octa/utility.h | 2 +- 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/octa/functional.h b/octa/functional.h index 78ea15d..cf3a217 100644 --- a/octa/functional.h +++ b/octa/functional.h @@ -95,7 +95,7 @@ template BinaryNegate not2(const T &fn) { template struct ToHash { using Argument = const T &; - using Result = typename T::Size; + using Result = octa::Size; octa::Size operator()(const T &v) const { return v.to_hash(); diff --git a/octa/memory.h b/octa/memory.h index e771dc5..2a4a50f 100644 --- a/octa/memory.h +++ b/octa/memory.h @@ -541,6 +541,9 @@ template struct Allocator { template using Rebind = Allocator; + Allocator() {} + template Allocator(const Allocator &) {} + Pointer address(Reference v) const { return address_of(v); }; @@ -575,6 +578,9 @@ template struct Allocator { template using Rebind = Allocator; + Allocator() {} + template Allocator(const Allocator &) {} + ConstPointer address(ConstReference v) const { return address_of(v); }; diff --git a/octa/string.h b/octa/string.h index 0aa628d..c34ef88 100644 --- a/octa/string.h +++ b/octa/string.h @@ -288,6 +288,14 @@ public: return *this; } + int compare(const StringBase &s) const { + return strcmp(p_buf.data(), s.data()); + } + + int compare(ConstPointer p) const { + return strcmp(p_buf.data(), p); + } + Range each() { return Range(p_buf.data(), size()); } @@ -315,6 +323,26 @@ using String = StringBase; using StringRange = StringRangeBase; using ConstStringRange = StringRangeBase; +static inline bool operator==(const String &lhs, const String &rhs) { + return !lhs.compare(rhs); +} +static inline bool operator==(const String &lhs, const char *rhs) { + return !lhs.compare(rhs); +} +static inline bool operator==(const char *lhs, const String &rhs) { + return !rhs.compare(lhs); +} + +static inline bool operator!=(const String &lhs, const String &rhs) { + return !!lhs.compare(rhs); +} +static inline bool operator!=(const String &lhs, const char *rhs) { + return !!lhs.compare(rhs); +} +static inline bool operator!=(const char *lhs, const String &rhs) { + return !!rhs.compare(lhs); +} + template String concat(const T v, const String &sep, F func) { String ret; diff --git a/octa/utility.h b/octa/utility.h index f68ddcc..26b7e67 100644 --- a/octa/utility.h +++ b/octa/utility.h @@ -272,7 +272,7 @@ namespace detail { template struct CompressedPair: CompressedPairBase { - typedef CompressedPairBase Base; + using Base = CompressedPairBase; template CompressedPair(TT &&a, UU &&b): Base(octa::forward(a),