mirror of
https://github.com/dlang/phobos.git
synced 2025-04-29 14:40:30 +03:00
Phobos should only mention tuple as std.typecons.Tuple
This commit is contained in:
parent
0f74b4c29f
commit
a76d90c927
11 changed files with 141 additions and 133 deletions
|
@ -90,7 +90,7 @@ uint among(alias pred = (a, b) => a == b, Value, Values...)
|
||||||
|
|
||||||
/// Ditto
|
/// Ditto
|
||||||
template among(values...)
|
template among(values...)
|
||||||
if (isExpressionTuple!values)
|
if (isExpressionList!values)
|
||||||
{
|
{
|
||||||
uint among(Value)(Value value)
|
uint among(Value)(Value value)
|
||||||
if (!is(CommonType!(Value, values) == void))
|
if (!is(CommonType!(Value, values) == void))
|
||||||
|
@ -169,8 +169,8 @@ efficient search, but one that only supports matching on equality:
|
||||||
// in a tuple.
|
// in a tuple.
|
||||||
private template indexOfFirstOvershadowingChoiceOnLast(choices...)
|
private template indexOfFirstOvershadowingChoiceOnLast(choices...)
|
||||||
{
|
{
|
||||||
alias firstParameterTypes = ParameterTypeTuple!(choices[0]);
|
alias firstParameterTypes = ParameterTypes!(choices[0]);
|
||||||
alias lastParameterTypes = ParameterTypeTuple!(choices[$ - 1]);
|
alias lastParameterTypes = ParameterTypes!(choices[$ - 1]);
|
||||||
|
|
||||||
static if (lastParameterTypes.length == 0)
|
static if (lastParameterTypes.length == 0)
|
||||||
{
|
{
|
||||||
|
@ -254,7 +254,7 @@ auto castSwitch(choices...)(Object switchObject)
|
||||||
static assert(isCallable!choice,
|
static assert(isCallable!choice,
|
||||||
"A choice handler must be callable");
|
"A choice handler must be callable");
|
||||||
|
|
||||||
alias choiceParameterTypes = ParameterTypeTuple!choice;
|
alias choiceParameterTypes = ParameterTypes!choice;
|
||||||
static assert(choiceParameterTypes.length <= 1,
|
static assert(choiceParameterTypes.length <= 1,
|
||||||
"A choice handler can not have more than one argument.");
|
"A choice handler can not have more than one argument.");
|
||||||
|
|
||||||
|
@ -270,7 +270,7 @@ auto castSwitch(choices...)(Object switchObject)
|
||||||
static assert(indexOfOvershadowingChoice == index,
|
static assert(indexOfOvershadowingChoice == index,
|
||||||
"choice number %d(type %s) is overshadowed by choice number %d(type %s)".format(
|
"choice number %d(type %s) is overshadowed by choice number %d(type %s)".format(
|
||||||
index + 1, CastClass.stringof, indexOfOvershadowingChoice + 1,
|
index + 1, CastClass.stringof, indexOfOvershadowingChoice + 1,
|
||||||
ParameterTypeTuple!(choices[indexOfOvershadowingChoice])[0].stringof));
|
ParameterTypes!(choices[indexOfOvershadowingChoice])[0].stringof));
|
||||||
|
|
||||||
if (classInfo == typeid(CastClass))
|
if (classInfo == typeid(CastClass))
|
||||||
{
|
{
|
||||||
|
@ -297,7 +297,7 @@ auto castSwitch(choices...)(Object switchObject)
|
||||||
// Checking for derived matches:
|
// Checking for derived matches:
|
||||||
foreach (choice; choices)
|
foreach (choice; choices)
|
||||||
{
|
{
|
||||||
alias choiceParameterTypes = ParameterTypeTuple!choice;
|
alias choiceParameterTypes = ParameterTypes!choice;
|
||||||
static if (choiceParameterTypes.length == 1)
|
static if (choiceParameterTypes.length == 1)
|
||||||
{
|
{
|
||||||
if (auto castedObject = cast(choiceParameterTypes[0]) switchObject)
|
if (auto castedObject = cast(choiceParameterTypes[0]) switchObject)
|
||||||
|
@ -327,7 +327,7 @@ auto castSwitch(choices...)(Object switchObject)
|
||||||
// Checking for null matches:
|
// Checking for null matches:
|
||||||
foreach (index, choice; choices)
|
foreach (index, choice; choices)
|
||||||
{
|
{
|
||||||
static if (ParameterTypeTuple!(choice).length == 0)
|
static if (ParameterTypes!(choice).length == 0)
|
||||||
{
|
{
|
||||||
immutable indexOfOvershadowingChoice =
|
immutable indexOfOvershadowingChoice =
|
||||||
indexOfFirstOvershadowingChoiceOnLast!(choices[0..index + 1]);
|
indexOfFirstOvershadowingChoiceOnLast!(choices[0..index + 1]);
|
||||||
|
|
|
@ -150,7 +150,7 @@ private
|
||||||
|
|
||||||
auto map(Op)( Op op )
|
auto map(Op)( Op op )
|
||||||
{
|
{
|
||||||
alias Args = ParameterTypeTuple!(Op);
|
alias Args = ParameterTypes!(Op);
|
||||||
|
|
||||||
static if( Args.length == 1 )
|
static if( Args.length == 1 )
|
||||||
{
|
{
|
||||||
|
@ -171,7 +171,7 @@ private
|
||||||
foreach( i, t1; T )
|
foreach( i, t1; T )
|
||||||
{
|
{
|
||||||
static assert( isFunctionPointer!t1 || isDelegate!t1 );
|
static assert( isFunctionPointer!t1 || isDelegate!t1 );
|
||||||
alias a1 = ParameterTypeTuple!(t1);
|
alias a1 = ParameterTypes!(t1);
|
||||||
alias r1 = ReturnType!(t1);
|
alias r1 = ReturnType!(t1);
|
||||||
|
|
||||||
static if( i < T.length - 1 && is( r1 == void ) )
|
static if( i < T.length - 1 && is( r1 == void ) )
|
||||||
|
@ -183,7 +183,7 @@ private
|
||||||
foreach( t2; T[i+1 .. $] )
|
foreach( t2; T[i+1 .. $] )
|
||||||
{
|
{
|
||||||
static assert( isFunctionPointer!t2 || isDelegate!t2 );
|
static assert( isFunctionPointer!t2 || isDelegate!t2 );
|
||||||
alias a2 = ParameterTypeTuple!(t2);
|
alias a2 = ParameterTypes!(t2);
|
||||||
|
|
||||||
static assert( !is( a1 == a2 ),
|
static assert( !is( a1 == a2 ),
|
||||||
"function with arguments " ~ a1.stringof ~
|
"function with arguments " ~ a1.stringof ~
|
||||||
|
@ -397,8 +397,8 @@ private template isSpawnable(F, T...)
|
||||||
{
|
{
|
||||||
template isParamsImplicitlyConvertible(F1, F2, int i=0)
|
template isParamsImplicitlyConvertible(F1, F2, int i=0)
|
||||||
{
|
{
|
||||||
alias param1 = ParameterTypeTuple!F1;
|
alias param1 = ParameterTypes!F1;
|
||||||
alias param2 = ParameterTypeTuple!F2;
|
alias param2 = ParameterTypes!F2;
|
||||||
static if (param1.length != param2.length)
|
static if (param1.length != param2.length)
|
||||||
enum isParamsImplicitlyConvertible = false;
|
enum isParamsImplicitlyConvertible = false;
|
||||||
else static if (param1.length == i)
|
else static if (param1.length == i)
|
||||||
|
@ -1920,7 +1920,7 @@ private
|
||||||
{
|
{
|
||||||
foreach( i, t; Ops )
|
foreach( i, t; Ops )
|
||||||
{
|
{
|
||||||
alias Args = ParameterTypeTuple!(t);
|
alias Args = ParameterTypes!(t);
|
||||||
auto op = ops[i];
|
auto op = ops[i];
|
||||||
|
|
||||||
if( msg.convertsTo!(Args) )
|
if( msg.convertsTo!(Args) )
|
||||||
|
|
|
@ -1066,7 +1066,7 @@ public:
|
||||||
scope(exit) colIndex++;
|
scope(exit) colIndex++;
|
||||||
if (indices.length > 0)
|
if (indices.length > 0)
|
||||||
{
|
{
|
||||||
foreach(ti, ToType; FieldTypeTuple!(Contents))
|
foreach(ti, ToType; FieldTypes!(Contents))
|
||||||
{
|
{
|
||||||
if (indices[ti] == colIndex)
|
if (indices[ti] == colIndex)
|
||||||
{
|
{
|
||||||
|
@ -1077,7 +1077,7 @@ public:
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
foreach(ti, ToType; FieldTypeTuple!(Contents))
|
foreach(ti, ToType; FieldTypes!(Contents))
|
||||||
{
|
{
|
||||||
if (ti == colIndex)
|
if (ti == colIndex)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1214,7 +1214,7 @@ unittest
|
||||||
//To check the class payload itself, iterate on its members:
|
//To check the class payload itself, iterate on its members:
|
||||||
()
|
()
|
||||||
{
|
{
|
||||||
foreach (index, _; FieldTypeTuple!C)
|
foreach (index, _; FieldTypes!C)
|
||||||
if (doesPointTo(a.tupleof[index], i))
|
if (doesPointTo(a.tupleof[index], i))
|
||||||
return;
|
return;
|
||||||
assert(0);
|
assert(0);
|
||||||
|
|
|
@ -87,10 +87,10 @@ private template needOpCallAlias(alias fun)
|
||||||
*/
|
*/
|
||||||
static if (is(typeof(fun.opCall) == function))
|
static if (is(typeof(fun.opCall) == function))
|
||||||
{
|
{
|
||||||
import std.traits : ParameterTypeTuple;
|
import std.traits : ParameterTypes;
|
||||||
|
|
||||||
enum needOpCallAlias = !is(typeof(fun)) && __traits(compiles, () {
|
enum needOpCallAlias = !is(typeof(fun)) && __traits(compiles, () {
|
||||||
return fun(ParameterTypeTuple!fun.init);
|
return fun(ParameterTypes!fun.init);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -659,7 +659,7 @@ template partial(alias fun, alias arg)
|
||||||
{
|
{
|
||||||
static if (is(typeof(fun) == delegate) || is(typeof(fun) == function))
|
static if (is(typeof(fun) == delegate) || is(typeof(fun) == function))
|
||||||
{
|
{
|
||||||
ReturnType!fun partial(ParameterTypeTuple!fun[1..$] args2)
|
ReturnType!fun partial(ParameterTypes!fun[1..$] args2)
|
||||||
{
|
{
|
||||||
return fun(arg, args2);
|
return fun(arg, args2);
|
||||||
}
|
}
|
||||||
|
@ -1024,11 +1024,11 @@ is useful to memoize an impure function, too.
|
||||||
*/
|
*/
|
||||||
template memoize(alias fun)
|
template memoize(alias fun)
|
||||||
{
|
{
|
||||||
// alias Args = ParameterTypeTuple!fun; // Bugzilla 13580
|
// alias Args = ParameterTypes!fun; // Bugzilla 13580
|
||||||
|
|
||||||
ReturnType!fun memoize(ParameterTypeTuple!fun args)
|
ReturnType!fun memoize(ParameterTypes!fun args)
|
||||||
{
|
{
|
||||||
alias Args = ParameterTypeTuple!fun;
|
alias Args = ParameterTypes!fun;
|
||||||
import std.typecons : Tuple;
|
import std.typecons : Tuple;
|
||||||
|
|
||||||
static ReturnType!fun[Tuple!Args] memo;
|
static ReturnType!fun[Tuple!Args] memo;
|
||||||
|
@ -1042,11 +1042,11 @@ template memoize(alias fun)
|
||||||
/// ditto
|
/// ditto
|
||||||
template memoize(alias fun, uint maxSize)
|
template memoize(alias fun, uint maxSize)
|
||||||
{
|
{
|
||||||
// alias Args = ParameterTypeTuple!fun; // Bugzilla 13580
|
// alias Args = ParameterTypes!fun; // Bugzilla 13580
|
||||||
ReturnType!fun memoize(ParameterTypeTuple!fun args)
|
ReturnType!fun memoize(ParameterTypes!fun args)
|
||||||
{
|
{
|
||||||
import std.typecons : tuple;
|
import std.typecons : tuple;
|
||||||
static struct Value { ParameterTypeTuple!fun args; ReturnType!fun res; }
|
static struct Value { ParameterTypes!fun args; ReturnType!fun res; }
|
||||||
static Value[] memo;
|
static Value[] memo;
|
||||||
static size_t[] initialized;
|
static size_t[] initialized;
|
||||||
|
|
||||||
|
@ -1209,7 +1209,7 @@ private struct DelegateFaker(F)
|
||||||
*--------------------
|
*--------------------
|
||||||
* struct DelegateFaker(F) {
|
* struct DelegateFaker(F) {
|
||||||
* extern(linkage)
|
* extern(linkage)
|
||||||
* [ref] ReturnType!F doIt(ParameterTypeTuple!F args) [@attributes]
|
* [ref] ReturnType!F doIt(ParameterTypes!F args) [@attributes]
|
||||||
* {
|
* {
|
||||||
* auto fp = cast(F) &this;
|
* auto fp = cast(F) &this;
|
||||||
* return fp(args);
|
* return fp(args);
|
||||||
|
@ -1229,7 +1229,7 @@ private struct DelegateFaker(F)
|
||||||
template generateFunctionBody(unused...)
|
template generateFunctionBody(unused...)
|
||||||
{
|
{
|
||||||
enum generateFunctionBody =
|
enum generateFunctionBody =
|
||||||
// [ref] ReturnType doIt(ParameterTypeTuple args) @attributes
|
// [ref] ReturnType doIt(ParameterTypes args) @attributes
|
||||||
q{
|
q{
|
||||||
// When this function gets called, the this pointer isn't
|
// When this function gets called, the this pointer isn't
|
||||||
// really a this pointer (no instance even really exists), but
|
// really a this pointer (no instance even really exists), but
|
||||||
|
|
|
@ -254,7 +254,7 @@ private template isSafeTask(F)
|
||||||
(functionAttributes!F & (FunctionAttribute.safe | FunctionAttribute.trusted)) != 0 &&
|
(functionAttributes!F & (FunctionAttribute.safe | FunctionAttribute.trusted)) != 0 &&
|
||||||
(functionAttributes!F & FunctionAttribute.ref_) == 0 &&
|
(functionAttributes!F & FunctionAttribute.ref_) == 0 &&
|
||||||
(isFunctionPointer!F || !hasUnsharedAliasing!F) &&
|
(isFunctionPointer!F || !hasUnsharedAliasing!F) &&
|
||||||
std.meta.algorithm.all!(noUnsharedAliasing, ParameterTypeTuple!F);
|
std.meta.algorithm.all!(noUnsharedAliasing, ParameterTypes!F);
|
||||||
}
|
}
|
||||||
|
|
||||||
unittest
|
unittest
|
||||||
|
@ -2342,9 +2342,9 @@ public:
|
||||||
*/
|
*/
|
||||||
auto asyncBuf(C1, C2)(C1 next, C2 empty, size_t initialBufSize = 0, size_t nBuffers = 100)
|
auto asyncBuf(C1, C2)(C1 next, C2 empty, size_t initialBufSize = 0, size_t nBuffers = 100)
|
||||||
if(is(typeof(C2.init()) : bool) &&
|
if(is(typeof(C2.init()) : bool) &&
|
||||||
ParameterTypeTuple!C1.length == 1 &&
|
ParameterTypes!C1.length == 1 &&
|
||||||
ParameterTypeTuple!C2.length == 0 &&
|
ParameterTypes!C2.length == 0 &&
|
||||||
isArray!(ParameterTypeTuple!C1[0])
|
isArray!(ParameterTypes!C1[0])
|
||||||
) {
|
) {
|
||||||
auto roundRobin = RoundRobinBuffer!(C1, C2)(next, empty, initialBufSize, nBuffers);
|
auto roundRobin = RoundRobinBuffer!(C1, C2)(next, empty, initialBufSize, nBuffers);
|
||||||
return asyncBuf(roundRobin, nBuffers / 2);
|
return asyncBuf(roundRobin, nBuffers / 2);
|
||||||
|
@ -3492,7 +3492,7 @@ int doSizeZeroCase(R, Delegate)(ref ParallelForeach!R p, Delegate dg)
|
||||||
{
|
{
|
||||||
foreach(ref ElementType!R elem; range)
|
foreach(ref ElementType!R elem; range)
|
||||||
{
|
{
|
||||||
static if(ParameterTypeTuple!dg.length == 2)
|
static if(ParameterTypes!dg.length == 2)
|
||||||
{
|
{
|
||||||
res = dg(index, elem);
|
res = dg(index, elem);
|
||||||
}
|
}
|
||||||
|
@ -3508,7 +3508,7 @@ int doSizeZeroCase(R, Delegate)(ref ParallelForeach!R p, Delegate dg)
|
||||||
{
|
{
|
||||||
foreach(ElementType!R elem; range)
|
foreach(ElementType!R elem; range)
|
||||||
{
|
{
|
||||||
static if(ParameterTypeTuple!dg.length == 2)
|
static if(ParameterTypes!dg.length == 2)
|
||||||
{
|
{
|
||||||
res = dg(index, elem);
|
res = dg(index, elem);
|
||||||
}
|
}
|
||||||
|
@ -3532,7 +3532,7 @@ private enum string parallelApplyMixinRandomAccess = q{
|
||||||
}
|
}
|
||||||
|
|
||||||
// Whether iteration is with or without an index variable.
|
// Whether iteration is with or without an index variable.
|
||||||
enum withIndex = ParameterTypeTuple!(typeof(dg)).length == 2;
|
enum withIndex = ParameterTypes!(typeof(dg)).length == 2;
|
||||||
|
|
||||||
shared size_t workUnitIndex = size_t.max; // Effectively -1: chunkIndex + 1 == 0
|
shared size_t workUnitIndex = size_t.max; // Effectively -1: chunkIndex + 1 == 0
|
||||||
immutable len = range.length;
|
immutable len = range.length;
|
||||||
|
@ -3587,7 +3587,7 @@ enum string parallelApplyMixinInputRange = q{
|
||||||
}
|
}
|
||||||
|
|
||||||
// Whether iteration is with or without an index variable.
|
// Whether iteration is with or without an index variable.
|
||||||
enum withIndex = ParameterTypeTuple!(typeof(dg)).length == 2;
|
enum withIndex = ParameterTypes!(typeof(dg)).length == 2;
|
||||||
|
|
||||||
// This protects the range while copying it.
|
// This protects the range while copying it.
|
||||||
auto rangeMutex = new Mutex();
|
auto rangeMutex = new Mutex();
|
||||||
|
@ -3844,7 +3844,7 @@ private struct RoundRobinBuffer(C1, C2)
|
||||||
{
|
{
|
||||||
// No need for constraints because they're already checked for in asyncBuf.
|
// No need for constraints because they're already checked for in asyncBuf.
|
||||||
|
|
||||||
alias Array = ParameterTypeTuple!(C1.init)[0];
|
alias Array = ParameterTypes!(C1.init)[0];
|
||||||
alias T = typeof(Array.init[0]);
|
alias T = typeof(Array.init[0]);
|
||||||
|
|
||||||
T[][] bufs;
|
T[][] bufs;
|
||||||
|
|
12
std/stdio.d
12
std/stdio.d
|
@ -2595,12 +2595,12 @@ $(D Range) that locks the file and allows fast writing to it.
|
||||||
/// ditto
|
/// ditto
|
||||||
void put(C)(C c) @safe if (is(C : const(dchar)))
|
void put(C)(C c) @safe if (is(C : const(dchar)))
|
||||||
{
|
{
|
||||||
import std.traits : ParameterTypeTuple;
|
import std.traits : ParameterTypes;
|
||||||
static auto trustedFPUTC(int ch, _iobuf* h) @trusted
|
static auto trustedFPUTC(int ch, _iobuf* h) @trusted
|
||||||
{
|
{
|
||||||
return FPUTC(ch, h);
|
return FPUTC(ch, h);
|
||||||
}
|
}
|
||||||
static auto trustedFPUTWC(ParameterTypeTuple!FPUTWC[0] ch, _iobuf* h) @trusted
|
static auto trustedFPUTWC(ParameterTypes!FPUTWC[0] ch, _iobuf* h) @trusted
|
||||||
{
|
{
|
||||||
return FPUTWC(ch, h);
|
return FPUTWC(ch, h);
|
||||||
}
|
}
|
||||||
|
@ -3656,8 +3656,8 @@ struct lines
|
||||||
// if (fileName.length && fclose(f))
|
// if (fileName.length && fclose(f))
|
||||||
// StdioException("Could not close file `"~fileName~"'");
|
// StdioException("Could not close file `"~fileName~"'");
|
||||||
// }
|
// }
|
||||||
import std.traits : ParameterTypeTuple;
|
import std.traits : ParameterTypes;
|
||||||
alias Parms = ParameterTypeTuple!(dg);
|
alias Parms = ParameterTypes!(dg);
|
||||||
static if (isSomeString!(Parms[$ - 1]))
|
static if (isSomeString!(Parms[$ - 1]))
|
||||||
{
|
{
|
||||||
enum bool duplicate = is(Parms[$ - 1] == string)
|
enum bool duplicate = is(Parms[$ - 1] == string)
|
||||||
|
@ -3702,9 +3702,9 @@ struct lines
|
||||||
{
|
{
|
||||||
import std.exception : assumeUnique;
|
import std.exception : assumeUnique;
|
||||||
import std.conv : to;
|
import std.conv : to;
|
||||||
import std.traits : ParameterTypeTuple;
|
import std.traits : ParameterTypes;
|
||||||
|
|
||||||
alias Parms = ParameterTypeTuple!(dg);
|
alias Parms = ParameterTypes!(dg);
|
||||||
enum duplicate = is(Parms[$ - 1] : immutable(ubyte)[]);
|
enum duplicate = is(Parms[$ - 1] : immutable(ubyte)[]);
|
||||||
int result = 1;
|
int result = 1;
|
||||||
int c = void;
|
int c = void;
|
||||||
|
|
|
@ -2067,8 +2067,8 @@ auto representation(Char)(Char[] s) @safe pure nothrow @nogc
|
||||||
Tuple!(wchar, ushort),
|
Tuple!(wchar, ushort),
|
||||||
Tuple!(dchar, uint )))
|
Tuple!(dchar, uint )))
|
||||||
{
|
{
|
||||||
alias Char = FieldTypeTuple!Type[0];
|
alias Char = FieldTypes!Type[0];
|
||||||
alias Int = FieldTypeTuple!Type[1];
|
alias Int = FieldTypes!Type[1];
|
||||||
enum immutable(Char)[] hello = "hello";
|
enum immutable(Char)[] hello = "hello";
|
||||||
|
|
||||||
test!( immutable Char, immutable Int)(hello);
|
test!( immutable Char, immutable Int)(hello);
|
||||||
|
|
58
std/traits.d
58
std/traits.d
|
@ -896,9 +896,10 @@ unittest
|
||||||
}
|
}
|
||||||
|
|
||||||
/***
|
/***
|
||||||
Get, as a $(D MetaList), the types of the parameters to a function, a pointer
|
Get, as a $(XREF meta.list, MetaList), the types of the parameters to a
|
||||||
to function, a delegate, a struct with an $(D opCall), a pointer to a
|
function, a pointer to function, a delegate, a struct with
|
||||||
struct with an $(D opCall), or a class with an $(D opCall).
|
an $(D opCall), a pointer to a struct with an $(D opCall), or a class
|
||||||
|
with an $(D opCall).
|
||||||
*/
|
*/
|
||||||
template ParameterTypes(func...)
|
template ParameterTypes(func...)
|
||||||
if (func.length == 1 && isCallable!func)
|
if (func.length == 1 && isCallable!func)
|
||||||
|
@ -965,8 +966,8 @@ unittest {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Returns a tuple consisting of the storage classes of the parameters of a
|
Returns a $(XREF meta.list, MetaList) consisting of the storage classes
|
||||||
function $(D func).
|
off the parameters of a function $(D func).
|
||||||
*/
|
*/
|
||||||
enum ParameterStorageClass : uint
|
enum ParameterStorageClass : uint
|
||||||
{
|
{
|
||||||
|
@ -997,7 +998,7 @@ template ParameterStorageClasses(func...)
|
||||||
// chop off CallConvention and FuncAttrs
|
// chop off CallConvention and FuncAttrs
|
||||||
enum margs = demangleFunctionAttributes(mangledName!Func[1 .. $]).rest;
|
enum margs = demangleFunctionAttributes(mangledName!Func[1 .. $]).rest;
|
||||||
|
|
||||||
// demangle Arguments and store parameter storage classes in a tuple
|
// demangle Arguments and store parameter storage classes in a list
|
||||||
template demangleNextParameter(string margs, size_t i = 0)
|
template demangleNextParameter(string margs, size_t i = 0)
|
||||||
{
|
{
|
||||||
static if (i < Params.length)
|
static if (i < Params.length)
|
||||||
|
@ -1092,7 +1093,8 @@ unittest
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Get, as a tuple, the identifiers of the parameters to a function symbol.
|
Get, as a $(XREF meta.list, MetaList), the identifiers of the parameters
|
||||||
|
to a function symbol.
|
||||||
*/
|
*/
|
||||||
template ParameterIdentifiers(func...)
|
template ParameterIdentifiers(func...)
|
||||||
if (func.length == 1 && isCallable!func)
|
if (func.length == 1 && isCallable!func)
|
||||||
|
@ -1181,7 +1183,8 @@ unittest
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Get, as a tuple, the default value of the parameters to a function symbol.
|
Get, as a $(XREF meta.list, MetaList), the default value of the parameters
|
||||||
|
to a function symbol.
|
||||||
If a parameter doesn't have the default value, $(D void) is returned instead.
|
If a parameter doesn't have the default value, $(D void) is returned instead.
|
||||||
*/
|
*/
|
||||||
template ParameterDefaultValues(func...)
|
template ParameterDefaultValues(func...)
|
||||||
|
@ -2170,11 +2173,13 @@ unittest
|
||||||
|
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* Get as a typetuple the types of the fields of a struct, class, or union.
|
* Get as a $(XREF meta.list, MetaList) the types of the fields of a struct,
|
||||||
|
* class, or union.
|
||||||
|
*
|
||||||
* This consists of the fields that take up memory space,
|
* This consists of the fields that take up memory space,
|
||||||
* excluding the hidden fields like the virtual function
|
* excluding the hidden fields like the virtual function
|
||||||
* table pointer or a context pointer for nested types.
|
* table pointer or a context pointer for nested types.
|
||||||
* If $(D T) isn't a struct, class, or union returns typetuple
|
* If $(D T) isn't a struct, class, or union returns type list
|
||||||
* with one element $(D T).
|
* with one element $(D T).
|
||||||
*/
|
*/
|
||||||
template FieldTypes(T)
|
template FieldTypes(T)
|
||||||
|
@ -2224,11 +2229,11 @@ unittest
|
||||||
private enum NameOf(alias T) = T.stringof;
|
private enum NameOf(alias T) = T.stringof;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get as an expression tuple the names of the fields of a struct, class, or
|
* Get as an expression list the names of the fields of a struct, class, or
|
||||||
* union. This consists of the fields that take up memory space, excluding the
|
* union. This consists of the fields that take up memory space, excluding the
|
||||||
* hidden fields like the virtual function table pointer or a context pointer
|
* hidden fields like the virtual function table pointer or a context pointer
|
||||||
* for nested types. If $(D T) isn't a struct, class, or union returns an
|
* for nested types. If $(D T) isn't a struct, class, or union returns an
|
||||||
* expression tuple with an empty string.
|
* expression list with an empty string.
|
||||||
*/
|
*/
|
||||||
template FieldNames(T)
|
template FieldNames(T)
|
||||||
{
|
{
|
||||||
|
@ -3340,13 +3345,13 @@ Params:
|
||||||
E = An enumerated type. $(D E) may have duplicated values.
|
E = An enumerated type. $(D E) may have duplicated values.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Static tuple composed of the members of the enumerated type $(D E).
|
Expression list composed of the members of the enumerated type $(D E).
|
||||||
The members are arranged in the same order as declared in $(D E).
|
The members are arranged in the same order as declared in $(D E).
|
||||||
|
|
||||||
Note:
|
Note:
|
||||||
An enum can have multiple members which have the same value. If you want
|
An enum can have multiple members which have the same value. If you want
|
||||||
to use EnumMembers to e.g. generate switch cases at compile-time,
|
to use EnumMembers to e.g. generate switch cases at compile-time,
|
||||||
you should use the $(XREF typetuple, NoDuplicates) template to avoid
|
you should use the $(XREF meta.list, NoDuplicates) template to avoid
|
||||||
generating duplicate switch cases.
|
generating duplicate switch cases.
|
||||||
|
|
||||||
Note:
|
Note:
|
||||||
|
@ -3488,7 +3493,7 @@ unittest
|
||||||
/***
|
/***
|
||||||
* Get a $(D_PARAM MetaList) of the base class and base interfaces of
|
* Get a $(D_PARAM MetaList) of the base class and base interfaces of
|
||||||
* this class or interface. $(D_PARAM BaseTypes!Object) returns
|
* this class or interface. $(D_PARAM BaseTypes!Object) returns
|
||||||
* the empty type tuple.
|
* the empty type list.
|
||||||
*/
|
*/
|
||||||
template BaseTypes(A)
|
template BaseTypes(A)
|
||||||
{
|
{
|
||||||
|
@ -3533,7 +3538,7 @@ unittest
|
||||||
/**
|
/**
|
||||||
* Get a $(D_PARAM MetaList) of $(I all) base classes of this class,
|
* Get a $(D_PARAM MetaList) of $(I all) base classes of this class,
|
||||||
* in decreasing order. Interfaces are not included. $(D_PARAM
|
* in decreasing order. Interfaces are not included. $(D_PARAM
|
||||||
* BaseClasses!Object) yields the empty type tuple.
|
* BaseClasses!Object) yields the empty type list.
|
||||||
*/
|
*/
|
||||||
template BaseClasses(T)
|
template BaseClasses(T)
|
||||||
if (is(T == class))
|
if (is(T == class))
|
||||||
|
@ -3585,7 +3590,7 @@ unittest
|
||||||
* Get a $(D_PARAM MetaList) of $(I all) interfaces directly or
|
* Get a $(D_PARAM MetaList) of $(I all) interfaces directly or
|
||||||
* indirectly inherited by this class or interface. Interfaces do not
|
* indirectly inherited by this class or interface. Interfaces do not
|
||||||
* repeat if multiply implemented. $(D_PARAM Interfaces!Object)
|
* repeat if multiply implemented. $(D_PARAM Interfaces!Object)
|
||||||
* yields the empty type tuple.
|
* yields the empty type list.
|
||||||
*/
|
*/
|
||||||
template Interfaces(T)
|
template Interfaces(T)
|
||||||
{
|
{
|
||||||
|
@ -3648,7 +3653,7 @@ unittest
|
||||||
* Get a $(D_PARAM MetaList) of $(I all) base classes of $(D_PARAM
|
* Get a $(D_PARAM MetaList) of $(I all) base classes of $(D_PARAM
|
||||||
* T), in decreasing order, followed by $(D_PARAM T)'s
|
* T), in decreasing order, followed by $(D_PARAM T)'s
|
||||||
* interfaces. $(D_PARAM TransitiveBaseTypes!Object) yields the
|
* interfaces. $(D_PARAM TransitiveBaseTypes!Object) yields the
|
||||||
* empty type tuple.
|
* empty type list.
|
||||||
*/
|
*/
|
||||||
template TransitiveBaseTypes(T)
|
template TransitiveBaseTypes(T)
|
||||||
{
|
{
|
||||||
|
@ -3683,8 +3688,10 @@ unittest
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Returns a tuple of non-static functions with the name $(D name) declared in the
|
Returns a symbol list of non-static functions with the name $(D name)
|
||||||
class or interface $(D C). Covariant duplicates are shrunk into the most
|
declared in the class or interface $(D C).
|
||||||
|
|
||||||
|
Covariant duplicates are shrunk into the most
|
||||||
derived one.
|
derived one.
|
||||||
*/
|
*/
|
||||||
template MemberFunctions(C, string name)
|
template MemberFunctions(C, string name)
|
||||||
|
@ -3724,7 +3731,7 @@ template MemberFunctions(C, string name)
|
||||||
alias MetaList!() CollectOverloads; // no overloads in this hierarchy
|
alias MetaList!() CollectOverloads; // no overloads in this hierarchy
|
||||||
}
|
}
|
||||||
|
|
||||||
// duplicates in this tuple will be removed by shrink()
|
// duplicates in this list will be removed by shrink()
|
||||||
alias CollectOverloads!C overloads;
|
alias CollectOverloads!C overloads;
|
||||||
|
|
||||||
// shrinkOne!args[0] = the most derived one in the covariant siblings of target
|
// shrinkOne!args[0] = the most derived one in the covariant siblings of target
|
||||||
|
@ -3884,7 +3891,8 @@ unittest
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Returns a $(D MetaList) of the template arguments used to instantiate $(D T).
|
Returns a $(XREF meta.list, MetaList) of the template arguments used
|
||||||
|
to instantiate $(D T).
|
||||||
*/
|
*/
|
||||||
template TemplateArgsOf(alias T : Base!Args, alias Base, Args...)
|
template TemplateArgsOf(alias T : Base!Args, alias Base, Args...)
|
||||||
{
|
{
|
||||||
|
@ -4017,7 +4025,7 @@ unittest
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a tuple with all possible target types of an implicit
|
* Returns a type list with all possible target types of an implicit
|
||||||
* conversion of a value of type $(D_PARAM T).
|
* conversion of a value of type $(D_PARAM T).
|
||||||
*
|
*
|
||||||
* Important note:
|
* Important note:
|
||||||
|
@ -5542,7 +5550,7 @@ unittest
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether $(D T) is an expression list.
|
* Check whether $(D T) is an expression list.
|
||||||
* An expression list is kind of compile-time list (also $(D MetaList))
|
* An expression list is kind of compile-time list (see $(XREF meta.list, MetaList))
|
||||||
* that only contains expressions.
|
* that only contains expressions.
|
||||||
*
|
*
|
||||||
* See_Also: $(LREF isTypeList).
|
* See_Also: $(LREF isTypeList).
|
||||||
|
@ -5593,7 +5601,7 @@ unittest
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether $(D T) is a type list.
|
* Check whether $(D T) is a type list.
|
||||||
* A type list is kind of compile-time list (also $(D MetaList))
|
* A type list is kind of compile-time list (see $(XREF meta.list, MetaList))
|
||||||
* that only contains types.
|
* that only contains types.
|
||||||
*
|
*
|
||||||
* See_Also: $(LREF isExpressionList).
|
* See_Also: $(LREF isExpressionList).
|
||||||
|
|
122
std/typecons.d
122
std/typecons.d
|
@ -410,7 +410,7 @@ for the second, and so on.
|
||||||
|
|
||||||
The choice of zero-based indexing instead of one-base indexing was
|
The choice of zero-based indexing instead of one-base indexing was
|
||||||
motivated by the ability to use value `Tuple`s with various compile-time
|
motivated by the ability to use value `Tuple`s with various compile-time
|
||||||
loop constructs (e.g. $(XREF typetuple, MetaList) iteration), all of which use
|
loop constructs (e.g. $(XREF meta.list, MetaList) iteration), all of which use
|
||||||
zero-based indexing.
|
zero-based indexing.
|
||||||
|
|
||||||
Params:
|
Params:
|
||||||
|
@ -1909,13 +1909,13 @@ Returns:
|
||||||
{
|
{
|
||||||
return _isNull;
|
return _isNull;
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
Nullable!int ni;
|
Nullable!int ni;
|
||||||
assert(ni.isNull);
|
assert(ni.isNull);
|
||||||
|
|
||||||
ni = 0;
|
ni = 0;
|
||||||
assert(!ni.isNull);
|
assert(!ni.isNull);
|
||||||
}
|
}
|
||||||
|
@ -1928,13 +1928,13 @@ Forces $(D this) to the null state.
|
||||||
.destroy(_value);
|
.destroy(_value);
|
||||||
_isNull = true;
|
_isNull = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
Nullable!int ni = 0;
|
Nullable!int ni = 0;
|
||||||
assert(!ni.isNull);
|
assert(!ni.isNull);
|
||||||
|
|
||||||
ni.nullify();
|
ni.nullify();
|
||||||
assert(ni.isNull);
|
assert(ni.isNull);
|
||||||
}
|
}
|
||||||
|
@ -1956,7 +1956,7 @@ Params:
|
||||||
If this `Nullable` wraps a type that already has a null value
|
If this `Nullable` wraps a type that already has a null value
|
||||||
(such as a pointer), then assigning the null value to this
|
(such as a pointer), then assigning the null value to this
|
||||||
`Nullable` is no different than assigning any other value of
|
`Nullable` is no different than assigning any other value of
|
||||||
type `T`, and the resulting code will look very strange. It
|
type `T`, and the resulting code will look very strange. It
|
||||||
is strongly recommended that this be avoided by instead using
|
is strongly recommended that this be avoided by instead using
|
||||||
the version of `Nullable` that takes an additional `nullValue`
|
the version of `Nullable` that takes an additional `nullValue`
|
||||||
template argument.
|
template argument.
|
||||||
|
@ -1966,7 +1966,7 @@ unittest
|
||||||
//Passes
|
//Passes
|
||||||
Nullable!(int*) npi;
|
Nullable!(int*) npi;
|
||||||
assert(npi.isNull);
|
assert(npi.isNull);
|
||||||
|
|
||||||
//Passes?!
|
//Passes?!
|
||||||
npi = null;
|
npi = null;
|
||||||
assert(!npi.isNull);
|
assert(!npi.isNull);
|
||||||
|
@ -1985,17 +1985,17 @@ Returns:
|
||||||
assert(!isNull, message);
|
assert(!isNull, message);
|
||||||
return _value;
|
return _value;
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
import std.exception: assertThrown, assertNotThrown;
|
import std.exception: assertThrown, assertNotThrown;
|
||||||
|
|
||||||
Nullable!int ni;
|
Nullable!int ni;
|
||||||
//`get` is implicitly called. Will throw
|
//`get` is implicitly called. Will throw
|
||||||
//an AssertError in non-release mode
|
//an AssertError in non-release mode
|
||||||
assertThrown!Throwable(ni == 0);
|
assertThrown!Throwable(ni == 0);
|
||||||
|
|
||||||
ni = 0;
|
ni = 0;
|
||||||
assertNotThrown!Throwable(ni == 0);
|
assertNotThrown!Throwable(ni == 0);
|
||||||
}
|
}
|
||||||
|
@ -2016,21 +2016,21 @@ unittest
|
||||||
string address;
|
string address;
|
||||||
int customerNum;
|
int customerNum;
|
||||||
}
|
}
|
||||||
|
|
||||||
Nullable!CustomerRecord getByName(string name)
|
Nullable!CustomerRecord getByName(string name)
|
||||||
{
|
{
|
||||||
//A bunch of hairy stuff
|
//A bunch of hairy stuff
|
||||||
|
|
||||||
return Nullable!CustomerRecord.init;
|
return Nullable!CustomerRecord.init;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto queryResult = getByName("Doe, John");
|
auto queryResult = getByName("Doe, John");
|
||||||
if (!queryResult.isNull)
|
if (!queryResult.isNull)
|
||||||
{
|
{
|
||||||
//Process Mr. Doe's customer record
|
//Process Mr. Doe's customer record
|
||||||
auto address = queryResult.address;
|
auto address = queryResult.address;
|
||||||
auto customerNum = queryResult.customerNum;
|
auto customerNum = queryResult.customerNum;
|
||||||
|
|
||||||
//Do some things with this customer's info
|
//Do some things with this customer's info
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -2320,7 +2320,7 @@ Nullable!T) because it does not need to store an extra $(D bool).
|
||||||
|
|
||||||
Params:
|
Params:
|
||||||
T = The wrapped type for which Nullable provides a null value.
|
T = The wrapped type for which Nullable provides a null value.
|
||||||
|
|
||||||
nullValue = The null value which denotes the null state of this
|
nullValue = The null value which denotes the null state of this
|
||||||
`Nullable`. Must be of type `T`.
|
`Nullable`. Must be of type `T`.
|
||||||
*/
|
*/
|
||||||
|
@ -2375,14 +2375,14 @@ Returns:
|
||||||
return _value == nullValue;
|
return _value == nullValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
Nullable!(int, -1) ni;
|
Nullable!(int, -1) ni;
|
||||||
//Initialized to "null" state
|
//Initialized to "null" state
|
||||||
assert(ni.isNull);
|
assert(ni.isNull);
|
||||||
|
|
||||||
ni = 0;
|
ni = 0;
|
||||||
assert(!ni.isNull);
|
assert(!ni.isNull);
|
||||||
}
|
}
|
||||||
|
@ -2394,20 +2394,20 @@ Forces $(D this) to the null state.
|
||||||
{
|
{
|
||||||
_value = nullValue;
|
_value = nullValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
Nullable!(int, -1) ni = 0;
|
Nullable!(int, -1) ni = 0;
|
||||||
assert(!ni.isNull);
|
assert(!ni.isNull);
|
||||||
|
|
||||||
ni = -1;
|
ni = -1;
|
||||||
assert(ni.isNull);
|
assert(ni.isNull);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Assigns $(D value) to the internally-held state. If the assignment
|
Assigns $(D value) to the internally-held state. If the assignment
|
||||||
succeeds, $(D this) becomes non-null. No null checks are made. Note
|
succeeds, $(D this) becomes non-null. No null checks are made. Note
|
||||||
that the assignment may leave $(D this) in the null state.
|
that the assignment may leave $(D this) in the null state.
|
||||||
|
|
||||||
Params:
|
Params:
|
||||||
|
@ -2419,13 +2419,13 @@ Params:
|
||||||
{
|
{
|
||||||
_value = value;
|
_value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
If this `Nullable` wraps a type that already has a null value
|
If this `Nullable` wraps a type that already has a null value
|
||||||
(such as a pointer), and that null value is not given for
|
(such as a pointer), and that null value is not given for
|
||||||
`nullValue`, then assigning the null value to this `Nullable`
|
`nullValue`, then assigning the null value to this `Nullable`
|
||||||
is no different than assigning any other value of type `T`,
|
is no different than assigning any other value of type `T`,
|
||||||
and the resulting code will look very strange. It is strongly
|
and the resulting code will look very strange. It is strongly
|
||||||
recommended that this be avoided by using `T`'s "built in"
|
recommended that this be avoided by using `T`'s "built in"
|
||||||
null value for `nullValue`.
|
null value for `nullValue`.
|
||||||
*/
|
*/
|
||||||
|
@ -2435,7 +2435,7 @@ unittest
|
||||||
enum nullVal = cast(int*)0xCAFEBABE;
|
enum nullVal = cast(int*)0xCAFEBABE;
|
||||||
Nullable!(int*, nullVal) npi;
|
Nullable!(int*, nullVal) npi;
|
||||||
assert(npi.isNull);
|
assert(npi.isNull);
|
||||||
|
|
||||||
//Passes?!
|
//Passes?!
|
||||||
npi = null;
|
npi = null;
|
||||||
assert(!npi.isNull);
|
assert(!npi.isNull);
|
||||||
|
@ -2456,17 +2456,17 @@ Returns:
|
||||||
assert(!isNull, message);
|
assert(!isNull, message);
|
||||||
return _value;
|
return _value;
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
import std.exception: assertThrown, assertNotThrown;
|
import std.exception: assertThrown, assertNotThrown;
|
||||||
|
|
||||||
Nullable!(int, -1) ni;
|
Nullable!(int, -1) ni;
|
||||||
//`get` is implicitly called. Will throw
|
//`get` is implicitly called. Will throw
|
||||||
//an error in non-release mode
|
//an error in non-release mode
|
||||||
assertThrown!Throwable(ni == 0);
|
assertThrown!Throwable(ni == 0);
|
||||||
|
|
||||||
ni = 0;
|
ni = 0;
|
||||||
assertNotThrown!Throwable(ni == 0);
|
assertNotThrown!Throwable(ni == 0);
|
||||||
}
|
}
|
||||||
|
@ -2484,14 +2484,14 @@ unittest
|
||||||
Nullable!(size_t, size_t.max) indexOf(string[] haystack, string needle)
|
Nullable!(size_t, size_t.max) indexOf(string[] haystack, string needle)
|
||||||
{
|
{
|
||||||
//Find the needle, returning -1 if not found
|
//Find the needle, returning -1 if not found
|
||||||
|
|
||||||
return Nullable!(size_t, size_t.max).init;
|
return Nullable!(size_t, size_t.max).init;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendLunchInvite(string name)
|
void sendLunchInvite(string name)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
//It's safer than C...
|
//It's safer than C...
|
||||||
auto coworkers = ["Jane", "Jim", "Marry", "Fred"];
|
auto coworkers = ["Jane", "Jim", "Marry", "Fred"];
|
||||||
auto pos = indexOf(coworkers, "Bob");
|
auto pos = indexOf(coworkers, "Bob");
|
||||||
|
@ -2504,7 +2504,7 @@ unittest
|
||||||
{
|
{
|
||||||
//Bob not found; report the error
|
//Bob not found; report the error
|
||||||
}
|
}
|
||||||
|
|
||||||
//And there's no overhead
|
//And there's no overhead
|
||||||
static assert(Nullable!(size_t, size_t.max).sizeof == size_t.sizeof);
|
static assert(Nullable!(size_t, size_t.max).sizeof == size_t.sizeof);
|
||||||
}
|
}
|
||||||
|
@ -2683,13 +2683,13 @@ Params:
|
||||||
{
|
{
|
||||||
_value = value;
|
_value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
NullableRef!int nr = new int(42);
|
NullableRef!int nr = new int(42);
|
||||||
assert(nr == 42);
|
assert(nr == 42);
|
||||||
|
|
||||||
int* n = new int(1);
|
int* n = new int(1);
|
||||||
nr.bind(n);
|
nr.bind(n);
|
||||||
assert(nr == 1);
|
assert(nr == 1);
|
||||||
|
@ -2705,13 +2705,13 @@ Returns:
|
||||||
{
|
{
|
||||||
return _value is null;
|
return _value is null;
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
NullableRef!int nr;
|
NullableRef!int nr;
|
||||||
assert(nr.isNull);
|
assert(nr.isNull);
|
||||||
|
|
||||||
int* n = new int(42);
|
int* n = new int(42);
|
||||||
nr.bind(n);
|
nr.bind(n);
|
||||||
assert(!nr.isNull && nr == 42);
|
assert(!nr.isNull && nr == 42);
|
||||||
|
@ -2724,13 +2724,13 @@ Forces $(D this) to the null state.
|
||||||
{
|
{
|
||||||
_value = null;
|
_value = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
NullableRef!int nr = new int(42);
|
NullableRef!int nr = new int(42);
|
||||||
assert(!nr.isNull);
|
assert(!nr.isNull);
|
||||||
|
|
||||||
nr.nullify();
|
nr.nullify();
|
||||||
assert(nr.isNull);
|
assert(nr.isNull);
|
||||||
}
|
}
|
||||||
|
@ -2751,16 +2751,16 @@ Params:
|
||||||
assert(!isNull, message);
|
assert(!isNull, message);
|
||||||
*_value = value;
|
*_value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
import std.exception: assertThrown, assertNotThrown;
|
import std.exception: assertThrown, assertNotThrown;
|
||||||
|
|
||||||
NullableRef!int nr;
|
NullableRef!int nr;
|
||||||
assert(nr.isNull);
|
assert(nr.isNull);
|
||||||
assertThrown!Throwable(nr = 42);
|
assertThrown!Throwable(nr = 42);
|
||||||
|
|
||||||
nr.bind(new int(0));
|
nr.bind(new int(0));
|
||||||
assert(!nr.isNull);
|
assert(!nr.isNull);
|
||||||
assertNotThrown!Throwable(nr = 42);
|
assertNotThrown!Throwable(nr = 42);
|
||||||
|
@ -2777,17 +2777,17 @@ This function is also called for the implicit conversion to $(D T).
|
||||||
assert(!isNull, message);
|
assert(!isNull, message);
|
||||||
return *_value;
|
return *_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
import std.exception: assertThrown, assertNotThrown;
|
import std.exception: assertThrown, assertNotThrown;
|
||||||
|
|
||||||
NullableRef!int nr;
|
NullableRef!int nr;
|
||||||
//`get` is implicitly called. Will throw
|
//`get` is implicitly called. Will throw
|
||||||
//an error in non-release mode
|
//an error in non-release mode
|
||||||
assertThrown!Throwable(nr == 0);
|
assertThrown!Throwable(nr == 0);
|
||||||
|
|
||||||
nr.bind(new int(0));
|
nr.bind(new int(0));
|
||||||
assertNotThrown!Throwable(nr == 0);
|
assertNotThrown!Throwable(nr == 0);
|
||||||
}
|
}
|
||||||
|
@ -3021,8 +3021,8 @@ unittest
|
||||||
|
|
||||||
/**
|
/**
|
||||||
$(D WhiteHole!Base) is a subclass of $(D Base) which automatically implements
|
$(D WhiteHole!Base) is a subclass of $(D Base) which automatically implements
|
||||||
all abstract member functions as functions that always fail. These functions
|
all abstract member functions as functions that always fail. These functions
|
||||||
simply throw an $(D Error) and never return. `Whitehole` is useful for
|
simply throw an $(D Error) and never return. `Whitehole` is useful for
|
||||||
trapping the use of class member functions that haven't been implemented.
|
trapping the use of class member functions that haven't been implemented.
|
||||||
|
|
||||||
The name came from
|
The name came from
|
||||||
|
@ -3203,7 +3203,7 @@ private static:
|
||||||
import std.meta : Filter;
|
import std.meta : Filter;
|
||||||
static if (names.length > 0)
|
static if (names.length > 0)
|
||||||
{
|
{
|
||||||
alias methods = Filter!(pred, MemberFunctionsTuple!(C, names[0]));
|
alias methods = Filter!(pred, MemberFunctions!(C, names[0]));
|
||||||
alias next = Impl!(names[1 .. $]);
|
alias next = Impl!(names[1 .. $]);
|
||||||
|
|
||||||
static if (methods.length > 0)
|
static if (methods.length > 0)
|
||||||
|
@ -3498,13 +3498,13 @@ Used by MemberFunctionGenerator.
|
||||||
*/
|
*/
|
||||||
package template FuncInfo(alias func, /+[BUG 4217 ?]+/ T = typeof(&func))
|
package template FuncInfo(alias func, /+[BUG 4217 ?]+/ T = typeof(&func))
|
||||||
{
|
{
|
||||||
alias RT = ReturnType!T;
|
alias RT = ReturnType!T;
|
||||||
alias PT = ParameterTypeTuple!T;
|
alias PT = ParameterTypes!T;
|
||||||
}
|
}
|
||||||
package template FuncInfo(Func)
|
package template FuncInfo(Func)
|
||||||
{
|
{
|
||||||
alias RT = ReturnType!Func;
|
alias RT = ReturnType!Func;
|
||||||
alias PT = ParameterTypeTuple!Func;
|
alias PT = ParameterTypes!Func;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -3700,7 +3700,7 @@ private static:
|
||||||
/*** Function Body ***/
|
/*** Function Body ***/
|
||||||
code ~= "{\n";
|
code ~= "{\n";
|
||||||
{
|
{
|
||||||
enum nparams = ParameterTypeTuple!(func).length;
|
enum nparams = ParameterTypes!(func).length;
|
||||||
|
|
||||||
/* Declare keywords: args, self and parent. */
|
/* Declare keywords: args, self and parent. */
|
||||||
string preamble;
|
string preamble;
|
||||||
|
@ -3737,7 +3737,7 @@ private static:
|
||||||
private GenParams generateParameters(string myFuncInfo, func...)()
|
private GenParams generateParameters(string myFuncInfo, func...)()
|
||||||
{
|
{
|
||||||
alias STC = ParameterStorageClass;
|
alias STC = ParameterStorageClass;
|
||||||
alias stcs = ParameterStorageClassTuple!(func);
|
alias stcs = ParameterStorageClasses!(func);
|
||||||
enum nparams = stcs.length;
|
enum nparams = stcs.length;
|
||||||
|
|
||||||
string imports = ""; // any imports required
|
string imports = ""; // any imports required
|
||||||
|
@ -4032,7 +4032,7 @@ if (Targets.length >= 1 && std.meta.algorithm.all!(isMutable, Targets))
|
||||||
enum n = to!string(i);
|
enum n = to!string(i);
|
||||||
static if (fa & FunctionAttribute.property)
|
static if (fa & FunctionAttribute.property)
|
||||||
{
|
{
|
||||||
static if (ParameterTypeTuple!(TargetMembers[i].type).length == 0)
|
static if (ParameterTypes!(TargetMembers[i].type).length == 0)
|
||||||
enum fbody = "_wrap_source."~name;
|
enum fbody = "_wrap_source."~name;
|
||||||
else
|
else
|
||||||
enum fbody = "_wrap_source."~name~" = forward!args";
|
enum fbody = "_wrap_source."~name~" = forward!args";
|
||||||
|
@ -4043,7 +4043,7 @@ if (Targets.length >= 1 && std.meta.algorithm.all!(isMutable, Targets))
|
||||||
}
|
}
|
||||||
enum generateFun =
|
enum generateFun =
|
||||||
"override "~stc~"ReturnType!(TargetMembers["~n~"].type) "
|
"override "~stc~"ReturnType!(TargetMembers["~n~"].type) "
|
||||||
~ name~"(ParameterTypeTuple!(TargetMembers["~n~"].type) args) "~mod~
|
~ name~"(ParameterTypes!(TargetMembers["~n~"].type) args) "~mod~
|
||||||
"{ return "~fbody~"; }";
|
"{ return "~fbody~"; }";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4340,7 +4340,7 @@ private template findCovariantFunction(alias finfo, Source, Fs...)
|
||||||
enum x = check!();
|
enum x = check!();
|
||||||
static if (x == -1 && is(typeof(Source.opDispatch)))
|
static if (x == -1 && is(typeof(Source.opDispatch)))
|
||||||
{
|
{
|
||||||
alias Params = ParameterTypeTuple!(finfo.type);
|
alias Params = ParameterTypes!(finfo.type);
|
||||||
enum ptrdiff_t findCovariantFunction =
|
enum ptrdiff_t findCovariantFunction =
|
||||||
is(typeof(( Source).init.opDispatch!(finfo.name)(Params.init))) ||
|
is(typeof(( Source).init.opDispatch!(finfo.name)(Params.init))) ||
|
||||||
is(typeof(( const Source).init.opDispatch!(finfo.name)(Params.init))) ||
|
is(typeof(( const Source).init.opDispatch!(finfo.name)(Params.init))) ||
|
||||||
|
@ -4452,8 +4452,8 @@ private template DerivedFunctionType(T...)
|
||||||
{
|
{
|
||||||
alias FA = FunctionAttribute;
|
alias FA = FunctionAttribute;
|
||||||
|
|
||||||
alias F0 = T[0], R0 = ReturnType!F0, PSTC0 = ParameterStorageClassTuple!F0;
|
alias F0 = T[0], R0 = ReturnType!F0, PSTC0 = ParameterStorageClasses!F0;
|
||||||
alias F1 = T[1], R1 = ReturnType!F1, PSTC1 = ParameterStorageClassTuple!F1;
|
alias F1 = T[1], R1 = ReturnType!F1, PSTC1 = ParameterStorageClasses!F1;
|
||||||
enum FA0 = functionAttributes!F0;
|
enum FA0 = functionAttributes!F0;
|
||||||
enum FA1 = functionAttributes!F1;
|
enum FA1 = functionAttributes!F1;
|
||||||
|
|
||||||
|
|
|
@ -517,7 +517,7 @@ private:
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
alias ParamTypes = ParameterTypeTuple!A;
|
alias ParamTypes = ParameterTypes!A;
|
||||||
auto p = cast(Variant*) parm;
|
auto p = cast(Variant*) parm;
|
||||||
auto argCount = p.get!size_t;
|
auto argCount = p.get!size_t;
|
||||||
// To assign the tuple we need to use the unqualified version,
|
// To assign the tuple we need to use the unqualified version,
|
||||||
|
@ -1197,7 +1197,7 @@ public:
|
||||||
*/
|
*/
|
||||||
int opApply(Delegate)(scope Delegate dg) if (is(Delegate == delegate))
|
int opApply(Delegate)(scope Delegate dg) if (is(Delegate == delegate))
|
||||||
{
|
{
|
||||||
alias A = ParameterTypeTuple!(Delegate)[0];
|
alias A = ParameterTypes!(Delegate)[0];
|
||||||
if (type == typeid(A[]))
|
if (type == typeid(A[]))
|
||||||
{
|
{
|
||||||
auto arr = get!(A[]);
|
auto arr = get!(A[]);
|
||||||
|
@ -2207,7 +2207,7 @@ private auto visitImpl(bool Strict, VariantType, Handler...)(VariantType variant
|
||||||
// Handle normal function objects
|
// Handle normal function objects
|
||||||
static if (isSomeFunction!dg)
|
static if (isSomeFunction!dg)
|
||||||
{
|
{
|
||||||
alias Params = ParameterTypeTuple!dg;
|
alias Params = ParameterTypes!dg;
|
||||||
static if (Params.length == 0)
|
static if (Params.length == 0)
|
||||||
{
|
{
|
||||||
// Just check exception functions in the first
|
// Just check exception functions in the first
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue