| Thread overview | |||||||
|---|---|---|---|---|---|---|---|
  | 
August 16, 2005 [proposal] How to overload opCast | ||||
|---|---|---|---|---|
  | ||||
Good day!
The one substantial drawback of D in comparition with C++ is that in D is
impossible to write more than one opCast per type. The reason is inability of
lincer to resolve different functions basing on respective return types.
But D - opposing to C++ - have "out" parameter modifier. So linker can easy
choose between proper functions:
# struct a {
#   void opCast(out int r);
#   void opCast(out double r);
#   void opCast(out char[] r);
# };
So I propose to add respective variants as valid choise when compiler resolve
code like
# cast(char[]) a;
Dusty.
 | ||||
August 16, 2005 Re: [proposal] How to overload opCast | ||||
|---|---|---|---|---|
  | ||||
Posted in reply to Dusty  | Dusty wrote:
> Good day!
> The one substantial drawback of D in comparition with C++ is that in D is
> impossible to write more than one opCast per type. The reason is inability of
> lincer to resolve different functions basing on respective return types.
> 
> But D - opposing to C++ - have "out" parameter modifier. So linker can easy
> choose between proper functions:
> # struct a {
> #   void opCast(out int r);
> #   void opCast(out double r);
> #   void opCast(out char[] r);
> # };
> 
> So I propose to add respective variants as valid choise when compiler resolve
> code like # cast(char[]) a;
Its been proposed a dozen times before.  And I for one still stand strongly in support of it.  The fact that it keeps on coming back up proves that it bears consideration.
-- Chris Sauls
 | |||
August 16, 2005 Re: [proposal] How to overload opCast | ||||
|---|---|---|---|---|
  | ||||
Posted in reply to Dusty  | Dusty wrote: > Good day! > The one substantial drawback of D in comparition with C++ is that in D is > impossible to write more than one opCast per type. The reason is inability of > lincer to resolve different functions basing on respective return types. <snip> Several proposals have been made for multiple cast operators. http://www.wikiservice.at/wiki4d/wiki.cgi?FeatureRequestList Stewart. -- My e-mail is valid but not my primary mailbox. Please keep replies on on the 'group where everyone may benefit.  | |||
August 16, 2005 Re: [proposal] How to overload opCast | ||||
|---|---|---|---|---|
  | ||||
Posted in reply to Chris Sauls  | In article <dds8rs$2n8u$1@digitaldaemon.com>, Chris Sauls says... > >Dusty wrote: >> Good day! >> The one substantial drawback of D in comparition with C++ is that in D is >> impossible to write more than one opCast per type. The reason is inability of >> lincer to resolve different functions basing on respective return types. >> >> But D - opposing to C++ - have "out" parameter modifier. So linker can easy >> choose between proper functions: >> # struct a { >> # void opCast(out int r); >> # void opCast(out double r); >> # void opCast(out char[] r); >> # }; >> >> So I propose to add respective variants as valid choise when compiler resolve >> code like >> # cast(char[]) a; > >Its been proposed a dozen times before. And I for one still stand strongly in support of it. The fact that it keeps on coming back up proves that it bears consideration. > >-- Chris Sauls I'm in favor as well, and was considering posting something exactly like this a few weeks ago! -Sha  | |||
August 16, 2005 Re: [proposal] How to overload opCast | ||||
|---|---|---|---|---|
  | ||||
Posted in reply to Dusty  | "Dusty" <Dusty_member@pathlink.com> wrote in message news:dds783$2lv5$1@digitaldaemon.com... > Good day! > The one substantial drawback of D in comparition with C++ is that in D is > impossible to write more than one opCast per type. The reason is inability > of > lincer to resolve different functions basing on respective return types. > > But D - opposing to C++ - have "out" parameter modifier. So linker can > easy > choose between proper functions: > # struct a { > # void opCast(out int r); > # void opCast(out double r); > # void opCast(out char[] r); > # }; > > So I propose to add respective variants as valid choise when compiler > resolve > code like > # cast(char[]) a; > > Dusty. > > I'm curious what you were coding that requires overloaded opCast (and, actually, what required an opCast at all). Note "cast(char[])a" in D would normally be code up as "a.toString()". Also D doesn't let you add to the set of implicit conversions the compiler tries to apply. All overloading has to happen on explicit casting expressions cast(Foo)bar. D is much less free-wheeling than C++ when it comes to implicit and explicit conversions and overloading.  | |||
Copyright © 1999-2021 by the D Language Foundation
 
Permalink
Reply