Boost logo

Boost :

Subject: [boost] [string_ref] Don't rely on implicit conversation for operators
From: Nicola Bizzoca (nicola.bizzoca_at_[hidden])
Date: 2013-05-17 14:39:03

This is a follow up of "[string_ref] Add an equality operator between
string_ref and char*"

I'm sorry for the previous message, I'm started learning C++ and I'm making
some errors

Here the new topic:
boost::string_ref rely on implicit conversation for using operators

For example this operator:
template<typename charT, typename traits>
bool operator==(basic_string_ref<charT, traits> x, basic_string_ref<charT,
traits> y)

Is bad because if I write this:
boost::string_ref("http") == "http"

The compiler complains:
error: no match for ‘operator==’ (operand types are
‘boost::basic_string_ref<char, std::char_traits<char> >’ and ‘const char

It can't find the correct overload because implicit conversion is
considered after candidate templates have been considered

boost::string_ref should offer overloads for string and const char* so it
can be possible write code like
boost::string_ref("boost") == "boost" && boost::string_ref("c++") ==

Boost list run by bdawes at, gregod at, cpdaniel at, john at