From 91f252b7091be414f35fcc0b86331b15a34dbd66 Mon Sep 17 00:00:00 2001 From: Abegail Jakop Date: Wed, 19 Aug 2015 18:04:36 -0400 Subject: [PATCH] stringtable.h: add logical ops and to_string if needed when it comes to string_ref, boost 1.53 doesn't contain all the logical operations that we need, nor to_string(). so we'll fill in the gaps with our own defintions for interned_string. --- stringtable.h | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/stringtable.h b/stringtable.h index 4455c9be8..68365d19b 100644 --- a/stringtable.h +++ b/stringtable.h @@ -14,6 +14,7 @@ #include #if defined(HAVE_BOOST_UTILITY_STRING_REF_HPP) +#include #include //header with string_ref // XXX: experimental tunables @@ -31,7 +32,36 @@ struct interned_string: public boost::string_ref interned_string(const interned_string& value): boost::string_ref(value) {} interned_string& operator = (const std::string& value); interned_string& operator = (const char* value); - + +#if BOOST_VERSION < 105400 + std::string to_string () const { return std::string(this->data(), this->size()); } + + // some comparison operators that aren't available in boost 1.53 + bool operator == (const char* y) { return compare(boost::string_ref(y)) == 0; } + bool operator == (const std::string& y) { return compare(boost::string_ref(y)) == 0; } + friend bool operator == (interned_string x, interned_string y) { return x.compare(y) == 0; } + friend bool operator == (const char * x, interned_string y) + { + return y.compare(boost::string_ref(x)) == 0; + } + friend bool operator == (const std::string& x, interned_string y) + { + return y.compare(boost::string_ref(x)) == 0; + } + + bool operator != (const char* y) { return compare(boost::string_ref(y)) != 0; } + bool operator != (const std::string& y) { return compare(boost::string_ref(y)) != 0; } + friend bool operator != (interned_string x, interned_string y) { return x.compare(y) != 0; } + friend bool operator != (const char * x, interned_string y) + { + return y.compare(boost::string_ref(x)) != 0; + } + friend bool operator != (const std::string& x, interned_string y) + { + return y.compare(boost::string_ref(x)) != 0; + } +#endif + // easy out-conversion operators operator std::string () const { return this->to_string(); } @@ -43,7 +73,8 @@ struct interned_string: public boost::string_ref // substrings -xor- implicit \0 terminators - not both. interned_string substr(size_t pos = 0, size_t len = npos) const { - return interned_string::intern (boost::string_ref::substr(pos, len).to_string()); + boost::string_ref sub = boost::string_ref::substr(pos, len); + return interned_string::intern (std::string(sub.data(), sub.size())); } // boost oversights -- 2.43.5