the Result Type

Marco Leise Marco.Leise at gmx.de
Sun Dec 8 02:29:46 PST 2013


Am Sun, 08 Dec 2013 09:59:55 +0100
schrieb "seany" <seany at uni-bonn.de>:

> O_O
> 
> with that knowledge, would also be possible to define new types 
> (not aliases, but new encapsulated types) representing things 
> such as Graph, Ring, Topology, surreal number, etc?

All these Result types are simply structs. Structs with
template parameters. Your question is a bit vague. You will
not be able to use D algorithms on anything but "consecutive
items of the same type" as I worte in my other post, if that
is the question.

Other than that the Result types are just:

struct Result(T)
{
    ...
}

You can call them "templated struct" or "generic type". Many
languages offer this in some way including C++, Java, Delphi
and C#. If you have used any of those programming languages
before you are probably already familiar with the concept.

In the most simple form you can use them to create type
specialized containers, graphs or this:

struct Matrix(T, size_t width, size_t height)
    if (isNumeric!T)
{
    ...
}

(A matrix with a fixed width and height that can be used if T
 is a built-in integer or floating point type.)

-- 
Marco



More information about the Digitalmars-d-learn mailing list