string equality + tweaks

master
Daniel Kolesa 2015-06-14 02:36:20 +01:00
parent 5c0f051eac
commit 850d20093a
4 changed files with 36 additions and 2 deletions

View File

@ -95,7 +95,7 @@ template<typename T> BinaryNegate<T> not2(const T &fn) {
template<typename T> 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();

View File

@ -541,6 +541,9 @@ template<typename T> struct Allocator {
template<typename U> using Rebind = Allocator<U>;
Allocator() {}
template<typename U> Allocator(const Allocator<U> &) {}
Pointer address(Reference v) const {
return address_of(v);
};
@ -575,6 +578,9 @@ template<typename T> struct Allocator<const T> {
template<typename U> using Rebind = Allocator<U>;
Allocator() {}
template<typename U> Allocator(const Allocator<U> &) {}
ConstPointer address(ConstReference v) const {
return address_of(v);
};

View File

@ -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<char>;
using StringRange = StringRangeBase<char>;
using ConstStringRange = StringRangeBase<const char>;
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<typename T, typename F>
String concat(const T v, const String &sep, F func) {
String ret;

View File

@ -272,7 +272,7 @@ namespace detail {
template<typename T, typename U>
struct CompressedPair: CompressedPairBase<T, U> {
typedef CompressedPairBase<T, U> Base;
using Base = CompressedPairBase<T, U>;
template<typename TT, typename UU>
CompressedPair(TT &&a, UU &&b): Base(octa::forward<TT>(a),