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
4 changes: 0 additions & 4 deletions std/algorithm/iteration.d
Original file line number Diff line number Diff line change
Expand Up @@ -2654,7 +2654,6 @@ template reduce(fun...) if (fun.length >= 1)
If $(D r) is empty, an $(D Exception) is thrown.

Params:
fun = one or more functions
r = an iterable value as defined by $(D isIterable)

Returns:
Expand Down Expand Up @@ -2693,7 +2692,6 @@ template reduce(fun...) if (fun.length >= 1)
Use $(D fold) instead of $(D reduce) to use the seed version in a UFCS chain.

Params:
fun = one or more functions
seed = the initial value of the accumulator
r = an iterable value as defined by $(D isIterable)

Expand Down Expand Up @@ -3170,7 +3168,6 @@ if (fun.length >= 1)
Once `S` has been determined, then $(D S s = e;) and $(D s = f(s, e);) must
both be legal.
Params:
fun = one or more functions
range = an input range as defined by `isInputRange`
Returns:
a range containing the consecutive reduced values.
Expand All @@ -3189,7 +3186,6 @@ if (fun.length >= 1)
`cumulativeFold` will operate on an unqualified copy. If this happens
then the returned type will not perfectly match `S`.
Params:
fun = one or more functions
range = an input range as defined by `isInputRange`
seed = the initial value of the accumulator
Returns:
Expand Down
4 changes: 2 additions & 2 deletions std/exception.d
Original file line number Diff line number Diff line change
Expand Up @@ -2143,8 +2143,8 @@ pure nothrow @safe unittest
Convenience mixin for trivially sub-classing exceptions

Even trivially sub-classing an exception involves writing boilerplate code
for the constructor to: 1) correctly pass in the source file and line number
the exception was thrown from; 2) be usable with $(LREF enforce) which
for the constructor to: 1$(RPAREN) correctly pass in the source file and line number
the exception was thrown from; 2$(RPAREN) be usable with $(LREF enforce) which
expects exception constructors to take arguments in a fixed order. This
mixin provides that boilerplate code.

Expand Down
26 changes: 12 additions & 14 deletions std/range/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -1853,18 +1853,27 @@ Lazily takes only up to `n` elements of a range. This is
particularly useful when using with infinite ranges.

Unlike $(LREF takeExactly), `take` does not require that there
are `n` or more elements in `r`. As a consequence, length
information is not applied to the result unless `r` also has
are `n` or more elements in `input`. As a consequence, length
information is not applied to the result unless `input` also has
length information.

Params:
r = an input range to iterate over up to `n` times
input = an input range to iterate over up to `n` times
n = the number of elements to take

Returns:
At minimum, an input range. If the range offers random access
and `length`, `take` offers them as well.
*/
Take!R take(R)(R input, size_t n)
if (isInputRange!(Unqual!R) && !isInfinite!(Unqual!R) && hasSlicing!(Unqual!R) &&
!is(R T == Take!T))
{
import std.algorithm.comparison : min;
return input[0 .. min(n, input.length)];
}

/// ditto
struct Take(Range)
if (isInputRange!(Unqual!Range) &&
//take _cannot_ test hasSlicing on infinite ranges, because hasSlicing uses
Expand Down Expand Up @@ -2054,17 +2063,6 @@ if (isInputRange!(Unqual!Range) &&
}
}

/// ditto
Take!R take(R)(R input, size_t n)
if (isInputRange!(Unqual!R) && !isInfinite!(Unqual!R) && hasSlicing!(Unqual!R) &&
!is(R T == Take!T))
{
// @@@BUG@@@
//return input[0 .. min(n, $)];
import std.algorithm.comparison : min;
return input[0 .. min(n, input.length)];
}

/**
This template simply aliases itself to R and is useful for consistency in
generic code.
Expand Down
74 changes: 18 additions & 56 deletions std/socket.d
Original file line number Diff line number Diff line change
Expand Up @@ -629,48 +629,18 @@ private mixin template socketOSExceptionCtors()


/**
* Class for exceptions thrown from an $(D InternetHost).
* Class for exceptions thrown from an `InternetHost`.
*/
class HostException: SocketOSException
{
mixin socketOSExceptionCtors;
}

