diff --git a/src/config.hpp b/src/config.hpp index 5bc0fc7d313c..284f304f2c6d 100644 --- a/src/config.hpp +++ b/src/config.hpp @@ -42,6 +42,10 @@ #include #include +#include +#include +#include + #include "exceptions.hpp" #include "tstring.hpp" @@ -280,15 +284,29 @@ class config bool operator==(const attribute_value &other) const; bool operator!=(const attribute_value &other) const { return !operator==(other); } - // We don't want strange conversions to t_string when doing like (c["a"] == "b") + + // returns always false if the underlying type is no string. bool equals(const std::string& str) const; - friend bool operator==(const attribute_value &val, const std::string &str) + //these function prevent t_string creation in case of c["a"] == "b" + //The templates are needed to prevent using these function in case of c["a"] == 0. + template + typename boost::enable_if::type>, bool>::type + friend operator==(const attribute_value &val, const T &str) { return val.equals(str); } - friend bool operator==(const std::string &str, const attribute_value &val) + + template + typename boost::enable_if::type>, bool>::type + friend operator==(const T &str, const attribute_value &val) { return val.equals(str); } - friend bool operator==(const attribute_value &val, const char* str) + + template + typename boost::enable_if, bool>::type + friend operator==(const attribute_value &val, T str) { return val.equals(std::string(str)); } - friend bool operator==(const char* str, const attribute_value &val) + + template + typename boost::enable_if, bool>::type + friend operator==(T str, const attribute_value &val) { return val.equals(std::string(str)); } // Streaming: