473,322 Members | 1,314 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

user-defined conversion combined with argument-dependent lookup

Suppose that I have a class that has a user-defined conversion to
std::string, and I would like to compare objects of that class to
"strings" (e.g. literals, std::strings):

class InUpperCase {
public:
operator std::string() const;
};

....
InUpperCase()=="a string"; // This does not compile.
// fine, bool operator==(InUpperCase const& , char const* );
// is not declared anywhere.

InUpperCase()==std::string("a string"); // This one does not compile
either,
// even though, there is a definition for an operator== in std
// that takes two std::strings.

I expected the second expression to compile fine due to ADL combined
with the user-defined conversion. Any idea why?
Nov 30 '07 #1
3 1338
On Dec 1, 3:20 am, Belebele <beluc...@gmail.comwrote:
Suppose that I have a class that has a user-defined conversion to
std::string, and I would like to compare objects of that class to
"strings" (e.g. literals, std::strings):

class InUpperCase {
public:
operator std::string() const;

};
Instead of providing a conversion operator, why don't you provide
friend overload for operator== taking InUpperCase and std::string as
arguments?
Dec 5 '07 #2
On Dec 5, 5:10 am, jg <jgu...@gmail.comwrote:
On Dec 2, 1:19 am, James Kanze <james.ka...@gmail.comwrote:
On the same page, can this operator== be explicitly
instantiated ?
I presume you mean the == operator for std::string. I think so,
but I'll admit that I've never done it.

I don't think that this will solve your problem, however. Even
if explicitly instantiated, the compiler will use type deduction
to determine whether the function is part of the overload set or
not, and type deduction will fail in your case.

The easiest solution is just to provide a simple wrapper in the
form of an operator== which uses your class.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Dec 5 '07 #3
class InUpperCase {
public:
operator std::string() const;
};

Instead of providing a conversion operator, why don't you provide
friend overload for operator== taking InUpperCase and std::string as
arguments?
My intention, besides being clarity of representation, is to take
advantage of the existing facilities to avoid writing more boilerplate
code (as long as I don't muddle the implementation too much along the
way).

That's why I avoided the friend overload if I could.
Dec 11 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

60
by: Fotios | last post by:
Hi guys, I have put together a flexible client-side user agent detector (written in js). I thought that some of you may find it useful. Code is here: http://fotios.cc/software/ua_detect.htm ...
3
by: zlst | last post by:
Many technological innovations rely upon User Interface Design to elevate their technical complexity to a usable product. Technology alone may not win user acceptance and subsequent marketability....
6
by: martin | last post by:
Hi, I am a web page and a web user control. My web user control is placed in my web page using the following directive <%@ Register TagPrefix="uc1" TagName="Header"...
1
by: Shourie | last post by:
I've noticed that none of the child controls events are firing for the first time from the dynamic user control. Here is the event cycle. 1) MainPage_load 2) User control1_Load user clicks a...
7
by: jsale | last post by:
I'm currently using ASP.NET with VS2003 and SQL Server 2003. The ASP.NET app i have made is running on IIS v6 and consists of a number of pages that allow the user to read information from the...
2
by: rn5a | last post by:
Assume that a user control (MyUC.ascx) encapsulates 2 TextBoxes with the IDs 'txt1' & 'txt2' respectively. To use this user control in an ASPX page, the following Register directive will be...
1
by: Carlettus | last post by:
Dear All, sorry but I'm not sure if this is the right place to post my problem. I was using the following asp code to create users in Active Directory. Suddenly, and I don't know the reason, users...
0
by: rbukkara | last post by:
Hi, I have got the following error while trying to add a user in the LDAP Directory. javax.naming.NameNotFoundException: ; remaining name 'uid=vassila,ou=People,dc=cs,dc=uno,dc=edu' I have...
9
by: Gordon | last post by:
I want to add a feature to a project I'm working on where i have multiple users set up on my Postgres database with varying levels of access. At the bare minimum there will be a login user who...
3
by: shapper | last post by:
Hello, On my web site I have a property, Visitor, which is available for Anonymous users: public class Visitor { public CultureInfo Culture { get; set; } public List<GuidPolls { get; set;...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.