/**
* $(D InternetHost) is a class for resolving IPv4 addresses.
* `InternetHost` is a class for resolving IPv4 addresses.
*
* Consider using $(D getAddress), $(D parseAddress) and $(D Address) methods
* Consider using `getAddress`, `parseAddress` and `Address` methods
* instead of using this class directly.
*
* Example:
* ---
* auto ih = new InternetHost;
*
* // Forward lookup
* writeln("About www.digitalmars.com:");
* if (ih.getHostByName("www.digitalmars.com"))
* {
* writefln(" Name: %s", ih.name);
* auto ip = InternetAddress.addrToString(ih.addrList[0]);
* writefln(" IP address: %s", ip);
* foreach (string s; ih.aliases)
* writefln(" Alias: %s", s);
* writeln("---");
*
* // Reverse lookup
* writefln("About IP %s:", ip);
* if (ih.getHostByAddr(ih.addrList[0]))
* {
* writefln(" Name: %s", ih.name);
* foreach (string s; ih.aliases)
* writefln(" Alias: %s", s);
* }
* else
* writeln(" Reverse lookup failed");
* }
* else
* writeln(" Can't resolve www.digitalmars.com");
* ---
*/
class InternetHost
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed Example from ddoc and just made the unittest part of the docs, because:

  • it was doing the same thing
  • in case of a change in the API, we do not need to worry about modifying the example as well (that is why we have ///unittest)

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes in general ddoced examples are horrible, because we can't ensure that they even compile.
As I seem not to be able to add a comment in the lines outside of the diff: maybe you could replace the commented writefln with assert's, so that it won't look to weird to a reader?
Note that for the rendered documentation we are considering to replace assert's like a == b automatically with a writeln equivalent

{
Expand Down Expand Up @@ -824,7 +794,7 @@ class InternetHost
}
}


///
@safe unittest
Copy link
Contributor

Choose a reason for hiding this comment

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

We now verify with CircleCi that public examples are runnable (also part of the style Makefile target)

out/std_socket.d(13): Deprecation: std.socket.softUnittest is not visible from module std_socket
out/std_socket.d(13): Error: function std.socket.softUnittest is not accessible from module std_socket

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I missed that softUnittest has a private scope. Fixed it

{
InternetHost ih = new InternetHost;
Expand All @@ -834,29 +804,21 @@ class InternetHost
ih.getHostByAddr("127.0.0.1");
assert(ih.addrList[0] == 0x7F_00_00_01);

softUnittest({
if (!ih.getHostByName("www.digitalmars.com"))
return; // don't fail if not connected to internet
//writefln("addrList.length = %d", ih.addrList.length);
assert(ih.addrList.length);
InternetAddress ia = new InternetAddress(ih.addrList[0], InternetAddress.PORT_ANY);
assert(ih.name == "www.digitalmars.com" || ih.name == "digitalmars.com",
ih.name);
// writefln("IP address = %s", ia.toAddrString());
// writefln("name = %s", ih.name);
// foreach (int i, string s; ih.aliases)
// {
// writefln("aliases[%d] = %s", i, s);
// }
// writefln("---");
if (!ih.getHostByName("www.digitalmars.com"))
return; // don't fail if not connected to internet

//assert(ih.getHostByAddr(ih.addrList[0]));
// writefln("name = %s", ih.name);
// foreach (int i, string s; ih.aliases)
// {
// writefln("aliases[%d] = %s", i, s);
// }
});
assert(ih.addrList.length);
InternetAddress ia = new InternetAddress(ih.addrList[0], InternetAddress.PORT_ANY);
assert(ih.name == "www.digitalmars.com" || ih.name == "digitalmars.com",
ih.name);

assert(ih.getHostByAddr(ih.addrList[0]));
string getHostNameFromInt = ih.name.dup;

assert(ih.getHostByAddr(ia.toAddrString()));
string getHostNameFromStr = ih.name.dup;

assert(getHostNameFromInt == getHostNameFromStr);
}


Expand Down
1 change: 0 additions & 1 deletion std/stdio.d
Original file line number Diff line number Diff line change
Expand Up @@ -2350,7 +2350,6 @@ $(REF readText, std,file)
Range primitives may throw $(D StdioException) on I/O error.

Params:
file = file handle to parse from
format = tuple record $(REF_ALTTEXT _format, formattedRead, std, _format)

Returns:
Expand Down
5 changes: 2 additions & 3 deletions std/utf.d
Original file line number Diff line number Diff line change
Expand Up @@ -3527,13 +3527,12 @@ int impureVariable;
*
* Params:
* C = `char`, `wchar`, or `dchar`
* r = input range of characters, or array of characters
* Returns:
* A forward range if r is a range and not auto-decodable, as defined by
* A forward range if `R` is a range and not auto-decodable, as defined by
* $(REF isAutodecodableString, std, traits), and if the base range is
* also a forward range.
*
* Or, if r is a range and it is auto-decodable and
* Or, if `R` is a range and it is auto-decodable and
* `is(ElementEncodingType!typeof(r) == C)`, then the range is passed
* to $(LREF byCodeUnit).
*
Expand Down