Summary: library-based typedef
           Product: D
           Version: D1 & D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos

--- Comment #0 from Trass3r <> 2011-01-20 08:48:32 PST ---
Typedef is scheduled for deprecation but there is no proper library-based
solution to it yet. Andrei pointed out the following use cases:

1. Something that's just like another type yet "parallel" with it. This is good
for abstractions that encode different units of measurement that aren't
supposed to be mixed.

ParallelTypedef!double Miles;

Such a type should accept explicit initialization from a regular double:

auto dist = Miles(3.2);

However it shouldn't accept initialization from another parallel typedef:

ParallelTypedef!double Kms;
auto dist1 = Kms(4);
auto dist2 = Miles(dist1); // no

Arithmetic operations should only work within Miles but not mixing Miles with
other types. Here's where things already get complicated - you do want to allow
some operations between Miles and double (e.g. "*"), in some others you don't
(e.g. "+"). Here's where a library facility would help:

ParallelTypdef!(double, "allow_arithmetic", "allow_mixed:*,/,%")

2. Opaque "handle" types that can be used with overloading. The base type of
the typedef is just the storage strategy:

OpaqueTypedef!int FileHandle;

Such a typedef supports no arithmetic and no implicit conversions. You can
explicitly initialize it from an int and you can cast it back to it using an
explicit cast.

3. Proper subtype. Create a true subtype of a type that allows explicit
initialization from the type and implicit conversion to the type.

SubtypeTypedef!Exception MyException;

4. Proper supertype. The base type implicitly converts to the introduced type,
but not vice versa.

SupertypeTypedef!uint Bits;

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to