[Issue 9112] Uniform construction for built-in types

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Dec 7 10:55:14 PST 2012


http://d.puremagic.com/issues/show_bug.cgi?id=9112



--- Comment #13 from monarchdodra at gmail.com 2012-12-07 10:55:13 PST ---
(In reply to comment #11)
> (In reply to comment #0)
> > So I'd like to propose new syntax to reduce such concept confusion.
> > 
> > int n = int(10);  // same as cast(int)10;
> 
> So we're introducing C++-style casts into D? This means you can no longer
> search for 'cast' and expect to find all the unsafe casts in your code. I'm
> very much against this, and if I remember right Walter was also against this.
> 

AFAIK, it's not exactly the same thing, as int(10) would be only a constructor,
so would not downcast.

Writing:
//----
void foo(long k)
{
  int n = int(k);
}
//----

Would fail to compile the same way as:

//----
void foo(long k)
{
  int n = k;
}
//----

would. You'd need to use:

//----
void foo(long k)
{
  int n = int(cast(int)k);
}
//----

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list