🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #3647

User-defined conversions

#3647
From: Tim Boemker
Date: Wed, 13 Mar 1996 04:19
52 lines
2459 bytes
I'm trying to write a class template Like that extends the behavior of
a (possibly built-in) type by defining conversions so that wherever a
Like<T> appears it's implicitly converted to T& and wherever const
Like<T> appears it's implicitly converted to const T&.

  template<class T> class Like<T> {
  private:
      T t;
  public:
      Like(T t_) : t(t_) {}
      operator const T&() const { return t; }
      operator T&() { return t; }
      // ...
  };

As I read the WP, the following code is ambiguous

  Like<T> x;
  int y;
  ...
  if(x == y)
    // do something

because the two candidate user-defined conversion sequences contain
different user-defined conversion operators (although they differ only
in their cv-qualifiers) and neither second standard conversion
sequences is better.  This is not the way standard conversion sequences
are compared.  In [over.ics.rank], the WP says

  Standard conversion sequence S1 is a better conversion sequence than
standard
  conversion sequence S2 if ... S1 and S2 differ only in their
qualification
  conversion and they yield types identical except for cv-qualifiers
and S2 adds
  all the qualifiers that S1 adds (and in the same places) and S2 adds
more cv-
  qualifiers than S1..."


It seems to me that similar language ought to apply to user-defined
conversions.

Tim Boemker
Optimum Group
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu 
]
Technical Details
Message-ID: <199603111535.AA12540@zacatecas.optimum.com>
Path: arc1-ca.pugleaf.net!chronicle.mti.sgi.com!austern

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!chronicle.mti.sgi.com!austern
From: tjb839@zacatecas.optimum.com (Tim Boemker)
Newsgroups: comp.std.c++
Subject: User-defined conversions
Date: 12 Mar 1996 20:19:06 PST
Organization: -
Approved: austern@isolde.mti.sgi.com
Message-ID: <199603111535.AA12540@zacatecas.optimum.com>
NNTP-Posting-Host: isolde.mti.sgi.com
X-Original-Date: Mon, 11 Mar 1996 10:35:09 -0500
X-Authenticated: tjb839 on POP host zacatecas.optimum.com
X-Mailed-From: InterNews 1.0.6@boemker.optimum.com
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBVAwUBMUZNMEy4NqrwXLNJAQEE0wH/Q4fhDH8jmB/1C3Fj6BBChKAm0u+xSNqn
 HnbbVIsCT2pZeOEruxVWWv7tGhWetAIvu1xCDSxoaJNi6Bv1AVQgsA==
 =4KPX
Originator: austern@isolde.mti.sgi.com