Compare commits
21 Commits
Author | SHA1 | Date | |
---|---|---|---|
2946fd7f81 | |||
2cda82eeea | |||
e9f70853c6 | |||
4aaa71a7d0 | |||
cbc68c2c43 | |||
048ddf21ff | |||
fd02c411e1 | |||
b69d737845 | |||
904451ccaa | |||
c1864cf473 | |||
8db1851c5c | |||
12de700706 | |||
78a8afdf75 | |||
3c996d7c57 | |||
2a68048fc1 | |||
907f7a4e61 | |||
670328c047 | |||
7fe69ccc5c | |||
26c3532e28 | |||
75ce854192 | |||
9e16d84f9e |
@ -7,9 +7,9 @@ os:
|
|||||||
language: d
|
language: d
|
||||||
|
|
||||||
d:
|
d:
|
||||||
- dmd-2.077.0
|
- dmd-2.078.2
|
||||||
|
- dmd-2.077.1
|
||||||
- dmd-2.076.1
|
- dmd-2.076.1
|
||||||
- dmd-2.075.1
|
|
||||||
|
|
||||||
env:
|
env:
|
||||||
matrix:
|
matrix:
|
||||||
@ -22,7 +22,7 @@ addons:
|
|||||||
- gcc-multilib
|
- gcc-multilib
|
||||||
|
|
||||||
before_script:
|
before_script:
|
||||||
- if [ "$PS1" = '(dmd-2.077.0)' ]; then
|
- if [ "$PS1" = '(dmd-2.078.2)' ]; then
|
||||||
export UNITTEST="unittest-cov";
|
export UNITTEST="unittest-cov";
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
13
README.md
13
README.md
@ -12,8 +12,8 @@ Tanya is a general purpose library for D programming language.
|
|||||||
Its aim is to simplify the manual memory management in D and to provide a
|
Its aim is to simplify the manual memory management in D and to provide a
|
||||||
guarantee with @nogc attribute that there are no hidden allocations on the
|
guarantee with @nogc attribute that there are no hidden allocations on the
|
||||||
Garbage Collector heap. Everything in the library is usable in @nogc code.
|
Garbage Collector heap. Everything in the library is usable in @nogc code.
|
||||||
Tanya extends Phobos functionality and provides alternative implementations for
|
Tanya provides data structures and utilities to facilitate painless systems
|
||||||
data structures and utilities that depend on the Garbage Collector in Phobos.
|
programming in D.
|
||||||
|
|
||||||
* [API Documentation](https://docs.caraus.io/tanya)
|
* [API Documentation](https://docs.caraus.io/tanya)
|
||||||
* [Contribution guidelines](CONTRIBUTING.md)
|
* [Contribution guidelines](CONTRIBUTING.md)
|
||||||
@ -149,9 +149,9 @@ There are more containers in the `tanya.container` package.
|
|||||||
|
|
||||||
| DMD | GCC |
|
| DMD | GCC |
|
||||||
|:-------:|:--------------:|
|
|:-------:|:--------------:|
|
||||||
| 2.077.0 | *gdc-5* branch |
|
| 2.078.2 | *gdc-5* branch |
|
||||||
|
| 2.077.1 | |
|
||||||
| 2.076.1 | |
|
| 2.076.1 | |
|
||||||
| 2.075.1 | |
|
|
||||||
|
|
||||||
### Current status
|
### Current status
|
||||||
|
|
||||||
@ -161,13 +161,10 @@ Following modules are under development:
|
|||||||
|----------|:---------:|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|----------|:---------:|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
| BitArray | bitvector | [](https://travis-ci.org/caraus-ecms/tanya) [](https://ci.appveyor.com/project/belka-ew/tanya/branch/bitvector) |
|
| BitArray | bitvector | [](https://travis-ci.org/caraus-ecms/tanya) [](https://ci.appveyor.com/project/belka-ew/tanya/branch/bitvector) |
|
||||||
| TLS | crypto | [](https://travis-ci.org/caraus-ecms/tanya) [](https://ci.appveyor.com/project/belka-ew/tanya/branch/crypto) |
|
| TLS | crypto | [](https://travis-ci.org/caraus-ecms/tanya) [](https://ci.appveyor.com/project/belka-ew/tanya/branch/crypto) |
|
||||||
| File IO | io | [](https://travis-ci.org/caraus-ecms/tanya) [](https://ci.appveyor.com/project/belka-ew/tanya/branch/io) |
|
|
||||||
|
|
||||||
### Release management
|
### Release management
|
||||||
|
|
||||||
3-week release cycle.
|
Deprecated features are removed after one release that includes these deprecations.
|
||||||
|
|
||||||
Deprecated features are removed after one release (in approximately 6 weeks after deprecating).
|
|
||||||
|
|
||||||
## Further characteristics
|
## Further characteristics
|
||||||
|
|
||||||
|
16
appveyor.yml
16
appveyor.yml
@ -4,10 +4,16 @@ os: Visual Studio 2015
|
|||||||
environment:
|
environment:
|
||||||
matrix:
|
matrix:
|
||||||
- DC: dmd
|
- DC: dmd
|
||||||
DVersion: 2.077.0
|
DVersion: 2.078.2
|
||||||
arch: x64
|
arch: x64
|
||||||
- DC: dmd
|
- DC: dmd
|
||||||
DVersion: 2.077.0
|
DVersion: 2.078.2
|
||||||
|
arch: x86
|
||||||
|
- DC: dmd
|
||||||
|
DVersion: 2.077.1
|
||||||
|
arch: x64
|
||||||
|
- DC: dmd
|
||||||
|
DVersion: 2.077.1
|
||||||
arch: x86
|
arch: x86
|
||||||
- DC: dmd
|
- DC: dmd
|
||||||
DVersion: 2.076.1
|
DVersion: 2.076.1
|
||||||
@ -15,12 +21,6 @@ environment:
|
|||||||
- DC: dmd
|
- DC: dmd
|
||||||
DVersion: 2.076.1
|
DVersion: 2.076.1
|
||||||
arch: x86
|
arch: x86
|
||||||
- DC: dmd
|
|
||||||
DVersion: 2.075.1
|
|
||||||
arch: x64
|
|
||||||
- DC: dmd
|
|
||||||
DVersion: 2.075.1
|
|
||||||
arch: x86
|
|
||||||
|
|
||||||
skip_tags: true
|
skip_tags: true
|
||||||
|
|
||||||
|
@ -37,6 +37,11 @@ _D5tanya6memory2op10fillMemoryFNaNbNiAvmZv:
|
|||||||
|
|
||||||
mov %rsi, %r8
|
mov %rsi, %r8
|
||||||
|
|
||||||
|
// If the length is less than the number of misaligned bytes,
|
||||||
|
// write one byte at a time and exit
|
||||||
|
cmp %rax, %rcx
|
||||||
|
jg aligned_1
|
||||||
|
|
||||||
naligned:
|
naligned:
|
||||||
mov %dl, (%r8) // Write a byte
|
mov %dl, (%r8) // Write a byte
|
||||||
|
|
||||||
|
7
dub.json
7
dub.json
@ -12,7 +12,12 @@
|
|||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"name": "library",
|
"name": "library",
|
||||||
"targetType": "library",
|
"targetType": "staticLibrary",
|
||||||
|
"versions": ["TanyaPhobos"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "dynamic",
|
||||||
|
"targetType": "dynamicLibrary",
|
||||||
"versions": ["TanyaPhobos"]
|
"versions": ["TanyaPhobos"]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -77,7 +77,7 @@ in
|
|||||||
{
|
{
|
||||||
assert(&source !is &target, "Source and target must be different");
|
assert(&source !is &target, "Source and target must be different");
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
static if (is(T == struct) || isStaticArray!T)
|
static if (is(T == struct) || isStaticArray!T)
|
||||||
{
|
{
|
||||||
|
@ -72,7 +72,7 @@ final class StreamTransport : SocketWatcher, DuplexTransport, SocketTransport
|
|||||||
{
|
{
|
||||||
assert(socket !is null);
|
assert(socket !is null);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
return cast(OverlappedConnectedSocket) socket_;
|
return cast(OverlappedConnectedSocket) socket_;
|
||||||
}
|
}
|
||||||
@ -130,7 +130,7 @@ final class StreamTransport : SocketWatcher, DuplexTransport, SocketTransport
|
|||||||
{
|
{
|
||||||
assert(protocol !is null);
|
assert(protocol !is null);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
protocol_ = protocol;
|
protocol_ = protocol;
|
||||||
}
|
}
|
||||||
@ -270,7 +270,7 @@ final class IOCPLoop : Loop
|
|||||||
{
|
{
|
||||||
assert(transport !is null);
|
assert(transport !is null);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
transport.socket.shutdown();
|
transport.socket.shutdown();
|
||||||
defaultAllocator.dispose(transport.socket);
|
defaultAllocator.dispose(transport.socket);
|
||||||
|
@ -61,7 +61,7 @@ package class StreamTransport : SocketWatcher, DuplexTransport, SocketTransport
|
|||||||
{
|
{
|
||||||
assert(loop !is null);
|
assert(loop !is null);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
super(socket);
|
super(socket);
|
||||||
this.loop = loop;
|
this.loop = loop;
|
||||||
@ -80,7 +80,7 @@ package class StreamTransport : SocketWatcher, DuplexTransport, SocketTransport
|
|||||||
{
|
{
|
||||||
assert(socket !is null);
|
assert(socket !is null);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
return cast(ConnectedSocket) socket_;
|
return cast(ConnectedSocket) socket_;
|
||||||
}
|
}
|
||||||
@ -91,7 +91,7 @@ package class StreamTransport : SocketWatcher, DuplexTransport, SocketTransport
|
|||||||
{
|
{
|
||||||
assert(socket !is null);
|
assert(socket !is null);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
socket_ = socket;
|
socket_ = socket;
|
||||||
}
|
}
|
||||||
@ -120,7 +120,7 @@ package class StreamTransport : SocketWatcher, DuplexTransport, SocketTransport
|
|||||||
{
|
{
|
||||||
assert(protocol !is null);
|
assert(protocol !is null);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
protocol_ = protocol;
|
protocol_ = protocol;
|
||||||
}
|
}
|
||||||
@ -263,7 +263,7 @@ abstract class SelectorLoop : Loop
|
|||||||
{
|
{
|
||||||
assert(transport !is null);
|
assert(transport !is null);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
transport.socket.shutdown();
|
transport.socket.shutdown();
|
||||||
defaultAllocator.dispose(transport.socket);
|
defaultAllocator.dispose(transport.socket);
|
||||||
@ -289,7 +289,7 @@ abstract class SelectorLoop : Loop
|
|||||||
{
|
{
|
||||||
assert(transport !is null);
|
assert(transport !is null);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
while (transport.input.length && transport.writeReady)
|
while (transport.input.length && transport.writeReady)
|
||||||
{
|
{
|
||||||
@ -356,7 +356,7 @@ abstract class SelectorLoop : Loop
|
|||||||
{
|
{
|
||||||
assert(connection !is null);
|
assert(connection !is null);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
|
@ -326,7 +326,7 @@ abstract class Loop
|
|||||||
assert(blockTime <= 1.dur!"hours", "Too long to wait.");
|
assert(blockTime <= 1.dur!"hours", "Too long to wait.");
|
||||||
assert(!blockTime.isNegative);
|
assert(!blockTime.isNegative);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
blockTime_ = blockTime;
|
blockTime_ = blockTime;
|
||||||
}
|
}
|
||||||
@ -414,7 +414,7 @@ in
|
|||||||
{
|
{
|
||||||
assert(loop !is null);
|
assert(loop !is null);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
defaultLoop_ = loop;
|
defaultLoop_ = loop;
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ abstract class SocketWatcher : Watcher
|
|||||||
{
|
{
|
||||||
assert(socket !is null);
|
assert(socket !is null);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
socket_ = socket;
|
socket_ = socket;
|
||||||
}
|
}
|
||||||
@ -123,7 +123,7 @@ class ConnectionWatcher : SocketWatcher
|
|||||||
{
|
{
|
||||||
assert(protocolFactory !is null, "Protocol isn't set.");
|
assert(protocolFactory !is null, "Protocol isn't set.");
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
foreach (transport; incoming)
|
foreach (transport; incoming)
|
||||||
{
|
{
|
||||||
|
@ -56,7 +56,7 @@ struct Range(A)
|
|||||||
assert(begin >= container.data);
|
assert(begin >= container.data);
|
||||||
assert(end <= container.data + container.length);
|
assert(end <= container.data + container.length);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
this.container = &container;
|
this.container = &container;
|
||||||
this.begin = begin;
|
this.begin = begin;
|
||||||
@ -87,7 +87,7 @@ struct Range(A)
|
|||||||
{
|
{
|
||||||
assert(!empty);
|
assert(!empty);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
return *this.begin;
|
return *this.begin;
|
||||||
}
|
}
|
||||||
@ -97,7 +97,7 @@ struct Range(A)
|
|||||||
{
|
{
|
||||||
assert(!empty);
|
assert(!empty);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
return *(this.end - 1);
|
return *(this.end - 1);
|
||||||
}
|
}
|
||||||
@ -107,7 +107,7 @@ struct Range(A)
|
|||||||
{
|
{
|
||||||
assert(!empty);
|
assert(!empty);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
++this.begin;
|
++this.begin;
|
||||||
}
|
}
|
||||||
@ -117,7 +117,7 @@ struct Range(A)
|
|||||||
{
|
{
|
||||||
assert(!empty);
|
assert(!empty);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
--this.end;
|
--this.end;
|
||||||
}
|
}
|
||||||
@ -127,7 +127,7 @@ struct Range(A)
|
|||||||
{
|
{
|
||||||
assert(i < length);
|
assert(i < length);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
return *(this.begin + i);
|
return *(this.begin + i);
|
||||||
}
|
}
|
||||||
@ -148,7 +148,7 @@ struct Range(A)
|
|||||||
assert(i <= j);
|
assert(i <= j);
|
||||||
assert(j <= length);
|
assert(j <= length);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
return typeof(return)(*this.container, this.begin + i, this.begin + j);
|
return typeof(return)(*this.container, this.begin + i, this.begin + j);
|
||||||
}
|
}
|
||||||
@ -159,7 +159,7 @@ struct Range(A)
|
|||||||
assert(i <= j);
|
assert(i <= j);
|
||||||
assert(j <= length);
|
assert(j <= length);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
return typeof(return)(*this.container, this.begin + i, this.begin + j);
|
return typeof(return)(*this.container, this.begin + i, this.begin + j);
|
||||||
}
|
}
|
||||||
@ -333,7 +333,7 @@ struct Array(T)
|
|||||||
{
|
{
|
||||||
assert(allocator !is null);
|
assert(allocator !is null);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
allocator_ = allocator;
|
allocator_ = allocator;
|
||||||
}
|
}
|
||||||
@ -597,7 +597,7 @@ struct Array(T)
|
|||||||
{
|
{
|
||||||
assert(!empty);
|
assert(!empty);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
length = length - 1;
|
length = length - 1;
|
||||||
}
|
}
|
||||||
@ -619,7 +619,7 @@ struct Array(T)
|
|||||||
{
|
{
|
||||||
assert(removed <= howMany);
|
assert(removed <= howMany);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
const toRemove = min(howMany, length);
|
const toRemove = min(howMany, length);
|
||||||
|
|
||||||
@ -662,7 +662,7 @@ struct Array(T)
|
|||||||
assert(r.begin >= this.data);
|
assert(r.begin >= this.data);
|
||||||
assert(r.end <= this.data + length);
|
assert(r.end <= this.data + length);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
auto target = r.begin;
|
auto target = r.begin;
|
||||||
for (auto source = r.end; source != end; ++source, ++target)
|
for (auto source = r.end; source != end; ++source, ++target)
|
||||||
@ -821,7 +821,7 @@ struct Array(T)
|
|||||||
assert(r.begin >= this.data);
|
assert(r.begin >= this.data);
|
||||||
assert(r.end <= this.data + length);
|
assert(r.end <= this.data + length);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
const oldLen = length;
|
const oldLen = length;
|
||||||
const offset = r.end - this.data;
|
const offset = r.end - this.data;
|
||||||
@ -838,7 +838,7 @@ struct Array(T)
|
|||||||
assert(r.begin >= this.data);
|
assert(r.begin >= this.data);
|
||||||
assert(r.end <= this.data + length);
|
assert(r.end <= this.data + length);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
return insertAfter!(T[])(r, el[]);
|
return insertAfter!(T[])(r, el[]);
|
||||||
}
|
}
|
||||||
@ -852,7 +852,7 @@ struct Array(T)
|
|||||||
assert(r.begin >= this.data);
|
assert(r.begin >= this.data);
|
||||||
assert(r.end <= this.data + length);
|
assert(r.end <= this.data + length);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
const oldLen = length;
|
const oldLen = length;
|
||||||
const offset = r.end - this.data;
|
const offset = r.end - this.data;
|
||||||
@ -881,7 +881,7 @@ struct Array(T)
|
|||||||
assert(r.begin >= this.data);
|
assert(r.begin >= this.data);
|
||||||
assert(r.end <= this.data + length);
|
assert(r.end <= this.data + length);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
return insertAfter(Range(this, this.data, r.begin), el);
|
return insertAfter(Range(this, this.data, r.begin), el);
|
||||||
}
|
}
|
||||||
@ -894,7 +894,7 @@ struct Array(T)
|
|||||||
assert(r.begin >= this.data);
|
assert(r.begin >= this.data);
|
||||||
assert(r.end <= this.data + length);
|
assert(r.end <= this.data + length);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
return insertBefore!(T[])(r, el[]);
|
return insertBefore!(T[])(r, el[]);
|
||||||
}
|
}
|
||||||
@ -908,7 +908,7 @@ struct Array(T)
|
|||||||
assert(r.begin >= this.data);
|
assert(r.begin >= this.data);
|
||||||
assert(r.end <= this.data + length);
|
assert(r.end <= this.data + length);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
const oldLen = length;
|
const oldLen = length;
|
||||||
const offset = r.begin - this.data;
|
const offset = r.begin - this.data;
|
||||||
@ -1080,7 +1080,7 @@ struct Array(T)
|
|||||||
{
|
{
|
||||||
assert(length > pos);
|
assert(length > pos);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
return *(this.data + pos);
|
return *(this.data + pos);
|
||||||
}
|
}
|
||||||
@ -1185,7 +1185,7 @@ struct Array(T)
|
|||||||
{
|
{
|
||||||
assert(!empty);
|
assert(!empty);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
return *this.data;
|
return *this.data;
|
||||||
}
|
}
|
||||||
@ -1212,7 +1212,7 @@ struct Array(T)
|
|||||||
{
|
{
|
||||||
assert(!empty);
|
assert(!empty);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
return *(this.data + length - 1);
|
return *(this.data + length - 1);
|
||||||
}
|
}
|
||||||
@ -1245,7 +1245,7 @@ struct Array(T)
|
|||||||
assert(i <= j);
|
assert(i <= j);
|
||||||
assert(j <= length);
|
assert(j <= length);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
return typeof(return)(this, this.data + i, this.data + j);
|
return typeof(return)(this, this.data + i, this.data + j);
|
||||||
}
|
}
|
||||||
@ -1257,7 +1257,7 @@ struct Array(T)
|
|||||||
assert(i <= j);
|
assert(i <= j);
|
||||||
assert(j <= length);
|
assert(j <= length);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
return typeof(return)(this, this.data + i, this.data + j);
|
return typeof(return)(this, this.data + i, this.data + j);
|
||||||
}
|
}
|
||||||
@ -1328,7 +1328,7 @@ struct Array(T)
|
|||||||
assert(i <= j);
|
assert(i <= j);
|
||||||
assert(j <= length);
|
assert(j <= length);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
copy(value[], this.data[i .. j]);
|
copy(value[], this.data[i .. j]);
|
||||||
return opSlice(i, j);
|
return opSlice(i, j);
|
||||||
@ -1342,7 +1342,7 @@ struct Array(T)
|
|||||||
assert(i <= j);
|
assert(i <= j);
|
||||||
assert(j <= length);
|
assert(j <= length);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
fill(this.data[i .. j], value);
|
fill(this.data[i .. j], value);
|
||||||
return opSlice(i, j);
|
return opSlice(i, j);
|
||||||
@ -1356,7 +1356,7 @@ struct Array(T)
|
|||||||
assert(j <= length);
|
assert(j <= length);
|
||||||
assert(j - i == value.length);
|
assert(j - i == value.length);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
copy(value, this.data[i .. j]);
|
copy(value, this.data[i .. j]);
|
||||||
return opSlice(i, j);
|
return opSlice(i, j);
|
||||||
|
@ -27,7 +27,7 @@ version (unittest)
|
|||||||
{
|
{
|
||||||
assert(start < end);
|
assert(start < end);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
auto numberRead = end - start;
|
auto numberRead = end - start;
|
||||||
for (ubyte i; i < numberRead; ++i)
|
for (ubyte i; i < numberRead; ++i)
|
||||||
@ -106,7 +106,7 @@ struct ReadBuffer(T = ubyte)
|
|||||||
{
|
{
|
||||||
assert(allocator_ is null);
|
assert(allocator_ is null);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
allocator_ = allocator;
|
allocator_ = allocator;
|
||||||
}
|
}
|
||||||
@ -349,7 +349,7 @@ struct WriteBuffer(T = ubyte)
|
|||||||
assert(size > 0);
|
assert(size > 0);
|
||||||
assert(allocator !is null);
|
assert(allocator !is null);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
blockSize = size;
|
blockSize = size;
|
||||||
ring = size - 1;
|
ring = size - 1;
|
||||||
@ -549,7 +549,7 @@ struct WriteBuffer(T = ubyte)
|
|||||||
{
|
{
|
||||||
assert(length <= this.length);
|
assert(length <= this.length);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
auto afterRing = ring + 1;
|
auto afterRing = ring + 1;
|
||||||
auto oldStart = start;
|
auto oldStart = start;
|
||||||
|
@ -64,7 +64,7 @@ struct SRange(L)
|
|||||||
{
|
{
|
||||||
assert(!empty);
|
assert(!empty);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
return (*this.head).content;
|
return (*this.head).content;
|
||||||
}
|
}
|
||||||
@ -74,7 +74,7 @@ struct SRange(L)
|
|||||||
{
|
{
|
||||||
assert(!empty);
|
assert(!empty);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
this.head = &(*this.head).next;
|
this.head = &(*this.head).next;
|
||||||
}
|
}
|
||||||
@ -205,7 +205,7 @@ struct SList(T)
|
|||||||
{
|
{
|
||||||
assert(allocator !is null);
|
assert(allocator !is null);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
this.allocator_ = allocator;
|
this.allocator_ = allocator;
|
||||||
}
|
}
|
||||||
@ -325,7 +325,7 @@ struct SList(T)
|
|||||||
{
|
{
|
||||||
assert(!empty);
|
assert(!empty);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
return this.head.content;
|
return this.head.content;
|
||||||
}
|
}
|
||||||
@ -467,7 +467,7 @@ struct SList(T)
|
|||||||
{
|
{
|
||||||
assert(checkRangeBelonging(r));
|
assert(checkRangeBelonging(r));
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
return moveEntry(*r.head, el);
|
return moveEntry(*r.head, el);
|
||||||
}
|
}
|
||||||
@ -490,7 +490,7 @@ struct SList(T)
|
|||||||
{
|
{
|
||||||
assert(checkRangeBelonging(r));
|
assert(checkRangeBelonging(r));
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
size_t inserted;
|
size_t inserted;
|
||||||
foreach (e; el)
|
foreach (e; el)
|
||||||
@ -519,7 +519,7 @@ struct SList(T)
|
|||||||
{
|
{
|
||||||
assert(checkRangeBelonging(r));
|
assert(checkRangeBelonging(r));
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
*r.head = allocator.make!Entry(el, *r.head);
|
*r.head = allocator.make!Entry(el, *r.head);
|
||||||
return 1;
|
return 1;
|
||||||
@ -641,7 +641,7 @@ struct SList(T)
|
|||||||
{
|
{
|
||||||
assert(!empty);
|
assert(!empty);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
auto n = this.head.next;
|
auto n = this.head.next;
|
||||||
|
|
||||||
@ -680,7 +680,7 @@ struct SList(T)
|
|||||||
{
|
{
|
||||||
assert(removed <= howMany);
|
assert(removed <= howMany);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
for (; i < howMany && !empty; ++i)
|
for (; i < howMany && !empty; ++i)
|
||||||
@ -716,7 +716,7 @@ struct SList(T)
|
|||||||
{
|
{
|
||||||
assert(checkRangeBelonging(r));
|
assert(checkRangeBelonging(r));
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
auto outOfScopeList = typeof(this)(allocator);
|
auto outOfScopeList = typeof(this)(allocator);
|
||||||
outOfScopeList.head = *r.head;
|
outOfScopeList.head = *r.head;
|
||||||
@ -963,7 +963,7 @@ struct DRange(L)
|
|||||||
{
|
{
|
||||||
assert(!empty);
|
assert(!empty);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
return (*this.head).content;
|
return (*this.head).content;
|
||||||
}
|
}
|
||||||
@ -973,7 +973,7 @@ struct DRange(L)
|
|||||||
{
|
{
|
||||||
assert(!empty);
|
assert(!empty);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
return (*this.tail).content;
|
return (*this.tail).content;
|
||||||
}
|
}
|
||||||
@ -983,7 +983,7 @@ struct DRange(L)
|
|||||||
{
|
{
|
||||||
assert(!empty);
|
assert(!empty);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
this.head = &(*this.head).next;
|
this.head = &(*this.head).next;
|
||||||
}
|
}
|
||||||
@ -993,7 +993,7 @@ struct DRange(L)
|
|||||||
{
|
{
|
||||||
assert(!empty);
|
assert(!empty);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
this.tail = &(*this.tail).prev;
|
this.tail = &(*this.tail).prev;
|
||||||
}
|
}
|
||||||
@ -1135,7 +1135,7 @@ struct DList(T)
|
|||||||
{
|
{
|
||||||
assert(allocator !is null);
|
assert(allocator !is null);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
this.allocator_ = allocator;
|
this.allocator_ = allocator;
|
||||||
}
|
}
|
||||||
@ -1259,7 +1259,7 @@ struct DList(T)
|
|||||||
{
|
{
|
||||||
assert(!empty);
|
assert(!empty);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
return this.head.content;
|
return this.head.content;
|
||||||
}
|
}
|
||||||
@ -1272,7 +1272,7 @@ struct DList(T)
|
|||||||
{
|
{
|
||||||
assert(!empty);
|
assert(!empty);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
return this.tail.content;
|
return this.tail.content;
|
||||||
}
|
}
|
||||||
@ -1319,7 +1319,7 @@ struct DList(T)
|
|||||||
assert((retLength == 0 && head is null && tail is null)
|
assert((retLength == 0 && head is null && tail is null)
|
||||||
|| (retLength > 0 && head !is null && tail !is null));
|
|| (retLength > 0 && head !is null && tail !is null));
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
size_t retLength;
|
size_t retLength;
|
||||||
|
|
||||||
@ -1595,7 +1595,7 @@ struct DList(T)
|
|||||||
{
|
{
|
||||||
assert(checkRangeBelonging(r));
|
assert(checkRangeBelonging(r));
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
return moveFront(*r.head, el);
|
return moveFront(*r.head, el);
|
||||||
}
|
}
|
||||||
@ -1615,7 +1615,7 @@ struct DList(T)
|
|||||||
{
|
{
|
||||||
assert(checkRangeBelonging(r));
|
assert(checkRangeBelonging(r));
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
auto temp = allocator.make!Entry(el, *r.head);
|
auto temp = allocator.make!Entry(el, *r.head);
|
||||||
|
|
||||||
@ -1653,7 +1653,7 @@ struct DList(T)
|
|||||||
{
|
{
|
||||||
assert(checkRangeBelonging(r));
|
assert(checkRangeBelonging(r));
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
size_t inserted;
|
size_t inserted;
|
||||||
foreach (e; el)
|
foreach (e; el)
|
||||||
@ -1710,7 +1710,7 @@ struct DList(T)
|
|||||||
{
|
{
|
||||||
assert(checkRangeBelonging(r));
|
assert(checkRangeBelonging(r));
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
return moveBack(*r.tail, el);
|
return moveBack(*r.tail, el);
|
||||||
}
|
}
|
||||||
@ -1741,7 +1741,7 @@ struct DList(T)
|
|||||||
{
|
{
|
||||||
assert(checkRangeBelonging(r));
|
assert(checkRangeBelonging(r));
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
auto temp = allocator.make!Entry(el, null, *r.tail);
|
auto temp = allocator.make!Entry(el, null, *r.tail);
|
||||||
|
|
||||||
@ -1779,7 +1779,7 @@ struct DList(T)
|
|||||||
{
|
{
|
||||||
assert(checkRangeBelonging(r));
|
assert(checkRangeBelonging(r));
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
size_t inserted;
|
size_t inserted;
|
||||||
foreach (e; el)
|
foreach (e; el)
|
||||||
@ -1896,7 +1896,7 @@ struct DList(T)
|
|||||||
{
|
{
|
||||||
assert(!empty);
|
assert(!empty);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
auto n = this.head.next;
|
auto n = this.head.next;
|
||||||
|
|
||||||
@ -1932,7 +1932,7 @@ struct DList(T)
|
|||||||
{
|
{
|
||||||
assert(!empty);
|
assert(!empty);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
auto n = this.tail.prev;
|
auto n = this.tail.prev;
|
||||||
|
|
||||||
@ -1978,7 +1978,7 @@ struct DList(T)
|
|||||||
{
|
{
|
||||||
assert(removed <= howMany);
|
assert(removed <= howMany);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
for (; i < howMany && !empty; ++i)
|
for (; i < howMany && !empty; ++i)
|
||||||
@ -2005,7 +2005,7 @@ struct DList(T)
|
|||||||
{
|
{
|
||||||
assert(removed <= howMany);
|
assert(removed <= howMany);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
for (; i < howMany && !empty; ++i)
|
for (; i < howMany && !empty; ++i)
|
||||||
@ -2041,7 +2041,7 @@ struct DList(T)
|
|||||||
{
|
{
|
||||||
assert(checkRangeBelonging(r));
|
assert(checkRangeBelonging(r));
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
// Save references to the elements before and after the range.
|
// Save references to the elements before and after the range.
|
||||||
Entry* tailNext, headPrev;
|
Entry* tailNext, headPrev;
|
||||||
|
@ -167,7 +167,7 @@ struct Queue(T)
|
|||||||
{
|
{
|
||||||
assert(!empty);
|
assert(!empty);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
auto n = first.next;
|
auto n = first.next;
|
||||||
T ret = move(first.content);
|
T ret = move(first.content);
|
||||||
|
@ -76,7 +76,7 @@ struct Range(E)
|
|||||||
assert(this.dataRange.empty
|
assert(this.dataRange.empty
|
||||||
|| this.dataRange.back.status == BucketStatus.used);
|
|| this.dataRange.back.status == BucketStatus.used);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
@ -96,7 +96,7 @@ struct Range(E)
|
|||||||
assert(this.dataRange.empty
|
assert(this.dataRange.empty
|
||||||
|| this.dataRange.back.status == BucketStatus.used);
|
|| this.dataRange.back.status == BucketStatus.used);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
@ -111,7 +111,7 @@ struct Range(E)
|
|||||||
assert(!this.dataRange.empty);
|
assert(!this.dataRange.empty);
|
||||||
assert(this.dataRange.front.status == BucketStatus.used);
|
assert(this.dataRange.front.status == BucketStatus.used);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
return dataRange.front.content;
|
return dataRange.front.content;
|
||||||
}
|
}
|
||||||
@ -122,7 +122,7 @@ struct Range(E)
|
|||||||
assert(!this.dataRange.empty);
|
assert(!this.dataRange.empty);
|
||||||
assert(this.dataRange.back.status == BucketStatus.used);
|
assert(this.dataRange.back.status == BucketStatus.used);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
return dataRange.back.content;
|
return dataRange.back.content;
|
||||||
}
|
}
|
||||||
@ -180,7 +180,7 @@ struct Set(T)
|
|||||||
{
|
{
|
||||||
assert(allocator !is null);
|
assert(allocator !is null);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
this(allocator);
|
this(allocator);
|
||||||
rehash(n);
|
rehash(n);
|
||||||
@ -192,7 +192,7 @@ struct Set(T)
|
|||||||
{
|
{
|
||||||
assert(allocator !is null);
|
assert(allocator !is null);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
this.data = typeof(this.data)(allocator);
|
this.data = typeof(this.data)(allocator);
|
||||||
}
|
}
|
||||||
@ -227,7 +227,7 @@ struct Set(T)
|
|||||||
{
|
{
|
||||||
assert(allocator !is null);
|
assert(allocator !is null);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
this.data = typeof(this.data)(init.data, allocator);
|
this.data = typeof(this.data)(init.data, allocator);
|
||||||
}
|
}
|
||||||
@ -239,7 +239,7 @@ struct Set(T)
|
|||||||
{
|
{
|
||||||
assert(allocator !is null);
|
assert(allocator !is null);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
this.data = typeof(this.data)(move(init.data), allocator);
|
this.data = typeof(this.data)(move(init.data), allocator);
|
||||||
this.lengthIndex = init.lengthIndex;
|
this.lengthIndex = init.lengthIndex;
|
||||||
@ -285,7 +285,7 @@ struct Set(T)
|
|||||||
{
|
{
|
||||||
assert(allocator !is null);
|
assert(allocator !is null);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
return cast(shared Allocator) this.data.allocator;
|
return cast(shared Allocator) this.data.allocator;
|
||||||
}
|
}
|
||||||
@ -371,7 +371,7 @@ struct Set(T)
|
|||||||
{
|
{
|
||||||
assert(buckets.length > 0);
|
assert(buckets.length > 0);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
return hash % buckets.length;
|
return hash % buckets.length;
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,7 @@ if (is(Unqual!E == char))
|
|||||||
assert(begin >= container.data);
|
assert(begin >= container.data);
|
||||||
assert(end <= container.data + container.length);
|
assert(end <= container.data + container.length);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
this.container = &container;
|
this.container = &container;
|
||||||
this.begin = begin;
|
this.begin = begin;
|
||||||
@ -122,7 +122,7 @@ if (is(Unqual!E == char))
|
|||||||
{
|
{
|
||||||
assert(!empty);
|
assert(!empty);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
return *this.begin;
|
return *this.begin;
|
||||||
}
|
}
|
||||||
@ -132,7 +132,7 @@ if (is(Unqual!E == char))
|
|||||||
{
|
{
|
||||||
assert(!empty);
|
assert(!empty);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
return *(this.end - 1);
|
return *(this.end - 1);
|
||||||
}
|
}
|
||||||
@ -142,7 +142,7 @@ if (is(Unqual!E == char))
|
|||||||
{
|
{
|
||||||
assert(!empty);
|
assert(!empty);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
++this.begin;
|
++this.begin;
|
||||||
}
|
}
|
||||||
@ -152,7 +152,7 @@ if (is(Unqual!E == char))
|
|||||||
{
|
{
|
||||||
assert(!empty);
|
assert(!empty);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
--this.end;
|
--this.end;
|
||||||
}
|
}
|
||||||
@ -162,7 +162,7 @@ if (is(Unqual!E == char))
|
|||||||
{
|
{
|
||||||
assert(i < length);
|
assert(i < length);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
return *(this.begin + i);
|
return *(this.begin + i);
|
||||||
}
|
}
|
||||||
@ -183,7 +183,7 @@ if (is(Unqual!E == char))
|
|||||||
assert(i <= j);
|
assert(i <= j);
|
||||||
assert(j <= length);
|
assert(j <= length);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
return typeof(return)(*this.container, this.begin + i, this.begin + j);
|
return typeof(return)(*this.container, this.begin + i, this.begin + j);
|
||||||
}
|
}
|
||||||
@ -194,7 +194,7 @@ if (is(Unqual!E == char))
|
|||||||
assert(i <= j);
|
assert(i <= j);
|
||||||
assert(j <= length);
|
assert(j <= length);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
return typeof(return)(*this.container, this.begin + i, this.begin + j);
|
return typeof(return)(*this.container, this.begin + i, this.begin + j);
|
||||||
}
|
}
|
||||||
@ -233,7 +233,7 @@ if (is(Unqual!E == char))
|
|||||||
assert(begin >= container.data);
|
assert(begin >= container.data);
|
||||||
assert(end <= container.data + container.length);
|
assert(end <= container.data + container.length);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
this.container = &container;
|
this.container = &container;
|
||||||
this.begin = begin;
|
this.begin = begin;
|
||||||
@ -261,10 +261,11 @@ if (is(Unqual!E == char))
|
|||||||
{
|
{
|
||||||
assert(chr < 0xd800 || chr > 0xdfff);
|
assert(chr < 0xd800 || chr > 0xdfff);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
dchar chr;
|
dchar chr;
|
||||||
ubyte units, mask;
|
ubyte units;
|
||||||
|
int mask;
|
||||||
const(char)* it = this.begin;
|
const(char)* it = this.begin;
|
||||||
|
|
||||||
if (*it & 0x80)
|
if (*it & 0x80)
|
||||||
@ -294,7 +295,7 @@ if (is(Unqual!E == char))
|
|||||||
{
|
{
|
||||||
assert(!empty);
|
assert(!empty);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
ubyte units;
|
ubyte units;
|
||||||
if ((*begin & 0xf0) == 0xf0)
|
if ((*begin & 0xf0) == 0xf0)
|
||||||
@ -437,7 +438,7 @@ struct String
|
|||||||
{
|
{
|
||||||
assert(allocator !is null);
|
assert(allocator !is null);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
this.allocator_ = allocator;
|
this.allocator_ = allocator;
|
||||||
}
|
}
|
||||||
@ -527,7 +528,7 @@ struct String
|
|||||||
assert(capacity - length >= 4);
|
assert(capacity - length >= 4);
|
||||||
assert(src - 0x10000 < 0x100000);
|
assert(src - 0x10000 < 0x100000);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
auto dst = this.data + length;
|
auto dst = this.data + length;
|
||||||
|
|
||||||
@ -545,7 +546,7 @@ struct String
|
|||||||
{
|
{
|
||||||
assert(capacity - length >= 3);
|
assert(capacity - length >= 3);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
auto dst = this.data + length;
|
auto dst = this.data + length;
|
||||||
if (chr < 0x80)
|
if (chr < 0x80)
|
||||||
@ -923,7 +924,7 @@ struct String
|
|||||||
assert(j <= length);
|
assert(j <= length);
|
||||||
assert(j - i == value.length);
|
assert(j - i == value.length);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
auto target = opSlice(i, j);
|
auto target = opSlice(i, j);
|
||||||
copy(value, target);
|
copy(value, target);
|
||||||
@ -940,7 +941,7 @@ struct String
|
|||||||
assert(i <= j);
|
assert(i <= j);
|
||||||
assert(j <= length);
|
assert(j <= length);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
copy(value[], this.data[i .. j]);
|
copy(value[], this.data[i .. j]);
|
||||||
return opSlice(i, j);
|
return opSlice(i, j);
|
||||||
@ -956,7 +957,7 @@ struct String
|
|||||||
assert(i <= j);
|
assert(i <= j);
|
||||||
assert(j <= length);
|
assert(j <= length);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
for (auto p = this.data + i; p < this.data + j; ++p)
|
for (auto p = this.data + i; p < this.data + j; ++p)
|
||||||
{
|
{
|
||||||
@ -1037,7 +1038,7 @@ struct String
|
|||||||
{
|
{
|
||||||
assert(length > pos);
|
assert(length > pos);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
return *(this.data + pos);
|
return *(this.data + pos);
|
||||||
}
|
}
|
||||||
@ -1187,7 +1188,7 @@ struct String
|
|||||||
assert(i <= j);
|
assert(i <= j);
|
||||||
assert(j <= length);
|
assert(j <= length);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
return typeof(return)(this, this.data + i, this.data + j);
|
return typeof(return)(this, this.data + i, this.data + j);
|
||||||
}
|
}
|
||||||
@ -1200,7 +1201,7 @@ struct String
|
|||||||
assert(i <= j);
|
assert(i <= j);
|
||||||
assert(j <= length);
|
assert(j <= length);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
return typeof(return)(this, this.data + i, this.data + j);
|
return typeof(return)(this, this.data + i, this.data + j);
|
||||||
}
|
}
|
||||||
@ -1508,7 +1509,7 @@ struct String
|
|||||||
assert(r.begin >= this.data);
|
assert(r.begin >= this.data);
|
||||||
assert(r.end <= this.data + length);
|
assert(r.end <= this.data + length);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
auto end = this.data + this.length;
|
auto end = this.data + this.length;
|
||||||
copy(ByCodeUnit!char(this, r.end, end), ByCodeUnit!char(this, r.begin, end));
|
copy(ByCodeUnit!char(this, r.end, end), ByCodeUnit!char(this, r.begin, end));
|
||||||
@ -1561,7 +1562,7 @@ struct String
|
|||||||
assert(r.begin >= this.data);
|
assert(r.begin >= this.data);
|
||||||
assert(r.end <= this.data + length);
|
assert(r.end <= this.data + length);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
auto oldLen = this.data + length;
|
auto oldLen = this.data + length;
|
||||||
const inserted = insertBack(el);
|
const inserted = insertBack(el);
|
||||||
@ -1594,7 +1595,7 @@ struct String
|
|||||||
assert(r.begin >= this.data);
|
assert(r.begin >= this.data);
|
||||||
assert(r.end <= this.data + length);
|
assert(r.end <= this.data + length);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
return insertAfter(R(this, this.data, r.begin), el);
|
return insertAfter(R(this, this.data, r.begin), el);
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ out (result)
|
|||||||
{
|
{
|
||||||
assert(memory.ptr is (() @trusted => cast(void*) result)());
|
assert(memory.ptr is (() @trusted => cast(void*) result)());
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
copy(typeid(T).initializer, memory);
|
copy(typeid(T).initializer, memory);
|
||||||
|
|
||||||
@ -91,7 +91,8 @@ in
|
|||||||
out (result)
|
out (result)
|
||||||
{
|
{
|
||||||
assert(memory.ptr is (() @trusted => cast(void*) result)());
|
assert(memory.ptr is (() @trusted => cast(void*) result)());
|
||||||
}body
|
}
|
||||||
|
do
|
||||||
{
|
{
|
||||||
copy(typeid(T).initializer, memory);
|
copy(typeid(T).initializer, memory);
|
||||||
|
|
||||||
@ -144,7 +145,7 @@ out (result)
|
|||||||
{
|
{
|
||||||
assert(memory.ptr is result);
|
assert(memory.ptr is result);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
auto result = (() @trusted => cast(T*) memory.ptr)();
|
auto result = (() @trusted => cast(T*) memory.ptr)();
|
||||||
static if (Args.length == 1)
|
static if (Args.length == 1)
|
||||||
@ -169,7 +170,7 @@ out (result)
|
|||||||
{
|
{
|
||||||
assert(memory.ptr is result);
|
assert(memory.ptr is result);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
auto result = (() @trusted => cast(T*) memory.ptr)();
|
auto result = (() @trusted => cast(T*) memory.ptr)();
|
||||||
static if (!hasElaborateAssign!T && isAssignable!T)
|
static if (!hasElaborateAssign!T && isAssignable!T)
|
||||||
|
@ -16,7 +16,6 @@ module tanya.format;
|
|||||||
|
|
||||||
import tanya.container.string;
|
import tanya.container.string;
|
||||||
import tanya.encoding.ascii;
|
import tanya.encoding.ascii;
|
||||||
public import tanya.format.conv;
|
|
||||||
import tanya.math;
|
import tanya.math;
|
||||||
import tanya.memory.op;
|
import tanya.memory.op;
|
||||||
import tanya.meta.metafunction;
|
import tanya.meta.metafunction;
|
||||||
@ -323,9 +322,9 @@ private HP raise2Power10(const HP value, int power)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Given a float value, returns the significant bits in bits, and the position
|
* Given a float value, returns the significant bits, and the position of the
|
||||||
* of the decimal point in $(D_PARAM exponent). +/-Inf and NaN are specified
|
* decimal point in $(D_PARAM exponent). +/-Inf and NaN are specified by
|
||||||
* by special values returned in the $(D_PARAM exponent). Sing bit is set in
|
* special values returned in the $(D_PARAM exponent). Sing bit is set in
|
||||||
* $(D_PARAM sign).
|
* $(D_PARAM sign).
|
||||||
*/
|
*/
|
||||||
private const(char)[] real2String(double value,
|
private const(char)[] real2String(double value,
|
||||||
@ -505,35 +504,9 @@ if (T.sizeof == U.sizeof)
|
|||||||
copy((&src)[0 .. 1], (&dest)[0 .. 1]);
|
copy((&src)[0 .. 1], (&dest)[0 .. 1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
package(tanya) String format(string fmt, Args...)(auto ref Args args)
|
private void formatReal(T)(ref T arg, ref String result)
|
||||||
|
if (isFloatingPoint!T)
|
||||||
{
|
{
|
||||||
String result;
|
|
||||||
|
|
||||||
static if (is(Unqual!(Args[0]) == typeof(null)))
|
|
||||||
{
|
|
||||||
result.insertBack("null");
|
|
||||||
}
|
|
||||||
else static if(is(Unqual!(Args[0]) == bool))
|
|
||||||
{
|
|
||||||
result.insertBack(args[0] ? "true" : "false");
|
|
||||||
}
|
|
||||||
else static if (isSomeString!(Args[0])) // String
|
|
||||||
{
|
|
||||||
if (args[0] is null)
|
|
||||||
{
|
|
||||||
result.insertBack("null");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
result.insertBack(args[0]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else static if (isSomeChar!(Args[0])) // Char
|
|
||||||
{
|
|
||||||
result.insertBack(args[0]);
|
|
||||||
}
|
|
||||||
else static if (isFloatingPoint!(Args[0])) // Float
|
|
||||||
{
|
|
||||||
char[512] buffer; // Big enough for e+308 or e-307.
|
char[512] buffer; // Big enough for e+308 or e-307.
|
||||||
char[8] tail = 0;
|
char[8] tail = 0;
|
||||||
char[] bufferSlice = buffer[64 .. $];
|
char[] bufferSlice = buffer[64 .. $];
|
||||||
@ -542,7 +515,7 @@ package(tanya) String format(string fmt, Args...)(auto ref Args args)
|
|||||||
int decimalPoint;
|
int decimalPoint;
|
||||||
|
|
||||||
// Read the double into a string.
|
// Read the double into a string.
|
||||||
auto realString = real2String(args[0], buffer, decimalPoint, negative);
|
auto realString = real2String(arg, buffer, decimalPoint, negative);
|
||||||
auto length = cast(uint) realString.length;
|
auto length = cast(uint) realString.length;
|
||||||
|
|
||||||
// Clamp the precision and delete extra zeros after clamp.
|
// Clamp the precision and delete extra zeros after clamp.
|
||||||
@ -551,9 +524,7 @@ package(tanya) String format(string fmt, Args...)(auto ref Args args)
|
|||||||
{
|
{
|
||||||
length = precision;
|
length = precision;
|
||||||
}
|
}
|
||||||
while ((length > 1)
|
while ((length > 1) && (precision != 0) && (realString[length - 1] == '0'))
|
||||||
&& (precision != 0)
|
|
||||||
&& (realString[length - 1] == '0'))
|
|
||||||
{
|
{
|
||||||
--precision;
|
--precision;
|
||||||
--length;
|
--length;
|
||||||
@ -566,7 +537,7 @@ package(tanya) String format(string fmt, Args...)(auto ref Args args)
|
|||||||
if (decimalPoint == special)
|
if (decimalPoint == special)
|
||||||
{
|
{
|
||||||
result.insertBack(realString);
|
result.insertBack(realString);
|
||||||
goto ParamEnd;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Should we use sceintific notation?
|
// Should we use sceintific notation?
|
||||||
@ -727,8 +698,132 @@ package(tanya) String format(string fmt, Args...)(auto ref Args args)
|
|||||||
|
|
||||||
result.insertBack(buffer[64 .. length]); // Number.
|
result.insertBack(buffer[64 .. length]); // Number.
|
||||||
result.insertBack(tail[1 .. tail[0] + 1]); // Tail.
|
result.insertBack(tail[1 .. tail[0] + 1]); // Tail.
|
||||||
|
}
|
||||||
|
|
||||||
|
private void formatStruct(T)(ref T arg, ref String result)
|
||||||
|
if (is(T == struct))
|
||||||
|
{
|
||||||
|
template pred(alias f)
|
||||||
|
{
|
||||||
|
static if (f == "this")
|
||||||
|
{
|
||||||
|
// Exclude context pointer from nested structs.
|
||||||
|
enum bool pred = false;
|
||||||
}
|
}
|
||||||
else static if (isPointer!(Args[0])) // Pointer
|
else
|
||||||
|
{
|
||||||
|
enum bool pred = !isSomeFunction!(__traits(getMember, arg, f));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
alias fields = Filter!(pred, __traits(allMembers, T));
|
||||||
|
|
||||||
|
result.insertBack(T.stringof);
|
||||||
|
result.insertBack('(');
|
||||||
|
static if (fields.length > 0)
|
||||||
|
{
|
||||||
|
printToString!"{}"(result, __traits(getMember, arg, fields[0]));
|
||||||
|
foreach (field; fields[1 .. $])
|
||||||
|
{
|
||||||
|
result.insertBack(", ");
|
||||||
|
printToString!"{}"(result, __traits(getMember, arg, field));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result.insertBack(')');
|
||||||
|
}
|
||||||
|
|
||||||
|
private void formatRange(T)(ref T arg, ref String result)
|
||||||
|
if (isInputRange!T && !isInfinite!T)
|
||||||
|
{
|
||||||
|
result.insertBack('[');
|
||||||
|
if (!arg.empty)
|
||||||
|
{
|
||||||
|
printToString!"{}"(result, arg.front);
|
||||||
|
arg.popFront();
|
||||||
|
}
|
||||||
|
foreach (e; arg)
|
||||||
|
{
|
||||||
|
result.insertBack(", ");
|
||||||
|
printToString!"{}"(result, e);
|
||||||
|
}
|
||||||
|
result.insertBack(']');
|
||||||
|
}
|
||||||
|
|
||||||
|
private ref String printToString(string fmt, Args...)(return ref String result,
|
||||||
|
auto ref Args args)
|
||||||
|
{
|
||||||
|
alias Arg = Args[0];
|
||||||
|
|
||||||
|
static if (is(Unqual!Arg == typeof(null))) // null
|
||||||
|
{
|
||||||
|
result.insertBack("null");
|
||||||
|
}
|
||||||
|
else static if (is(Unqual!Arg == bool)) // Boolean
|
||||||
|
{
|
||||||
|
result.insertBack(args[0] ? "true" : "false");
|
||||||
|
}
|
||||||
|
else static if (is(Arg == enum)) // Enum
|
||||||
|
{
|
||||||
|
foreach (m; __traits(allMembers, Arg))
|
||||||
|
{
|
||||||
|
if (args[0] == __traits(getMember, Arg, m))
|
||||||
|
{
|
||||||
|
result.insertBack(m);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else static if (isSomeChar!Arg || isSomeString!Arg) // String or char
|
||||||
|
{
|
||||||
|
result.insertBack(args[0]);
|
||||||
|
}
|
||||||
|
else static if (isInputRange!Arg
|
||||||
|
&& !isInfinite!Arg
|
||||||
|
&& isSomeChar!(ElementType!Arg)) // Stringish range
|
||||||
|
{
|
||||||
|
result.insertBack(args[0]);
|
||||||
|
}
|
||||||
|
else static if (isInputRange!Arg && !isInfinite!Arg)
|
||||||
|
{
|
||||||
|
formatRange(args[0], result);
|
||||||
|
}
|
||||||
|
else static if (is(Unqual!(typeof(args[0].stringify())) == String))
|
||||||
|
{
|
||||||
|
static if (is(Arg == class) || is(Arg == interface))
|
||||||
|
{
|
||||||
|
if (args[0] is null)
|
||||||
|
{
|
||||||
|
result.insertBack("null");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result.insertBack(args[0].stringify()[]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result.insertBack(args[0].stringify()[]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else static if (is(Arg == class))
|
||||||
|
{
|
||||||
|
result.insertBack(args[0] is null ? "null" : args[0].toString());
|
||||||
|
}
|
||||||
|
else static if (is(Arg == interface))
|
||||||
|
{
|
||||||
|
result.insertBack(Arg.classinfo.name);
|
||||||
|
}
|
||||||
|
else static if (is(Arg == struct))
|
||||||
|
{
|
||||||
|
formatStruct(args[0], result);
|
||||||
|
}
|
||||||
|
else static if (is(Arg == union))
|
||||||
|
{
|
||||||
|
result.insertBack(Arg.stringof);
|
||||||
|
}
|
||||||
|
else static if (isFloatingPoint!Arg) // Float
|
||||||
|
{
|
||||||
|
formatReal(args[0], result);
|
||||||
|
}
|
||||||
|
else static if (isPointer!Arg) // Pointer
|
||||||
{
|
{
|
||||||
char[size_t.sizeof * 2] buffer;
|
char[size_t.sizeof * 2] buffer;
|
||||||
size_t position = buffer.length;
|
size_t position = buffer.length;
|
||||||
@ -744,20 +839,40 @@ package(tanya) String format(string fmt, Args...)(auto ref Args args)
|
|||||||
result.insertBack("0x");
|
result.insertBack("0x");
|
||||||
result.insertBack(buffer[position .. $]);
|
result.insertBack(buffer[position .. $]);
|
||||||
}
|
}
|
||||||
else static if (isIntegral!(Args[0])) // Integer
|
else static if (isIntegral!Arg) // Integer
|
||||||
{
|
{
|
||||||
char[21] buffer;
|
char[21] buffer;
|
||||||
result.insertBack(integral2String(args[0], buffer));
|
result.insertBack(integral2String(args[0], buffer));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
static assert(false);
|
static assert(false,
|
||||||
|
"Formatting type " ~ Arg.stringof ~ " is not supported");
|
||||||
}
|
}
|
||||||
ParamEnd:
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
package(tanya) String format(string fmt, Args...)(auto ref Args args)
|
||||||
|
{
|
||||||
|
String formatted;
|
||||||
|
return printToString!fmt(formatted, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enum.
|
||||||
|
@nogc nothrow pure @safe unittest
|
||||||
|
{
|
||||||
|
enum E1 : int
|
||||||
|
{
|
||||||
|
one,
|
||||||
|
two,
|
||||||
|
}
|
||||||
|
assert(format!"{}"(E1.one) == "one");
|
||||||
|
|
||||||
|
const E1 e1;
|
||||||
|
assert(format!"{}"(e1) == "one");
|
||||||
|
}
|
||||||
|
|
||||||
// One argument tests.
|
// One argument tests.
|
||||||
@nogc pure @safe unittest
|
@nogc pure @safe unittest
|
||||||
{
|
{
|
||||||
@ -772,7 +887,7 @@ ParamEnd:
|
|||||||
|
|
||||||
// String printing.
|
// String printing.
|
||||||
assert(format!"{}"("Some weired string") == "Some weired string");
|
assert(format!"{}"("Some weired string") == "Some weired string");
|
||||||
assert(format!"{}"(cast(string) null) == "null");
|
assert(format!"{}"(cast(string) null) == "");
|
||||||
assert(format!"{}"('c') == "c");
|
assert(format!"{}"('c') == "c");
|
||||||
|
|
||||||
// Integer.
|
// Integer.
|
||||||
@ -826,6 +941,145 @@ ParamEnd:
|
|||||||
assert(format!"{}"(cast(void*) null) == "0x0");
|
assert(format!"{}"(cast(void*) null) == "0x0");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Structs.
|
||||||
|
@nogc pure @safe unittest
|
||||||
|
{
|
||||||
|
static struct WithoutStringify1
|
||||||
|
{
|
||||||
|
int a;
|
||||||
|
void func()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert(format!"{}"(WithoutStringify1(6)) == "WithoutStringify1(6)");
|
||||||
|
|
||||||
|
static struct WithoutStringify2
|
||||||
|
{
|
||||||
|
}
|
||||||
|
assert(format!"{}"(WithoutStringify2()) == "WithoutStringify2()");
|
||||||
|
|
||||||
|
static struct WithoutStringify3
|
||||||
|
{
|
||||||
|
int a = -2;
|
||||||
|
int b = 8;
|
||||||
|
}
|
||||||
|
assert(format!"{}"(WithoutStringify3()) == "WithoutStringify3(-2, 8)");
|
||||||
|
|
||||||
|
struct Nested
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
void func()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert(format!"{}"(Nested()) == "Nested(0)");
|
||||||
|
|
||||||
|
static struct WithStringify
|
||||||
|
{
|
||||||
|
String stringify() const @nogc nothrow pure @safe
|
||||||
|
{
|
||||||
|
return String("stringify method");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert(format!"{}"(WithStringify()) == "stringify method");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate types.
|
||||||
|
@system unittest // Object.toString has no attributes.
|
||||||
|
{
|
||||||
|
import tanya.memory;
|
||||||
|
import tanya.memory.smartref;
|
||||||
|
|
||||||
|
interface I
|
||||||
|
{
|
||||||
|
}
|
||||||
|
class A : I
|
||||||
|
{
|
||||||
|
}
|
||||||
|
auto instance = defaultAllocator.unique!A();
|
||||||
|
assert(format!"{}"(instance.get()) == instance.get().toString());
|
||||||
|
assert(format!"{}"(cast(I) instance.get()) == I.classinfo.name);
|
||||||
|
assert(format!"{}"(cast(A) null) == "null");
|
||||||
|
|
||||||
|
class B
|
||||||
|
{
|
||||||
|
String stringify() @nogc nothrow pure @safe
|
||||||
|
{
|
||||||
|
return String("Class B");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert(format!"{}"(cast(B) null) == "null");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unions.
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
union U
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
char c;
|
||||||
|
}
|
||||||
|
assert(format!"{}"(U(2)) == "U");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ranges.
|
||||||
|
@nogc pure @safe unittest
|
||||||
|
{
|
||||||
|
static struct Stringish
|
||||||
|
{
|
||||||
|
private string content = "Some content";
|
||||||
|
|
||||||
|
immutable(char) front() const @nogc nothrow pure @safe
|
||||||
|
{
|
||||||
|
return this.content[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
void popFront() @nogc nothrow pure @safe
|
||||||
|
{
|
||||||
|
this.content = this.content[1 .. $];
|
||||||
|
}
|
||||||
|
|
||||||
|
bool empty() const @nogc nothrow pure @safe
|
||||||
|
{
|
||||||
|
return this.content.length == 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert(format!"{}"(Stringish()) == "Some content");
|
||||||
|
|
||||||
|
static struct Intish
|
||||||
|
{
|
||||||
|
private int front_ = 3;
|
||||||
|
|
||||||
|
int front() const @nogc nothrow pure @safe
|
||||||
|
{
|
||||||
|
return this.front_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void popFront() @nogc nothrow pure @safe
|
||||||
|
{
|
||||||
|
--this.front_;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool empty() const @nogc nothrow pure @safe
|
||||||
|
{
|
||||||
|
return this.front == 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert(format!"{}"(Intish()) == "[3, 2, 1]");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Typeid.
|
||||||
|
nothrow pure @safe unittest
|
||||||
|
{
|
||||||
|
assert(format!"{}"(typeid(int[])) == "int[]");
|
||||||
|
|
||||||
|
class C
|
||||||
|
{
|
||||||
|
}
|
||||||
|
assert(format!"{}"(typeid(C)) == typeid(C).toString());
|
||||||
|
}
|
||||||
|
|
||||||
private struct FormatSpec
|
private struct FormatSpec
|
||||||
{
|
{
|
||||||
}
|
}
|
@ -1,293 +0,0 @@
|
|||||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This module provides functions for converting between different types.
|
|
||||||
*
|
|
||||||
* Copyright: Eugene Wissner 2017.
|
|
||||||
* License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/,
|
|
||||||
* Mozilla Public License, v. 2.0).
|
|
||||||
* Authors: Jeff Roberts, $(LINK2 mailto:info@caraus.de, Eugene Wissner)
|
|
||||||
* Source: $(LINK2 https://github.com/caraus-ecms/tanya/blob/master/source/tanya/format/conv.d,
|
|
||||||
* tanya/format/conv.d)
|
|
||||||
*/
|
|
||||||
module tanya.format.conv;
|
|
||||||
|
|
||||||
import tanya.container.string;
|
|
||||||
import tanya.memory;
|
|
||||||
import tanya.memory.op;
|
|
||||||
import tanya.meta.trait;
|
|
||||||
import tanya.meta.transform;
|
|
||||||
|
|
||||||
version (unittest)
|
|
||||||
{
|
|
||||||
import tanya.test.assertion;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Thrown if a type conversion fails.
|
|
||||||
*/
|
|
||||||
final class ConvException : Exception
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Params:
|
|
||||||
* msg = The message for the exception.
|
|
||||||
* file = The file where the exception occurred.
|
|
||||||
* line = The line number where the exception occurred.
|
|
||||||
* next = The previous exception in the chain of exceptions, if any.
|
|
||||||
*/
|
|
||||||
this(string msg,
|
|
||||||
string file = __FILE__,
|
|
||||||
size_t line = __LINE__,
|
|
||||||
Throwable next = null) @nogc @safe pure nothrow
|
|
||||||
{
|
|
||||||
super(msg, file, line, next);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If the source type $(D_PARAM From) and the target type $(D_PARAM To) are
|
|
||||||
* equal, does nothing. If $(D_PARAM From) can be implicitly converted to
|
|
||||||
* $(D_PARAM To), just returns $(D_PARAM from).
|
|
||||||
*
|
|
||||||
* Params:
|
|
||||||
* To = Target type.
|
|
||||||
*
|
|
||||||
* Returns: $(D_PARAM from).
|
|
||||||
*/
|
|
||||||
deprecated("Use tanya.conv.to instead")
|
|
||||||
template to(To)
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Params:
|
|
||||||
* From = Source type.
|
|
||||||
* from = Source value.
|
|
||||||
*/
|
|
||||||
ref To to(From)(ref From from)
|
|
||||||
if (is(To == From))
|
|
||||||
{
|
|
||||||
return from;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// ditto
|
|
||||||
To to(From)(From from)
|
|
||||||
if (is(Unqual!To == Unqual!From) || (isNumeric!From && isFloatingPoint!To))
|
|
||||||
{
|
|
||||||
return from;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Performs checked conversion from an integral type $(D_PARAM From) to an
|
|
||||||
* integral type $(D_PARAM To).
|
|
||||||
*
|
|
||||||
* Params:
|
|
||||||
* From = Source type.
|
|
||||||
* To = Target type.
|
|
||||||
* from = Source value.
|
|
||||||
*
|
|
||||||
* Returns: $(D_PARAM from) converted to $(D_PARAM To).
|
|
||||||
*
|
|
||||||
* Throws: $(D_PSYMBOL ConvException) if $(D_PARAM from) is too small or too
|
|
||||||
* large to be represented by $(D_PARAM To).
|
|
||||||
*/
|
|
||||||
deprecated("Use tanya.conv.to instead")
|
|
||||||
To to(To, From)(From from)
|
|
||||||
if (isIntegral!From
|
|
||||||
&& isIntegral!To
|
|
||||||
&& !is(Unqual!To == Unqual!From)
|
|
||||||
&& !is(To == enum))
|
|
||||||
{
|
|
||||||
static if ((isUnsigned!From && isSigned!To && From.sizeof == To.sizeof)
|
|
||||||
|| From.sizeof > To.sizeof)
|
|
||||||
{
|
|
||||||
if (from > To.max)
|
|
||||||
{
|
|
||||||
throw make!ConvException(defaultAllocator,
|
|
||||||
"Positive integer overflow");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
static if (isSigned!From)
|
|
||||||
{
|
|
||||||
static if (isUnsigned!To)
|
|
||||||
{
|
|
||||||
if (from < 0)
|
|
||||||
{
|
|
||||||
throw make!ConvException(defaultAllocator,
|
|
||||||
"Negative integer overflow");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else static if (From.sizeof > To.sizeof)
|
|
||||||
{
|
|
||||||
if (from < To.min)
|
|
||||||
{
|
|
||||||
throw make!ConvException(defaultAllocator,
|
|
||||||
"Negative integer overflow");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
static if (From.sizeof <= To.sizeof)
|
|
||||||
{
|
|
||||||
return from;
|
|
||||||
}
|
|
||||||
else static if (isSigned!To)
|
|
||||||
{
|
|
||||||
return cast(To) from;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return from & To.max;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts $(D_PARAM from) to a boolean.
|
|
||||||
*
|
|
||||||
* If $(D_PARAM From) is a numeric type, then `1` becomes $(D_KEYWORD true),
|
|
||||||
* `0` $(D_KEYWORD false). Otherwise $(D_PSYMBOL ConvException) is thrown.
|
|
||||||
*
|
|
||||||
* If $(D_PARAM To) is a string (built-in string or $(D_PSYMBOL String)),
|
|
||||||
* then `"true"` or `"false"` are converted to the appropriate boolean value.
|
|
||||||
* Otherwise $(D_PSYMBOL ConvException) is thrown.
|
|
||||||
*
|
|
||||||
* Params:
|
|
||||||
* From = Source type.
|
|
||||||
* To = Target type.
|
|
||||||
* from = Source value.
|
|
||||||
*
|
|
||||||
* Returns: $(D_KEYWORD from) converted to a boolean.
|
|
||||||
*
|
|
||||||
* Throws: $(D_PSYMBOL ConvException) if $(D_PARAM from) isn't convertible.
|
|
||||||
*/
|
|
||||||
deprecated("Use tanya.conv.to instead")
|
|
||||||
To to(To, From)(From from)
|
|
||||||
if (isNumeric!From && is(Unqual!To == bool) && !is(Unqual!To == Unqual!From))
|
|
||||||
{
|
|
||||||
if (from == 0)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else if (from < 0)
|
|
||||||
{
|
|
||||||
throw make!ConvException(defaultAllocator,
|
|
||||||
"Negative number overflow");
|
|
||||||
}
|
|
||||||
else if (from <= 1)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
throw make!ConvException(defaultAllocator,
|
|
||||||
"Positive number overflow");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// ditto
|
|
||||||
deprecated("Use tanya.conv.to instead")
|
|
||||||
To to(To, From)(auto ref const From from)
|
|
||||||
if ((is(From == String) || isSomeString!From) && is(Unqual!To == bool))
|
|
||||||
{
|
|
||||||
if (from == "true")
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if (from == "false")
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
throw make!ConvException(defaultAllocator,
|
|
||||||
"String doesn't contain a boolean value");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts a boolean to $(D_PARAM To).
|
|
||||||
*
|
|
||||||
* If $(D_PARAM To) is a numeric type, then $(D_KEYWORD true) becomes `1`,
|
|
||||||
* $(D_KEYWORD false) `0`.
|
|
||||||
*
|
|
||||||
* If $(D_PARAM To) is a $(D_PSYMBOL String), then `"true"` or `"false"`
|
|
||||||
* is returned.
|
|
||||||
*
|
|
||||||
* Params:
|
|
||||||
* From = Source type.
|
|
||||||
* To = Target type.
|
|
||||||
* from = Source value.
|
|
||||||
*
|
|
||||||
* Returns: $(D_PARAM from) converted to $(D_PARAM To).
|
|
||||||
*/
|
|
||||||
deprecated("Use tanya.conv.to instead")
|
|
||||||
To to(To, From)(const From from)
|
|
||||||
if (is(Unqual!From == bool) && isNumeric!To && !is(Unqual!To == Unqual!From))
|
|
||||||
{
|
|
||||||
return from;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// ditto
|
|
||||||
deprecated("Use tanya.conv.to instead")
|
|
||||||
To to(To, From)(const From from)
|
|
||||||
if (is(Unqual!From == bool) && is(Unqual!To == String))
|
|
||||||
{
|
|
||||||
return String(from ? "true" : "false");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts a floating point number to an integral type.
|
|
||||||
*
|
|
||||||
* Params:
|
|
||||||
* From = Source type.
|
|
||||||
* To = Target type.
|
|
||||||
* from = Source value.
|
|
||||||
*
|
|
||||||
* Returns: Truncated $(D_PARAM from) (everything after the decimal point is
|
|
||||||
* dropped).
|
|
||||||
*
|
|
||||||
* Throws: $(D_PSYMBOL ConvException) if
|
|
||||||
* $(D_INLINECODE from < To.min || from > To.max).
|
|
||||||
*/
|
|
||||||
deprecated("Use tanya.conv.to instead")
|
|
||||||
To to(To, From)(From from)
|
|
||||||
if (isFloatingPoint!From
|
|
||||||
&& isIntegral!To
|
|
||||||
&& !is(Unqual!To == Unqual!From)
|
|
||||||
&& !is(To == enum))
|
|
||||||
{
|
|
||||||
if (from > To.max)
|
|
||||||
{
|
|
||||||
throw make!ConvException(defaultAllocator,
|
|
||||||
"Positive number overflow");
|
|
||||||
}
|
|
||||||
else if (from < To.min)
|
|
||||||
{
|
|
||||||
throw make!ConvException(defaultAllocator,
|
|
||||||
"Negative number overflow");
|
|
||||||
}
|
|
||||||
return cast(To) from;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Performs checked conversion from an integral type $(D_PARAM From) to an
|
|
||||||
* $(D_KEYWORD enum).
|
|
||||||
*
|
|
||||||
* Params:
|
|
||||||
* From = Source type.
|
|
||||||
* To = Target type.
|
|
||||||
* from = Source value.
|
|
||||||
*
|
|
||||||
* Returns: $(D_KEYWORD enum) value.
|
|
||||||
*
|
|
||||||
* Throws: $(D_PSYMBOL ConvException) if $(D_PARAM from) is not a member of
|
|
||||||
* $(D_PSYMBOL To).
|
|
||||||
*/
|
|
||||||
deprecated("Use tanya.conv.to instead")
|
|
||||||
To to(To, From)(From from)
|
|
||||||
if (isIntegral!From && is(To == enum))
|
|
||||||
{
|
|
||||||
foreach (m; EnumMembers!To)
|
|
||||||
{
|
|
||||||
if (from == m)
|
|
||||||
{
|
|
||||||
return m;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw make!ConvException(defaultAllocator,
|
|
||||||
"Value not found in enum '" ~ To.stringof ~ "'");
|
|
||||||
}
|
|
@ -112,7 +112,7 @@ struct Integer
|
|||||||
{
|
{
|
||||||
assert(allocator !is null);
|
assert(allocator !is null);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
this.allocator_ = allocator;
|
this.allocator_ = allocator;
|
||||||
}
|
}
|
||||||
@ -393,7 +393,9 @@ struct Integer
|
|||||||
T opCast(T)() const
|
T opCast(T)() const
|
||||||
if (isIntegral!T && isSigned!T)
|
if (isIntegral!T && isSigned!T)
|
||||||
{
|
{
|
||||||
return this.sign ? -(cast(Unsigned!T) this) : cast(Unsigned!T) this;
|
return this.sign
|
||||||
|
? cast(T) -(cast(Promoted!(Unsigned!T)) (cast(Unsigned!T) this))
|
||||||
|
: cast(Unsigned!T) this;
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
@ -871,7 +873,7 @@ struct Integer
|
|||||||
{
|
{
|
||||||
assert(operand.length > 0, "Division by zero.");
|
assert(operand.length > 0, "Division by zero.");
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
divide(operand, this);
|
divide(operand, this);
|
||||||
return this;
|
return this;
|
||||||
@ -883,7 +885,7 @@ struct Integer
|
|||||||
{
|
{
|
||||||
assert(operand.length > 0, "Division by zero.");
|
assert(operand.length > 0, "Division by zero.");
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
divide(operand, null, this);
|
divide(operand, null, this);
|
||||||
return this;
|
return this;
|
||||||
@ -1072,7 +1074,7 @@ struct Integer
|
|||||||
assert(h1 == 79);
|
assert(h1 == 79);
|
||||||
|
|
||||||
h2 = ~h1;
|
h2 = ~h1;
|
||||||
assert(h2 == ~cast(ubyte) 79);
|
assert(h2 == cast(ubyte) ~79);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ditto
|
/// ditto
|
||||||
@ -1166,7 +1168,7 @@ struct Integer
|
|||||||
{
|
{
|
||||||
assert(operand.length > 0, "Division by zero.");
|
assert(operand.length > 0, "Division by zero.");
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
mixin("return Integer(this, allocator) " ~ op ~ "= operand;");
|
mixin("return Integer(this, allocator) " ~ op ~ "= operand;");
|
||||||
}
|
}
|
||||||
@ -1285,7 +1287,7 @@ struct Integer
|
|||||||
{
|
{
|
||||||
assert(divisor != 0, "Division by zero.");
|
assert(divisor != 0, "Division by zero.");
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
if (compare(divisor) < 0)
|
if (compare(divisor) < 0)
|
||||||
{
|
{
|
||||||
@ -1470,7 +1472,7 @@ struct Integer
|
|||||||
{
|
{
|
||||||
assert(array.length == length);
|
assert(array.length == length);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
Array!ubyte array;
|
Array!ubyte array;
|
||||||
|
|
||||||
|
@ -586,7 +586,7 @@ in
|
|||||||
{
|
{
|
||||||
assert(z > 0, "Division by zero.");
|
assert(z > 0, "Division by zero.");
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
G mask = G.max / 2 + 1;
|
G mask = G.max / 2 + 1;
|
||||||
H result;
|
H result;
|
||||||
@ -627,7 +627,7 @@ in
|
|||||||
{
|
{
|
||||||
assert(z.length > 0, "Division by zero.");
|
assert(z.length > 0, "Division by zero.");
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
auto tmp1 = Integer(x, x.allocator);
|
auto tmp1 = Integer(x, x.allocator);
|
||||||
|
@ -134,7 +134,7 @@ version (linux)
|
|||||||
{
|
{
|
||||||
assert(length <= maxGather);
|
assert(length <= maxGather);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
// int getrandom(void *buf, size_t buflen, unsigned int flags);
|
// int getrandom(void *buf, size_t buflen, unsigned int flags);
|
||||||
auto length = syscall(318, output.ptr, output.length, 0);
|
auto length = syscall(318, output.ptr, output.length, 0);
|
||||||
@ -198,7 +198,7 @@ class Entropy
|
|||||||
assert(maxSources > 0 && maxSources <= ubyte.max);
|
assert(maxSources > 0 && maxSources <= ubyte.max);
|
||||||
assert(allocator !is null);
|
assert(allocator !is null);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
allocator.resize(sources, maxSources);
|
allocator.resize(sources, maxSources);
|
||||||
|
|
||||||
@ -234,7 +234,7 @@ class Entropy
|
|||||||
{
|
{
|
||||||
assert(sourceCount_ <= sources.length);
|
assert(sourceCount_ <= sources.length);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
sources[sourceCount_++] = source;
|
sources[sourceCount_++] = source;
|
||||||
return this;
|
return this;
|
||||||
@ -251,7 +251,7 @@ class Entropy
|
|||||||
{
|
{
|
||||||
assert(sourceCount_ > 0, "No entropy sources defined.");
|
assert(sourceCount_ > 0, "No entropy sources defined.");
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
bool haveStrong;
|
bool haveStrong;
|
||||||
ushort done;
|
ushort done;
|
||||||
|
@ -32,6 +32,16 @@ else
|
|||||||
import core.stdc.string;
|
import core.stdc.string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
version (TanyaNative)
|
||||||
|
{
|
||||||
|
@nogc nothrow pure @system unittest
|
||||||
|
{
|
||||||
|
ubyte[2] buffer = 1;
|
||||||
|
fillMemory(buffer[1 .. $], 0);
|
||||||
|
assert(buffer[0] == 1 && buffer[1] == 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private enum alignMask = size_t.sizeof - 1;
|
private enum alignMask = size_t.sizeof - 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -58,7 +68,7 @@ in
|
|||||||
assert(source.length == 0 || source.ptr !is null);
|
assert(source.length == 0 || source.ptr !is null);
|
||||||
assert(target.length == 0 || target.ptr !is null);
|
assert(target.length == 0 || target.ptr !is null);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
version (TanyaNative)
|
version (TanyaNative)
|
||||||
{
|
{
|
||||||
@ -126,7 +136,7 @@ in
|
|||||||
{
|
{
|
||||||
assert(memory.length == 0 || memory.ptr !is null);
|
assert(memory.length == 0 || memory.ptr !is null);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
version (TanyaNative)
|
version (TanyaNative)
|
||||||
{
|
{
|
||||||
@ -149,31 +159,6 @@ body
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stress test. Checks that `fill` can handle unaligned pointers and different
|
|
||||||
// lengths.
|
|
||||||
@nogc nothrow pure @safe unittest
|
|
||||||
{
|
|
||||||
ubyte[192] memory;
|
|
||||||
|
|
||||||
foreach (j; 0 .. 192)
|
|
||||||
{
|
|
||||||
foreach (ubyte i, ref ubyte v; memory[j .. $])
|
|
||||||
{
|
|
||||||
v = i;
|
|
||||||
}
|
|
||||||
fill(memory[j .. $]);
|
|
||||||
foreach (ubyte v; memory[j .. $])
|
|
||||||
{
|
|
||||||
assert(v == 0);
|
|
||||||
}
|
|
||||||
fill!1(memory[j .. $]);
|
|
||||||
foreach (ubyte v; memory[j .. $])
|
|
||||||
{
|
|
||||||
assert(v == 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copies starting from the end of $(D_PARAM source) into the end of
|
* Copies starting from the end of $(D_PARAM source) into the end of
|
||||||
* $(D_PARAM target).
|
* $(D_PARAM target).
|
||||||
@ -203,7 +188,7 @@ in
|
|||||||
assert(source.length == 0 || source.ptr !is null);
|
assert(source.length == 0 || source.ptr !is null);
|
||||||
assert(target.length == 0 || target.ptr !is null);
|
assert(target.length == 0 || target.ptr !is null);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
version (TanyaNative)
|
version (TanyaNative)
|
||||||
{
|
{
|
||||||
@ -257,7 +242,7 @@ in
|
|||||||
assert(r1.length == 0 || r1.ptr !is null);
|
assert(r1.length == 0 || r1.ptr !is null);
|
||||||
assert(r2.length == 0 || r2.ptr !is null);
|
assert(r2.length == 0 || r2.ptr !is null);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
version (TanyaNative)
|
version (TanyaNative)
|
||||||
{
|
{
|
||||||
@ -321,7 +306,7 @@ in
|
|||||||
{
|
{
|
||||||
assert(haystack.length == 0 || haystack.ptr !is null);
|
assert(haystack.length == 0 || haystack.ptr !is null);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
auto length = haystack.length;
|
auto length = haystack.length;
|
||||||
const size_t needleWord = size_t.max * needle;
|
const size_t needleWord = size_t.max * needle;
|
||||||
|
@ -45,7 +45,7 @@ mixin template DefaultAllocator()
|
|||||||
{
|
{
|
||||||
assert(allocator !is null);
|
assert(allocator !is null);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
this.allocator_ = allocator;
|
this.allocator_ = allocator;
|
||||||
}
|
}
|
||||||
@ -63,7 +63,7 @@ mixin template DefaultAllocator()
|
|||||||
{
|
{
|
||||||
assert(allocator !is null);
|
assert(allocator !is null);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
if (allocator_ is null)
|
if (allocator_ is null)
|
||||||
{
|
{
|
||||||
@ -78,7 +78,7 @@ mixin template DefaultAllocator()
|
|||||||
{
|
{
|
||||||
assert(allocator !is null);
|
assert(allocator !is null);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
if (allocator_ is null)
|
if (allocator_ is null)
|
||||||
{
|
{
|
||||||
@ -114,7 +114,7 @@ out (allocator)
|
|||||||
{
|
{
|
||||||
assert(allocator !is null);
|
assert(allocator !is null);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
return (cast(GetPureInstance!Allocator) &getAllocatorInstance)();
|
return (cast(GetPureInstance!Allocator) &getAllocatorInstance)();
|
||||||
}
|
}
|
||||||
@ -132,7 +132,7 @@ in
|
|||||||
{
|
{
|
||||||
assert(allocator !is null);
|
assert(allocator !is null);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
.allocator = allocator;
|
.allocator = allocator;
|
||||||
}
|
}
|
||||||
@ -403,7 +403,7 @@ in
|
|||||||
{
|
{
|
||||||
assert(allocator !is null);
|
assert(allocator !is null);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
auto mem = (() @trusted => allocator.allocate(stateSize!T))();
|
auto mem = (() @trusted => allocator.allocate(stateSize!T))();
|
||||||
if (mem is null)
|
if (mem is null)
|
||||||
@ -442,7 +442,7 @@ in
|
|||||||
{
|
{
|
||||||
assert(allocator !is null);
|
assert(allocator !is null);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
auto mem = (() @trusted => allocator.allocate(stateSize!T))();
|
auto mem = (() @trusted => allocator.allocate(stateSize!T))();
|
||||||
if (mem is null)
|
if (mem is null)
|
||||||
@ -484,7 +484,7 @@ in
|
|||||||
assert(allocator !is null);
|
assert(allocator !is null);
|
||||||
assert(n <= size_t.max / ElementType!T.sizeof);
|
assert(n <= size_t.max / ElementType!T.sizeof);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
auto ret = allocator.resize!(ElementType!T)(null, n);
|
auto ret = allocator.resize!(ElementType!T)(null, n);
|
||||||
ret.uninitializedFill(ElementType!T.init);
|
ret.uninitializedFill(ElementType!T.init);
|
||||||
|
@ -54,7 +54,7 @@ private final class RefCountedStore(T)
|
|||||||
{
|
{
|
||||||
assert(this.counter > 0);
|
assert(this.counter > 0);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
mixin("return " ~ op ~ "counter;");
|
mixin("return " ~ op ~ "counter;");
|
||||||
}
|
}
|
||||||
@ -139,7 +139,7 @@ struct RefCounted(T)
|
|||||||
{
|
{
|
||||||
assert(allocator !is null);
|
assert(allocator !is null);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
this.allocator_ = allocator;
|
this.allocator_ = allocator;
|
||||||
}
|
}
|
||||||
@ -247,7 +247,7 @@ struct RefCounted(T)
|
|||||||
{
|
{
|
||||||
assert(count > 0, "Attempted to access an uninitialized reference");
|
assert(count > 0, "Attempted to access an uninitialized reference");
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
return this.storage.payload;
|
return this.storage.payload;
|
||||||
}
|
}
|
||||||
@ -501,7 +501,7 @@ in
|
|||||||
{
|
{
|
||||||
assert(allocator !is null);
|
assert(allocator !is null);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
auto rc = typeof(return)(allocator);
|
auto rc = typeof(return)(allocator);
|
||||||
|
|
||||||
@ -546,7 +546,7 @@ in
|
|||||||
assert(allocator !is null);
|
assert(allocator !is null);
|
||||||
assert(size <= size_t.max / ElementType!T.sizeof);
|
assert(size <= size_t.max / ElementType!T.sizeof);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
return RefCounted!T(allocator.make!T(size), allocator);
|
return RefCounted!T(allocator.make!T(size), allocator);
|
||||||
}
|
}
|
||||||
@ -664,7 +664,7 @@ struct Unique(T)
|
|||||||
{
|
{
|
||||||
assert(allocator !is null);
|
assert(allocator !is null);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
this.allocator_ = allocator;
|
this.allocator_ = allocator;
|
||||||
}
|
}
|
||||||
@ -849,7 +849,7 @@ in
|
|||||||
{
|
{
|
||||||
assert(allocator !is null);
|
assert(allocator !is null);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
auto payload = allocator.make!(T, A)(args);
|
auto payload = allocator.make!(T, A)(args);
|
||||||
return Unique!T(payload, allocator);
|
return Unique!T(payload, allocator);
|
||||||
@ -877,7 +877,7 @@ in
|
|||||||
assert(allocator !is null);
|
assert(allocator !is null);
|
||||||
assert(size <= size_t.max / ElementType!T.sizeof);
|
assert(size <= size_t.max / ElementType!T.sizeof);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
auto payload = allocator.resize!(ElementType!T)(null, size);
|
auto payload = allocator.resize!(ElementType!T)(null, size);
|
||||||
return Unique!T(payload, allocator);
|
return Unique!T(payload, allocator);
|
||||||
|
@ -275,15 +275,50 @@ enum bool isTemplate(alias T) = __traits(isTemplate, T);
|
|||||||
static assert(!isTemplate!(S!int));
|
static assert(!isTemplate!(S!int));
|
||||||
}
|
}
|
||||||
|
|
||||||
deprecated("Use is(T == interface) instead")
|
/**
|
||||||
|
* Tests whether $(D_PARAM T) is an interface.
|
||||||
|
*
|
||||||
|
* Params:
|
||||||
|
* T = A type.
|
||||||
|
*
|
||||||
|
* Returns: $(D_KEYWORD true) if $(D_PARAM T) is an interface,
|
||||||
|
* $(D_KEYWORD false) otherwise.
|
||||||
|
*/
|
||||||
enum bool isInterface(T) = is(T == interface);
|
enum bool isInterface(T) = is(T == interface);
|
||||||
|
|
||||||
deprecated("Use is(T == class) instead")
|
/**
|
||||||
|
* Tests whether $(D_PARAM T) is a class.
|
||||||
|
*
|
||||||
|
* Params:
|
||||||
|
* T = A type.
|
||||||
|
*
|
||||||
|
* Returns: $(D_KEYWORD true) if $(D_PARAM T) is a class,
|
||||||
|
* $(D_KEYWORD false) otherwise.
|
||||||
|
*/
|
||||||
enum bool isClass(T) = is(T == class);
|
enum bool isClass(T) = is(T == class);
|
||||||
|
|
||||||
deprecated("Use is(T == struct) instead")
|
/**
|
||||||
|
* Tests whether $(D_PARAM T) is a struct.
|
||||||
|
*
|
||||||
|
* Params:
|
||||||
|
* T = A type.
|
||||||
|
*
|
||||||
|
* Returns: $(D_KEYWORD true) if $(D_PARAM T) is a struct,
|
||||||
|
* $(D_KEYWORD false) otherwise.
|
||||||
|
*/
|
||||||
enum bool isStruct(T) = is(T == struct);
|
enum bool isStruct(T) = is(T == struct);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests whether $(D_PARAM T) is a enum.
|
||||||
|
*
|
||||||
|
* Params:
|
||||||
|
* T = A type.
|
||||||
|
*
|
||||||
|
* Returns: $(D_KEYWORD true) if $(D_PARAM T) is an enum,
|
||||||
|
* $(D_KEYWORD false) otherwise.
|
||||||
|
*/
|
||||||
|
enum bool isEnum(T) = is(T == enum);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines whether $(D_PARAM T) is a polymorphic type, i.e. a
|
* Determines whether $(D_PARAM T) is a polymorphic type, i.e. a
|
||||||
* $(D_KEYWORD class) or an $(D_KEYWORD interface).
|
* $(D_KEYWORD class) or an $(D_KEYWORD interface).
|
||||||
|
@ -77,7 +77,7 @@ struct NetworkOrder(uint L)
|
|||||||
{
|
{
|
||||||
assert(value <= pow(2, L * 8) - 1);
|
assert(value <= pow(2, L * 8) - 1);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
this.value = value & StorageType.max;
|
this.value = value & StorageType.max;
|
||||||
}
|
}
|
||||||
@ -92,7 +92,7 @@ struct NetworkOrder(uint L)
|
|||||||
{
|
{
|
||||||
assert(this.length > 0);
|
assert(this.length > 0);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
return this.value & 0xff;
|
return this.value & 0xff;
|
||||||
}
|
}
|
||||||
@ -107,7 +107,7 @@ struct NetworkOrder(uint L)
|
|||||||
{
|
{
|
||||||
assert(this.length > 0);
|
assert(this.length > 0);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
return (this.value >> ((this.length - 1) * 8)) & 0xff;
|
return (this.value >> ((this.length - 1) * 8)) & 0xff;
|
||||||
}
|
}
|
||||||
@ -122,7 +122,7 @@ struct NetworkOrder(uint L)
|
|||||||
{
|
{
|
||||||
assert(this.length > 0);
|
assert(this.length > 0);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
this.value >>= 8;
|
this.value >>= 8;
|
||||||
--this.size;
|
--this.size;
|
||||||
@ -138,7 +138,7 @@ struct NetworkOrder(uint L)
|
|||||||
{
|
{
|
||||||
assert(this.length > 0);
|
assert(this.length > 0);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
this.value &= StorageType.max >> ((StorageType.sizeof - this.length) * 8);
|
this.value &= StorageType.max >> ((StorageType.sizeof - this.length) * 8);
|
||||||
--this.size;
|
--this.size;
|
||||||
|
@ -185,7 +185,7 @@ else version (Windows)
|
|||||||
{
|
{
|
||||||
assert(count >= 0);
|
assert(count >= 0);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
DWORD lpNumber;
|
DWORD lpNumber;
|
||||||
BOOL result = GetOverlappedResult(overlapped.handle,
|
BOOL result = GetOverlappedResult(overlapped.handle,
|
||||||
@ -259,7 +259,7 @@ else version (Windows)
|
|||||||
{
|
{
|
||||||
assert(count >= 0);
|
assert(count >= 0);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
DWORD lpNumber;
|
DWORD lpNumber;
|
||||||
BOOL result = GetOverlappedResult(overlapped.handle,
|
BOOL result = GetOverlappedResult(overlapped.handle,
|
||||||
@ -720,7 +720,7 @@ abstract class Socket
|
|||||||
assert(handle != SocketType.init);
|
assert(handle != SocketType.init);
|
||||||
assert(handle_ == SocketType.init, "Socket handle cannot be changed");
|
assert(handle_ == SocketType.init, "Socket handle cannot be changed");
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
handle_ = handle;
|
handle_ = handle;
|
||||||
|
|
||||||
@ -749,7 +749,7 @@ abstract class Socket
|
|||||||
{
|
{
|
||||||
assert(handle != SocketType.init);
|
assert(handle != SocketType.init);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
scope (failure)
|
scope (failure)
|
||||||
{
|
{
|
||||||
|
@ -59,7 +59,7 @@ in
|
|||||||
{
|
{
|
||||||
assert(array.length > 0);
|
assert(array.length > 0);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
return array[0];
|
return array[0];
|
||||||
}
|
}
|
||||||
@ -99,7 +99,7 @@ in
|
|||||||
{
|
{
|
||||||
assert(array.length > 0);
|
assert(array.length > 0);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
return array[$ - 1];
|
return array[$ - 1];
|
||||||
}
|
}
|
||||||
@ -138,7 +138,7 @@ in
|
|||||||
{
|
{
|
||||||
assert(array.length > 0);
|
assert(array.length > 0);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
array = array[1 .. $];
|
array = array[1 .. $];
|
||||||
}
|
}
|
||||||
@ -149,7 +149,7 @@ in
|
|||||||
{
|
{
|
||||||
assert(array.length > 0);
|
assert(array.length > 0);
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
array = array[0 .. $ - 1];
|
array = array[0 .. $ - 1];
|
||||||
}
|
}
|
||||||
|
@ -1053,7 +1053,7 @@ in
|
|||||||
assert(count <= range.length);
|
assert(count <= range.length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
static if (hasSlicing!R)
|
static if (hasSlicing!R)
|
||||||
{
|
{
|
||||||
@ -1112,7 +1112,7 @@ in
|
|||||||
assert(count <= range.length);
|
assert(count <= range.length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
body
|
do
|
||||||
{
|
{
|
||||||
static if (hasSlicing!R)
|
static if (hasSlicing!R)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user