Thread overview
For the new std.variant
Oct 31, 2011
Steve Teale
Oct 31, 2011
Jesse Phillips
Oct 31, 2011
Steve Teale
Oct 31, 2011
Jesse Phillips
Oct 31, 2011
Trass3r
Nov 01, 2011
Steve Teale
Nov 01, 2011
Robert Jacques
October 31, 2011
Robert,

Maybe you can fix this along the way:

import std.variant;
struct B
{
   int p, q, r, s;
}
typedef B C;

void main()
{
   B b;
   C c;
   b = c;   // ok
   Variant v = c;
   assert(v.convertsTo!(B));   // no dice
}

Steve
October 31, 2011
typedef shouldn't exist anymore, use alias.

Steve Teale Wrote:

> Robert,
> 
> Maybe you can fix this along the way:
> 
> import std.variant;
> struct B
> {
>    int p, q, r, s;
> }
> typedef B C;
> 
> void main()
> {
>    B b;
>    C c;
>    b = c;   // ok
>    Variant v = c;
>    assert(v.convertsTo!(B));   // no dice
> }
> 
> Steve

October 31, 2011
On Mon, 31 Oct 2011 11:50:42 -0400, Jesse Phillips wrote:

> typedef shouldn't exist anymore, use alias.
>

Jesse,

Maybe you want to do something like:

struct X
{
  int a;
  double b;
}
typedef X Y;
alias X Z;

void discriminate(T)(T t)
{
   if (is(T == X))
      writeln("It's an X");
   else
      writeln("No it's not");
}

void main()
{
   Y y;
   Z z;
   discriminate(y);
   discriminate(z);
}

Steve
October 31, 2011
I literally meant it is not supposed to exist. There was a suggestion to even axe it from 2.056 I believe.

A library solution is intended to be created which will allow for the type to act as either a parent or child to the type.

http://stackoverflow.com/questions/3576580/does-d-have-newtype/3577246#3577246

So I understand its usage, but you shouldn't use it because it won't be there.
October 31, 2011
> I literally meant it is not supposed to exist. There was a suggestion to even axe it from 2.056 I believe.

At least they prepared to actually deprecate it.


> A library solution is intended to be created which will allow for the type to act as either a parent or child to the type.

http://d.puremagic.com/issues/show_bug.cgi?id=5467
November 01, 2011
On Mon, 31 Oct 2011 21:03:39 +0100, Trass3r wrote:

>> I literally meant it is not supposed to exist. There was a suggestion to even axe it from 2.056 I believe.
> 
> At least they prepared to actually deprecate it.
> 
> 
>> A library solution is intended to be created which will allow for the type to act as either a parent or child to the type.
> 
> http://d.puremagic.com/issues/show_bug.cgi?id=5467

OK, my use case is that in the database interface modules, as far as possible I would like to infer an SQL type from a D type. There are often SQL types for TIME, DATE, DATETIME, and TIMESTAMP, but the latter two will usually correspond to D structs with the same members.

I can define two identical structs with the same set of protocol parsing and packing methods, but with different names, but to me this seems clunky, error-prone, and not a very good advert for the language.

There's was also a temptation to create typedefs of char[] like tinyString, mediumString and longString. I have not gone there - just as well.

Forgetting typedef, which I should assume does not exist, what is the elegant approach to this?

Steve
November 01, 2011
On Mon, 31 Oct 2011 06:30:40 -0400, Steve Teale <steve.teale@britseyeview.com> wrote:
> Robert,
>
> Maybe you can fix this along the way:
>
> import std.variant;
> struct B
> {
>    int p, q, r, s;
> }
> typedef B C;
>
> void main()
> {
>    B b;
>    C c;
>    b = c;   // ok
>    Variant v = c;
>    assert(v.convertsTo!(B));   // no dice
> }
>
> Steve

As others have mentioned, typedef is being deprecated. That said, variant now supports duck-typing. So 'v.to!B()' works. However, 'convertsTo's mandate is to test for implicit conversion, which isn't covered as there's no way in __traits to recover a typedef's base type.