mirror of
https://github.com/dlang/phobos.git
synced 2025-05-01 23:50:31 +03:00
Rename *Tuple symbols
This commit is contained in:
parent
1f08cbfbdb
commit
40ca5eabc6
2 changed files with 74 additions and 52 deletions
99
std/traits.d
99
std/traits.d
|
@ -20,10 +20,10 @@
|
||||||
* $(LREF FunctionTypeOf)
|
* $(LREF FunctionTypeOf)
|
||||||
* $(LREF isSafe)
|
* $(LREF isSafe)
|
||||||
* $(LREF isUnsafe)
|
* $(LREF isUnsafe)
|
||||||
* $(LREF ParameterDefaultValueTuple)
|
* $(LREF ParameterDefaults)
|
||||||
* $(LREF ParameterIdentifierTuple)
|
* $(LREF ParameterIdentifierTuple)
|
||||||
* $(LREF ParameterStorageClassTuple)
|
* $(LREF ParameterStorageClassTuple)
|
||||||
* $(LREF ParameterTypeTuple)
|
* $(LREF Parameters)
|
||||||
* $(LREF ReturnType)
|
* $(LREF ReturnType)
|
||||||
* $(LREF SetFunctionAttributes)
|
* $(LREF SetFunctionAttributes)
|
||||||
* $(LREF variadicFunctionStyle)
|
* $(LREF variadicFunctionStyle)
|
||||||
|
@ -34,7 +34,7 @@
|
||||||
* $(LREF classInstanceAlignment)
|
* $(LREF classInstanceAlignment)
|
||||||
* $(LREF EnumMembers)
|
* $(LREF EnumMembers)
|
||||||
* $(LREF FieldNameTuple)
|
* $(LREF FieldNameTuple)
|
||||||
* $(LREF FieldTypeTuple)
|
* $(LREF Fields)
|
||||||
* $(LREF hasAliasing)
|
* $(LREF hasAliasing)
|
||||||
* $(LREF hasElaborateAssign)
|
* $(LREF hasElaborateAssign)
|
||||||
* $(LREF hasElaborateCopyConstructor)
|
* $(LREF hasElaborateCopyConstructor)
|
||||||
|
@ -98,7 +98,7 @@
|
||||||
* $(LREF isAbstractFunction)
|
* $(LREF isAbstractFunction)
|
||||||
* $(LREF isCallable)
|
* $(LREF isCallable)
|
||||||
* $(LREF isDelegate)
|
* $(LREF isDelegate)
|
||||||
* $(LREF isExpressionTuple)
|
* $(LREF isExpressions)
|
||||||
* $(LREF isFinalClass)
|
* $(LREF isFinalClass)
|
||||||
* $(LREF isFinalFunction)
|
* $(LREF isFinalFunction)
|
||||||
* $(LREF isFunctionPointer)
|
* $(LREF isFunctionPointer)
|
||||||
|
@ -134,7 +134,7 @@
|
||||||
* Copyright: Copyright Digital Mars 2005 - 2009.
|
* Copyright: Copyright Digital Mars 2005 - 2009.
|
||||||
* License: $(WEB www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
|
* License: $(WEB www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
|
||||||
* Authors: $(WEB digitalmars.com, Walter Bright),
|
* Authors: $(WEB digitalmars.com, Walter Bright),
|
||||||
* Tomasz Stachowiak ($(D isExpressionTuple)),
|
* Tomasz Stachowiak ($(D isExpressions)),
|
||||||
* $(WEB erdani.org, Andrei Alexandrescu),
|
* $(WEB erdani.org, Andrei Alexandrescu),
|
||||||
* Shin Fujishiro,
|
* Shin Fujishiro,
|
||||||
* $(WEB octarineparrot.com, Robert Clipsham),
|
* $(WEB octarineparrot.com, Robert Clipsham),
|
||||||
|
@ -593,7 +593,7 @@ private template fqnType(T,
|
||||||
|
|
||||||
string parametersTypeString(T)() @property
|
string parametersTypeString(T)() @property
|
||||||
{
|
{
|
||||||
alias parameters = ParameterTypeTuple!(T);
|
alias parameters = Parameters!(T);
|
||||||
alias parameterStC = ParameterStorageClassTuple!(T);
|
alias parameterStC = ParameterStorageClassTuple!(T);
|
||||||
|
|
||||||
enum variadic = variadicFunctionStyle!T;
|
enum variadic = variadicFunctionStyle!T;
|
||||||
|
@ -900,11 +900,11 @@ Get, as a tuple, the types of the parameters to a function, a pointer
|
||||||
to function, a delegate, a struct with an $(D opCall), a pointer to a
|
to function, a delegate, a struct with an $(D opCall), a pointer to a
|
||||||
struct with an $(D opCall), or a class with an $(D opCall).
|
struct with an $(D opCall), or a class with an $(D opCall).
|
||||||
*/
|
*/
|
||||||
template ParameterTypeTuple(func...)
|
template Parameters(func...)
|
||||||
if (func.length == 1 && isCallable!func)
|
if (func.length == 1 && isCallable!func)
|
||||||
{
|
{
|
||||||
static if (is(FunctionTypeOf!func P == function))
|
static if (is(FunctionTypeOf!func P == function))
|
||||||
alias ParameterTypeTuple = P;
|
alias Parameters = P;
|
||||||
else
|
else
|
||||||
static assert(0, "argument has no parameters");
|
static assert(0, "argument has no parameters");
|
||||||
}
|
}
|
||||||
|
@ -913,10 +913,15 @@ template ParameterTypeTuple(func...)
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
int foo(int, long);
|
int foo(int, long);
|
||||||
void bar(ParameterTypeTuple!foo); // declares void bar(int, long);
|
void bar(Parameters!foo); // declares void bar(int, long);
|
||||||
void abc(ParameterTypeTuple!foo[1]); // declares void abc(long);
|
void abc(Parameters!foo[1]); // declares void abc(long);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Alternate name for $(LREF Parameters), kept for legacy compatibility.
|
||||||
|
*/
|
||||||
|
alias ParameterTypeTuple = Parameters;
|
||||||
|
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
int foo(int i, bool b) { return 0; }
|
int foo(int i, bool b) { return 0; }
|
||||||
|
@ -948,7 +953,7 @@ arity is undefined for variadic functions.
|
||||||
template arity(alias func)
|
template arity(alias func)
|
||||||
if ( isCallable!func && variadicFunctionStyle!func == Variadic.no )
|
if ( isCallable!func && variadicFunctionStyle!func == Variadic.no )
|
||||||
{
|
{
|
||||||
enum size_t arity = ParameterTypeTuple!func.length;
|
enum size_t arity = Parameters!func.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
|
@ -989,7 +994,7 @@ template ParameterStorageClassTuple(func...)
|
||||||
* TypeFuncion:
|
* TypeFuncion:
|
||||||
* CallConvention FuncAttrs Arguments ArgClose Type
|
* CallConvention FuncAttrs Arguments ArgClose Type
|
||||||
*/
|
*/
|
||||||
alias Params = ParameterTypeTuple!Func;
|
alias Params = Parameters!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;
|
||||||
|
@ -1175,7 +1180,7 @@ unittest
|
||||||
Get, as a tuple, the default value of the parameters to a function symbol.
|
Get, as a tuple, 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 ParameterDefaultValueTuple(func...)
|
template ParameterDefaults(func...)
|
||||||
if (func.length == 1 && isCallable!func)
|
if (func.length == 1 && isCallable!func)
|
||||||
{
|
{
|
||||||
static if (is(FunctionTypeOf!(func[0]) PT == __parameters))
|
static if (is(FunctionTypeOf!(func[0]) PT == __parameters))
|
||||||
|
@ -1218,18 +1223,23 @@ template ParameterDefaultValueTuple(func...)
|
||||||
alias Impl = TypeTuple!(Get!i, Impl!(i+1));
|
alias Impl = TypeTuple!(Get!i, Impl!(i+1));
|
||||||
}
|
}
|
||||||
|
|
||||||
alias ParameterDefaultValueTuple = Impl!();
|
alias ParameterDefaults = Impl!();
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
int foo(int num, string name = "hello", int[] = [1,2,3]);
|
int foo(int num, string name = "hello", int[] = [1,2,3]);
|
||||||
static assert(is(ParameterDefaultValueTuple!foo[0] == void));
|
static assert(is(ParameterDefaults!foo[0] == void));
|
||||||
static assert( ParameterDefaultValueTuple!foo[1] == "hello");
|
static assert( ParameterDefaults!foo[1] == "hello");
|
||||||
static assert( ParameterDefaultValueTuple!foo[2] == [1,2,3]);
|
static assert( ParameterDefaults!foo[2] == [1,2,3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Alternate name for $(LREF ParameterDefaults), kept for legacy compatibility.
|
||||||
|
*/
|
||||||
|
alias ParameterDefaultValueTuple = ParameterDefaults;
|
||||||
|
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
alias PDVT = ParameterDefaultValueTuple;
|
alias PDVT = ParameterDefaultValueTuple;
|
||||||
|
@ -1931,8 +1941,8 @@ template SetFunctionAttributes(T, string linkage, uint attrs)
|
||||||
|
|
||||||
result ~= "(";
|
result ~= "(";
|
||||||
|
|
||||||
static if (ParameterTypeTuple!T.length > 0)
|
static if (Parameters!T.length > 0)
|
||||||
result ~= "ParameterTypeTuple!T";
|
result ~= "Parameters!T";
|
||||||
|
|
||||||
enum varStyle = variadicFunctionStyle!T;
|
enum varStyle = variadicFunctionStyle!T;
|
||||||
static if (varStyle == Variadic.c)
|
static if (varStyle == Variadic.c)
|
||||||
|
@ -2088,7 +2098,7 @@ template hasNested(T)
|
||||||
enum hasNested = hasNested!(typeof(T.init[0]));
|
enum hasNested = hasNested!(typeof(T.init[0]));
|
||||||
else static if(is(T == class) || is(T == struct) || is(T == union))
|
else static if(is(T == class) || is(T == struct) || is(T == union))
|
||||||
enum hasNested = isNested!T ||
|
enum hasNested = isNested!T ||
|
||||||
anySatisfy!(.hasNested, FieldTypeTuple!T);
|
anySatisfy!(.hasNested, Fields!T);
|
||||||
else
|
else
|
||||||
enum hasNested = false;
|
enum hasNested = false;
|
||||||
}
|
}
|
||||||
|
@ -2158,30 +2168,35 @@ unittest
|
||||||
|
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* Get as a typetuple the types of the fields of a struct, class, or union.
|
* Get as a tuple 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 a tuple
|
||||||
* with one element $(D T).
|
* with one element $(D T).
|
||||||
*/
|
*/
|
||||||
template FieldTypeTuple(T)
|
template Fields(T)
|
||||||
{
|
{
|
||||||
static if (is(T == struct) || is(T == union))
|
static if (is(T == struct) || is(T == union))
|
||||||
alias FieldTypeTuple = typeof(T.tupleof[0 .. $ - isNested!T]);
|
alias Fields = typeof(T.tupleof[0 .. $ - isNested!T]);
|
||||||
else static if (is(T == class))
|
else static if (is(T == class))
|
||||||
alias FieldTypeTuple = typeof(T.tupleof);
|
alias Fields = typeof(T.tupleof);
|
||||||
else
|
else
|
||||||
alias FieldTypeTuple = TypeTuple!T;
|
alias Fields = TypeTuple!T;
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
struct S { int x; float y; }
|
struct S { int x; float y; }
|
||||||
static assert(is(FieldTypeTuple!S == TypeTuple!(int, float)));
|
static assert(is(Fields!S == TypeTuple!(int, float)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Alternate name for $(LREF FieldTypeTuple), kept for legacy compatibility.
|
||||||
|
*/
|
||||||
|
alias FieldTypeTuple = Fields;
|
||||||
|
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
static assert(is(FieldTypeTuple!int == TypeTuple!int));
|
static assert(is(FieldTypeTuple!int == TypeTuple!int));
|
||||||
|
@ -4380,8 +4395,8 @@ template isCovariantWith(F, G)
|
||||||
template checkParameters()
|
template checkParameters()
|
||||||
{
|
{
|
||||||
alias STC = ParameterStorageClass;
|
alias STC = ParameterStorageClass;
|
||||||
alias UprParams = ParameterTypeTuple!Upr;
|
alias UprParams = Parameters!Upr;
|
||||||
alias LwrParams = ParameterTypeTuple!Lwr;
|
alias LwrParams = Parameters!Lwr;
|
||||||
alias UprPSTCs = ParameterStorageClassTuple!Upr;
|
alias UprPSTCs = ParameterStorageClassTuple!Upr;
|
||||||
alias LwrPSTCs = ParameterStorageClassTuple!Lwr;
|
alias LwrPSTCs = ParameterStorageClassTuple!Lwr;
|
||||||
//
|
//
|
||||||
|
@ -5510,27 +5525,33 @@ unittest
|
||||||
*
|
*
|
||||||
* See_Also: $(LREF isTypeTuple).
|
* See_Also: $(LREF isTypeTuple).
|
||||||
*/
|
*/
|
||||||
template isExpressionTuple(T ...)
|
template isExpressions(T ...)
|
||||||
{
|
{
|
||||||
static if (T.length >= 2)
|
static if (T.length >= 2)
|
||||||
enum bool isExpressionTuple =
|
enum bool isExpressions =
|
||||||
isExpressionTuple!(T[0 .. $/2]) &&
|
isExpressions!(T[0 .. $/2]) &&
|
||||||
isExpressionTuple!(T[$/2 .. $]);
|
isExpressions!(T[$/2 .. $]);
|
||||||
else static if (T.length == 1)
|
else static if (T.length == 1)
|
||||||
enum bool isExpressionTuple =
|
enum bool isExpressions =
|
||||||
!is(T[0]) && __traits(compiles, { auto ex = T[0]; });
|
!is(T[0]) && __traits(compiles, { auto ex = T[0]; });
|
||||||
else
|
else
|
||||||
enum bool isExpressionTuple = true; // default
|
enum bool isExpressions = true; // default
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
static assert(isExpressionTuple!(1, 2.0, "a"));
|
static assert(isExpressions!(1, 2.0, "a"));
|
||||||
static assert(!isExpressionTuple!(int, double, string));
|
static assert(!isExpressions!(int, double, string));
|
||||||
static assert(!isExpressionTuple!(int, 2.0, "a"));
|
static assert(!isExpressions!(int, 2.0, "a"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Alternate name for $(LREF isExpressions), kept for legacy compatibility.
|
||||||
|
*/
|
||||||
|
|
||||||
|
alias isExpressionTuple = isExpressions;
|
||||||
|
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
void foo();
|
void foo();
|
||||||
|
@ -5555,7 +5576,7 @@ unittest
|
||||||
* Check whether the tuple $(D T) is a type tuple.
|
* Check whether the tuple $(D T) is a type tuple.
|
||||||
* A type tuple only contains types.
|
* A type tuple only contains types.
|
||||||
*
|
*
|
||||||
* See_Also: $(LREF isExpressionTuple).
|
* See_Also: $(LREF isExpressions).
|
||||||
*/
|
*/
|
||||||
template isTypeTuple(T...)
|
template isTypeTuple(T...)
|
||||||
{
|
{
|
||||||
|
|
|
@ -20,33 +20,29 @@
|
||||||
* Macros:
|
* Macros:
|
||||||
* WIKI = Phobos/StdTypeTuple
|
* WIKI = Phobos/StdTypeTuple
|
||||||
*
|
*
|
||||||
* Copyright: Copyright Digital Mars 2005 - 2009.
|
* Copyright: Copyright Digital Mars 2005 - 2015.
|
||||||
* License: $(WEB www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
|
* License: $(WEB www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
|
||||||
* Authors:
|
* Authors:
|
||||||
* $(WEB digitalmars.com, Walter Bright),
|
* $(WEB digitalmars.com, Walter Bright),
|
||||||
* $(WEB klickverbot.at, David Nadlinger)
|
* $(WEB klickverbot.at, David Nadlinger)
|
||||||
* Source: $(PHOBOSSRC std/_typetuple.d)
|
* Source: $(PHOBOSSRC std/_typetuple.d)
|
||||||
*/
|
*/
|
||||||
/* Copyright Digital Mars 2005 - 2009.
|
|
||||||
* Distributed under the Boost Software License, Version 1.0.
|
|
||||||
* (See accompanying file LICENSE_1_0.txt or copy at
|
|
||||||
* http://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
*/
|
|
||||||
module std.typetuple;
|
module std.typetuple;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a typetuple out of a sequence of zero or more types.
|
* Creates a tuple out of a sequence of zero or more template arguments.
|
||||||
*/
|
*/
|
||||||
template TypeTuple(TList...)
|
template Arguments(TList...)
|
||||||
{
|
{
|
||||||
alias TypeTuple = TList;
|
alias Arguments = TList;
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
import std.typetuple;
|
import std.typetuple;
|
||||||
alias TL = TypeTuple!(int, double);
|
alias TL = Arguments!(int, double);
|
||||||
|
|
||||||
int foo(TL td) // same as int foo(int, double);
|
int foo(TL td) // same as int foo(int, double);
|
||||||
{
|
{
|
||||||
|
@ -57,12 +53,17 @@ unittest
|
||||||
///
|
///
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
alias TL = TypeTuple!(int, double);
|
alias TL = Arguments!(int, double);
|
||||||
|
|
||||||
alias Types = TypeTuple!(TL, char);
|
alias Types = Arguments!(TL, char);
|
||||||
static assert(is(Types == TypeTuple!(int, double, char)));
|
static assert(is(Types == Arguments!(int, double, char)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Alternate name for $(LREF Arguments) for legacy compatibility.
|
||||||
|
*/
|
||||||
|
alias TypeTuple = Arguments;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the index of the first occurrence of type T in the
|
* Returns the index of the first occurrence of type T in the
|
||||||
* sequence of zero or more types TList.
|
* sequence of zero or more types TList.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue