Jump to page: 1 215  
Page
Thread overview
Library Typedefs are fundamentally broken
Sep 17, 2014
Freddy
Sep 17, 2014
bearophile
Sep 17, 2014
Andrej Mitrovic
Sep 17, 2014
monarch_dodra
Sep 17, 2014
Walter Bright
Sep 17, 2014
Walter Bright
Sep 17, 2014
Adam D. Ruppe
Sep 17, 2014
H. S. Teoh
Sep 17, 2014
Piotrek
Sep 17, 2014
H. S. Teoh
Sep 17, 2014
Piotrek
Sep 17, 2014
Jakob Ovrum
Sep 17, 2014
Freddy
Sep 17, 2014
Jack Applegame
Sep 17, 2014
Dicebot
Sep 17, 2014
bearophile
Sep 17, 2014
Dicebot
Sep 18, 2014
Andrej Mitrovic
Sep 17, 2014
Walter Bright
Sep 17, 2014
Dicebot
Sep 19, 2014
Jakob Ovrum
Sep 19, 2014
Dicebot
Sep 19, 2014
Jakob Ovrum
Sep 18, 2014
Wyatt
Sep 18, 2014
H. S. Teoh
Sep 18, 2014
Wyatt
Sep 19, 2014
bearophile
Sep 19, 2014
Marco Leise
Sep 20, 2014
Marco Leise
Sep 20, 2014
ketmar
Sep 20, 2014
bearophile
Sep 20, 2014
ketmar
Sep 20, 2014
ketmar
Sep 21, 2014
Dicebot
Sep 21, 2014
bearophile
Sep 21, 2014
Dicebot
Sep 21, 2014
Dicebot
Sep 21, 2014
ketmar
Sep 21, 2014
ketmar
Sep 21, 2014
Tourist
Sep 21, 2014
ketmar
Sep 21, 2014
ketmar
Sep 21, 2014
bearophile
Sep 21, 2014
ketmar
Sep 21, 2014
Timon Gehr
Sep 22, 2014
Don
Sep 22, 2014
Meta
Sep 23, 2014
Don
Sep 23, 2014
Adam D. Ruppe
Sep 23, 2014
H. S. Teoh
Sep 23, 2014
bearophile
Sep 23, 2014
ketmar
Sep 23, 2014
simendsjo
Sep 23, 2014
ketmar
Sep 23, 2014
Timon Gehr
Sep 24, 2014
Don
Sep 23, 2014
ketmar
Sep 23, 2014
Dicebot
Sep 23, 2014
Dicebot
Sep 23, 2014
H. S. Teoh
Sep 23, 2014
Adam D. Ruppe
Sep 23, 2014
Meta
Sep 23, 2014
ketmar
Sep 21, 2014
Andrej Mitrovic
Sep 21, 2014
Marco Leise
Sep 21, 2014
Marco Leise
Sep 21, 2014
bearophile
Sep 21, 2014
Dicebot
Sep 21, 2014
ketmar
Sep 21, 2014
ketmar
Sep 22, 2014
Marc Schütz
Sep 21, 2014
bearophile
Sep 20, 2014
Timon Gehr
Sep 20, 2014
Timon Gehr
Sep 20, 2014
Vladimir Panteleev
Sep 20, 2014
Marco Leise
Sep 20, 2014
Vladimir Panteleev
Sep 20, 2014
Daniel Murphy
Sep 20, 2014
Vladimir Panteleev
Sep 22, 2014
Daniel Murphy
Sep 20, 2014
Jakob Ovrum
Sep 20, 2014
Dicebot
Sep 20, 2014
Dicebot
Sep 20, 2014
bearophile
Sep 20, 2014
bearophile
Sep 21, 2014
Timon Gehr
Sep 20, 2014
Timon Gehr
Sep 20, 2014
bearophile
Sep 23, 2014
Meta
Sep 22, 2014
Wyatt
Sep 22, 2014
eles
Sep 22, 2014
bearophile
Sep 23, 2014
ketmar
Sep 22, 2014
Adam D. Ruppe
Sep 23, 2014
Wyatt
Sep 22, 2014
ketmar
Sep 23, 2014
ketmar
Sep 21, 2014
Freddy
Sep 21, 2014
Freddy
Sep 23, 2014
Shammah Chancellor
Sep 23, 2014
Adam D. Ruppe
Sep 23, 2014
H. S. Teoh
September 17, 2014
When you have separate 2 typedefs of the exact same type, they
are equal.While this maybe able to be solved with
Typedef!(Typedef!(...)) different modules typedef ing the same
type (most likely build-in types) would have their typedef be
equivalent thereby degrading the purpose of typedef.
---
import std.typecons;

alias meter = Typedef!float;
alias feet = Typedef!float;
static assert(!is(meter==feet));
---
Your thoughts?
September 17, 2014
On 9/16/14, 7:57 PM, Freddy wrote:
> When you have separate 2 typedefs of the exact same type, they
> are equal.While this maybe able to be solved with
> Typedef!(Typedef!(...)) different modules typedef ing the same
> type (most likely build-in types) would have their typedef be
> equivalent thereby degrading the purpose of typedef.
> ---
> import std.typecons;
>
> alias meter = Typedef!float;
> alias feet = Typedef!float;
> static assert(!is(meter==feet));
> ---
> Your thoughts?

Add a sequence number as a uint, defaulted to 0. -- Andrei

September 17, 2014
I don't think I've used any kind of typedef for a long time. I prefer to just use a plain struct.
September 17, 2014
On Wednesday, 17 September 2014 at 02:57:03 UTC, Freddy wrote:
> When you have separate 2 typedefs of the exact same type, they
> are equal.While this maybe able to be solved with
> Typedef!(Typedef!(...)) different modules typedef ing the same
> type (most likely build-in types) would have their typedef be
> equivalent thereby degrading the purpose of typedef.
> ---
> import std.typecons;
>
> alias meter = Typedef!float;
> alias feet = Typedef!float;
> static assert(!is(meter==feet));
> ---
> Your thoughts?

`Typedef` takes a second argument that can make it unique. It's all in the docs.
September 17, 2014
On Wednesday, 17 September 2014 at 03:08:46 UTC, Jakob Ovrum
wrote:
> On Wednesday, 17 September 2014 at 02:57:03 UTC, Freddy wrote:
>> When you have separate 2 typedefs of the exact same type, they
>> are equal.While this maybe able to be solved with
>> Typedef!(Typedef!(...)) different modules typedef ing the same
>> type (most likely build-in types) would have their typedef be
>> equivalent thereby degrading the purpose of typedef.
>> ---
>> import std.typecons;
>>
>> alias meter = Typedef!float;
>> alias feet = Typedef!float;
>> static assert(!is(meter==feet));
>> ---
>> Your thoughts?
>
> `Typedef` takes a second argument that can make it unique. It's all in the docs.

Sorry, my mistake.
September 17, 2014
On Wed, Sep 17, 2014 at 03:05:57AM +0000, Adam D. Ruppe via Digitalmars-d wrote:
> I don't think I've used any kind of typedef for a long time. I prefer to just use a plain struct.

Yeah, I found structs + alias this far more useful than any kind of typedef. Due to the way alias this lookups work, you can basically "customize" the underlying type by defining the appropriate struct methods to shadow the underlying type's, thereby achieving a kind of "static inheritance".


T

-- 
Error: Keyboard not attached. Press F1 to continue. -- Yoon Ha Lee, CONLANG
September 17, 2014
Andrei Alexandrescu:

> Add a sequence number as a uint, defaulted to 0. -- Andrei

See discussion:
https://d.puremagic.com/issues/show_bug.cgi?id=12100

Bye,
bearophile
September 17, 2014
On 9/17/14, bearophile via Digitalmars-d <digitalmars-d@puremagic.com> wrote:
> Andrei Alexandrescu:
>
>> Add a sequence number as a uint, defaulted to 0. -- Andrei
>
> See discussion: https://d.puremagic.com/issues/show_bug.cgi?id=12100

It's a good thing you found GCC and VC implement this. I think it's another sign that we could use this feature.
September 17, 2014
On Wednesday, 17 September 2014 at 07:21:13 UTC, Andrej Mitrovic via Digitalmars-d wrote:
> On 9/17/14, bearophile via Digitalmars-d <digitalmars-d@puremagic.com> wrote:
>> Andrei Alexandrescu:
>>
>>> Add a sequence number as a uint, defaulted to 0. -- Andrei
>>
>> See discussion:
>> https://d.puremagic.com/issues/show_bug.cgi?id=12100
>
> It's a good thing you found GCC and VC implement this. I think it's
> another sign that we could use this feature.

Technically, they implement it via macro, and the macro re-expands on every use. It's mostly useless outside of ".cpp" files: The identifiers are unstable cross compilation units. And if it appears in a .h, it'll be re-expanded to a different value on every include. If it appears in a macro, it'll be expanded to something different on every macro use too.
September 17, 2014
On 9/17/2014 12:30 AM, monarch_dodra wrote:
> On Wednesday, 17 September 2014 at 07:21:13 UTC, Andrej Mitrovic via
> Digitalmars-d wrote:
>> On 9/17/14, bearophile via Digitalmars-d <digitalmars-d@puremagic.com> wrote:
>>> Andrei Alexandrescu:
>>>
>>>> Add a sequence number as a uint, defaulted to 0. -- Andrei
>>>
>>> See discussion:
>>> https://d.puremagic.com/issues/show_bug.cgi?id=12100
>>
>> It's a good thing you found GCC and VC implement this. I think it's
>> another sign that we could use this feature.
>
> Technically, they implement it via macro, and the macro re-expands on every use.
> It's mostly useless outside of ".cpp" files: The identifiers are unstable cross
> compilation units. And if it appears in a .h, it'll be re-expanded to a
> different value on every include. If it appears in a macro, it'll be expanded to
> something different on every macro use too.

It's implemented as a special macro named __COUNTER__ which expands to an integer literal, incremented each time.

If such a thing were implemented in D, one could not depend on the values being globally unique, nor consistent when a module is compiled vs imported, nor consistent when multiple modules are compiled together vs compiled independently, nor even any predictable relationship between the values within a particular module (because semantic analysis is not supposed to be order dependent).
« First   ‹ Prev
1 2 3 4 5 6 7 8 9 10 11