Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions cpptod.dd
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Foo

$(H4 The D Way)

Constructors are defined with the this keyword:
Constructors are defined with the `this` keyword:

------
class Foo
Expand Down Expand Up @@ -76,7 +76,7 @@ class B : A

$(H4 The D Way)

The base class constructor is called with the super syntax:
The base class constructor is called with the `super` syntax:

------
class A { this() { ... } }
Expand Down Expand Up @@ -573,24 +573,33 @@ void test()
$(H4 The D Way)

The D version is analogous, though a little simpler, taking
advantage of promotion of single template members to the
advantage of
$(HTTPS dlang.org/spec/template.html#implicit_template_properties,
Eponymous Templates) - promotion of single template members to the
enclosing name space:

------
template factorial(int n)
{
enum { factorial = n * .factorial!(n-1) }
enum factorial = n * .factorial!(n-1);
}

template factorial(int n : 1)
{
enum { factorial = 1 }
enum factorial = 1;
}

void test()
{
writefln("%d", factorial!(4)); // prints 24
writeln(factorial!(4)); // prints 24
}
------
The template blocks can be made shorter using
$(HTTPS dlang.org/spec/template.html#variable-template,
Enum Template) syntax:
------
enum factorial(int n) = n * .factorial!(n-1);

enum factorial(int n : 1) = 1;
------

<hr>$(COMMENT -------------------------------------------- )
Expand Down Expand Up @@ -800,7 +809,7 @@ template IsFunctionT(T)

void test()
{
typedef int fp(int);
alias int fp(int);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new alias syntax please

Copy link
Contributor Author

@ntrel ntrel Jan 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how, I tried alias fp = int function(int) but that didn't work.

edit: It fails is(fp == function).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I've run into this issue before. If it is what I think it is, it's not possible to translate this to the new alias syntax.


assert(IsFunctionT!(fp) == 1);
}
Expand Down
26 changes: 13 additions & 13 deletions ctod.dd
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ sizeof(struct Foo)

$(H4 The D Way)

$(P Use the size property:)
$(P Use the `sizeof` property:)

----------------------------
int.sizeof
Expand Down Expand Up @@ -137,8 +137,8 @@ _Imaginary long double =&gt; ireal
_Complex long double =&gt; creal
)
$(P
Although char is an unsigned 8 bit type, and
wchar is an unsigned 16 bit type, they have their own separate types
Although `char` is an unsigned 8-bit type, and
`wchar` is an unsigned 16-bit type, they have their own separate types
in order to aid overloading and type safety.
)
$(P Ints and unsigneds in C are of varying size; not so in D.)
Expand Down Expand Up @@ -194,7 +194,7 @@ long double r = fmodl(x,y);

$(H4 The D Way)

D supports the remainder ('%') operator on floating point operands:
D supports the remainder (`%`) operator on floating point operands:

----------------------------
float f = x % y;
Expand Down Expand Up @@ -295,7 +295,7 @@ for (i = 0; i &lt; sizeof(array) / sizeof(array[0]); i++)

$(H4 The D Way)

The length of an array is accessible through the property "length".
The length of an array is accessible through the `length` property.

----------------------------
int[17] array;
Expand All @@ -319,7 +319,7 @@ foreach (value; array)
func(value);
----------------------------

or through the ref keyword (for reference access):
or through the `ref` keyword (for reference access):

----------------------------
int[17] array;
Expand Down Expand Up @@ -406,7 +406,7 @@ memcpy(s + lens, hello, sizeof(hello));

$(H4 The D Way)

D overloads the operators ~ and ~= for char and wchar arrays to mean
D overloads the operators `~` and `~=` for char and wchar arrays to mean
concatenate and append, respectively:

----------------------------
Expand Down Expand Up @@ -582,7 +582,7 @@ $(H3 <a name="tagspace">Struct tag name space</a>)

$(H4 The C Way)

It's annoying to have to put the struct keyword every time a type is specified,
It's annoying to have to use the `struct` keyword every time a type is specified,
so a common idiom is to use:

$(CCODE
Expand Down Expand Up @@ -1181,7 +1181,7 @@ if (strcmp(str, "betty") == 0) // do strings match?

$(H4 The D Way)

Why not use the == operator?
Why not use the `==` operator?

-----------------------------
string str = "hello";
Expand Down Expand Up @@ -1394,7 +1394,7 @@ $(H3 <a name="ushr">Unsigned Right Shift</a>)

$(H4 The C Way)

The right shift operators &gt;&gt; and &gt;&gt;= are signed
The right shift operators `>>` and `>>=` are signed
shifts if the left operand is a signed integral type, and
are unsigned right shifts if the left operand is an unsigned
integral type. To produce an unsigned right shift on an int,
Expand Down Expand Up @@ -1422,9 +1422,9 @@ j = (unsigned)i >> 3;

$(H4 The D Way)

D has the right shift operators &gt;&gt; and &gt;&gt;= which
D has the right shift operators `>>` and `>>=` which
behave as they do in C. But D also has explicitly unsigned
right shift operators &gt;&gt;&gt; and &gt;&gt;&gt;= which will
right shift operators `>>>` and `>>>=` which will
do an unsigned right shift regardless of the sign of the left
operand. Hence,

Expand Down Expand Up @@ -1579,7 +1579,7 @@ int main()

$(H4 The D Way)

The ... following an array parameter declaration means that
The `...` following an array parameter declaration means that
the trailing arguments are collected together to form
an array. The arguments are type checked against the array
type, and the number of arguments becomes a property
Expand Down