diff --git a/include/duckhandy/string_bt.hpp b/include/duckhandy/string_bt.hpp index 6697579..927b91f 100644 --- a/include/duckhandy/string_bt.hpp +++ b/include/duckhandy/string_bt.hpp @@ -31,9 +31,14 @@ namespace dhandy { template std::basic_ostream& operator<< ( std::basic_ostream& parStream, const string& parString ); + namespace implem { + template constexpr bool eq (const string& l, const string& r); + } //namespace implem + template class string { friend std::ostream& operator<< <>( std::ostream& parStream, const string& parString ); + friend constexpr bool implem::eq (const string&, const string&); public: using value_type = Ch; constexpr string ( const value_type* parString ); @@ -42,6 +47,8 @@ namespace dhandy { template constexpr string operator+ ( const string& parOther ) const; constexpr value_type operator[] ( std::size_t parIndex ) const; + constexpr bool operator== (const string& other) const; + template constexpr bool operator== (const string&) const { return false; } template constexpr string ( Args... ); @@ -64,6 +71,9 @@ namespace dhandy { ); } + template <> constexpr inline bool eq (const string<1>& l, const string<1>& r) { return l[0] == r[0]; } + template + constexpr inline bool eq (const string& l, const string& r) { return l[0] == r[0] and eq(string(l.m_data+1), string(r.m_data+1)); } } //namespace implem template @@ -107,6 +117,11 @@ namespace dhandy { constexpr string make_string (const Ch (&parData)[S]) { return string(parData); } + + template + constexpr bool string::operator== (const string& other) const { + return implem::eq(*this, other); + } } //namespace bt } //namespace dhandy