Hi,
After looking at it the problem is a little different. Operators are
searched in the namespaces of their arguments. It is called "König
lookup". Or after searching for it, I saw, that it used to be called so
but is now "argument dependent name lookup" (ADL). So the operator must
be defined either in the tntdb or std namespace. Since the defined
operator is not there, the compiler finds a suitable in the tntdb
namespace with a different meaning.
When removing that definition as we discussed, the compiler complains,
that there is no suitable operator at all.
Defining:
namespace std
{
void operator <<(tntdb::Hostvar& hv, const std::set<std::string>&
lists)
{ ...}
}
or
namespace tntdb
{
void operator <<(tntdb::Hostvar& hv, const std::set<std::string>&
lists)
{ ...}
}
both work.
Both not really elegant since users should not define anything in std or
tntdb. The normal case is anyway to have own classes in own namespaces
and then define those operator in that namespace.
Btw: let me suggest to use Json instead of that semicolon separated
list. The semicolon separated list do not work if one of the strings
have semicolons.
If you still want to use the semicolon separated list, there is a
function template "join" in cxxtools:
void operator <<(tntdb::Hostvar& hv, const std::set<std::string>& lists)
{
std::ostringstream s;
cxxtools::join(list.begin(), list.end(), ';', s);
hv.set(s.str());
}
The variant with json is here (also the opposite operator):
namespace tntdb
{
void operator <<(tntdb::Hostvar& hv, const std::set<std::string>&
lists)
{
std::ostringstream s;
s << cxxtools::Json(lists);
hv.set(s.str());
}
void operator >>(const tntdb::Value& v, std::set<std::string>& lists)
{
std::istringstream s;
s >> cxxtools::Json(lists);
}
}
You need cxxtools from git for that. Version 2.2 is not enough. Although
you can use 2.2 but then it is a little more work to use json.
Tommi
------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
Tntnet-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tntnet-general