🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Tim Boemker Wed, 13 Mar 1996 04:19
User-defined conversions
#3647
Author: 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 
]
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads