mirror of
https://github.com/dlang/phobos.git
synced 2025-05-01 15:40:36 +03:00
Unnamed parameters for ParameterIdentifierTuple, fix name conflict for ParameterDefaultValueTuple
This commit is contained in:
parent
d4d60e201d
commit
ee683ae79f
1 changed files with 11 additions and 5 deletions
16
std/traits.d
16
std/traits.d
|
@ -1055,7 +1055,9 @@ template ParameterIdentifierTuple(func...)
|
||||||
{
|
{
|
||||||
template Get(size_t i)
|
template Get(size_t i)
|
||||||
{
|
{
|
||||||
static if (!isFunctionPointer!func && !isDelegate!func)
|
static if (!isFunctionPointer!func && !isDelegate!func
|
||||||
|
// Unnamed parameters yield CT error.
|
||||||
|
&& is(typeof(__traits(identifier, PT[i..i+1]))x))
|
||||||
{
|
{
|
||||||
enum Get = __traits(identifier, PT[i..i+1]);
|
enum Get = __traits(identifier, PT[i..i+1]);
|
||||||
}
|
}
|
||||||
|
@ -1089,8 +1091,8 @@ template ParameterIdentifierTuple(func...)
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
import std.traits;
|
import std.traits;
|
||||||
int foo(int num, string name);
|
int foo(int num, string name, int);
|
||||||
static assert([ParameterIdentifierTuple!foo] == ["num", "name"]);
|
static assert([ParameterIdentifierTuple!foo] == ["num", "name", ""]);
|
||||||
}
|
}
|
||||||
|
|
||||||
unittest
|
unittest
|
||||||
|
@ -1141,7 +1143,11 @@ template ParameterDefaultValueTuple(func...)
|
||||||
{
|
{
|
||||||
template Get(size_t i)
|
template Get(size_t i)
|
||||||
{
|
{
|
||||||
enum get = (PT[i..i+1] args) => args[0];
|
enum ParamName = ParameterIdentifierTuple!(func[0])[i];
|
||||||
|
static if (ParamName.length)
|
||||||
|
enum get = (PT[i..i+1]) => mixin(ParamName);
|
||||||
|
else // Unnamed parameter
|
||||||
|
enum get = (PT[i..i+1] __args) => __args[0];
|
||||||
static if (is(typeof(get())))
|
static if (is(typeof(get())))
|
||||||
enum Get = get();
|
enum Get = get();
|
||||||
else
|
else
|
||||||
|
@ -1180,7 +1186,7 @@ template ParameterDefaultValueTuple(func...)
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
import std.traits;
|
import std.traits;
|
||||||
int foo(int num, string name = "hello", int[] arr = [1,2,3]);
|
int foo(int num, string name = "hello", int[] = [1,2,3]);
|
||||||
static assert(is(ParameterDefaultValueTuple!foo[0] == void));
|
static assert(is(ParameterDefaultValueTuple!foo[0] == void));
|
||||||
static assert( ParameterDefaultValueTuple!foo[1] == "hello");
|
static assert( ParameterDefaultValueTuple!foo[1] == "hello");
|
||||||
static assert( ParameterDefaultValueTuple!foo[2] == [1,2,3]);
|
static assert( ParameterDefaultValueTuple!foo[2] == [1,2,3]);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue