Thread overview | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
September 17, 2014 Library Typedefs are fundamentally broken | ||||
---|---|---|---|---|
| ||||
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 Re: Library Typedefs are fundamentally broken | ||||
---|---|---|---|---|
| ||||
Posted in reply to Freddy | 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 Re: Library Typedefs are fundamentally broken | ||||
---|---|---|---|---|
| ||||
Posted in reply to Freddy | 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 Re: Library Typedefs are fundamentally broken | ||||
---|---|---|---|---|
| ||||
Posted in reply to Freddy | 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 Re: Library Typedefs are fundamentally broken | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jakob Ovrum | 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 Re: Library Typedefs are fundamentally broken | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | 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 Re: Library Typedefs are fundamentally broken | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | 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 Re: Library Typedefs are fundamentally broken | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | 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 Re: Library Typedefs are fundamentally broken | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | 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 Re: Library Typedefs are fundamentally broken | ||||
---|---|---|---|---|
| ||||
Posted in reply to monarch_dodra | 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).
|
Copyright © 1999-2021 by the D Language Foundation