On 2015-07-16 18:49, badlink wrote:
The method with the variadic function works, but I would have to use
only one parameter because this doesn't work:
fun(const(char[])[] a, const(char[])[] b ...)
and is a bit ugly in my use case ...
I don't think I really understand how you want to use/call
On Friday, 17 July 2015 at 12:58:58 UTC, Jacob Carlborg wrote:
I don't think I really understand how you want to use/call the
function. Could you give an example with all the different
types you want to call the function?
My fault, I didn't test the variadic function enough and jumped
to
On 2015-07-17 19:25, badlink wrote:
My fault, I didn't test the variadic function enough and jumped to
conclusion.
It actually works well http://pastebin.com/R4EHuBLh
Cool :)
Sometimes D developers think templates will be needed to solve everything.
--
/Jacob Carlborg
On 2015-07-15 23:57, badlink wrote:
Hello, I can't figure how to write a template function that accept
either strings or array of strings.
This is my current code:
bool hasItemParent(T)(const(char)[] itemId, const(T)[] parentId)
if (is(typeof(T) == char) || (isArray!T is(typeof(T[]) == char
Thank you for all answers.
Removing typeof do resolve the problem when the second parameter
is a simple string.
However when passing an array of string the error still occur:
Error: template cache.MetadataCache.hasItemParent cannot deduce
function from argument types !()(string, string[]).
On Wednesday, 15 July 2015 at 21:57:50 UTC, badlink wrote:
Hello, I can't figure how to write a template function that
accept either strings or array of strings.
This is my current code:
bool hasItemParent(T)(const(char)[] itemId, const(T)[] parentId)
if (is(typeof(T) == char) || (isArray!T
Also checkout inout functions:
http://dlang.org/function.html#inout-functions
After a thorough reading of the documentation I found an even
simpler solution:
bool hasItemParent(T)(const(char)[] itemId, T parentId)
if (is(T : const(char)[]) || is(T : const(char[])[]))
{ ... }
Now it accepts all these: char[], const(char)[],
immutable(char)[], char[][], const(char)[][]
On Thursday, 16 July 2015 at 18:41:47 UTC, Gary Willoughby wrote:
bool hasItemParent(A, B)(A itemId, B parentId)
if (isSomeString!(A) (isSomeString!(B) || isArray!(B)
isSomeString!(ElementType!(B
Thank you ! I completely missed isSomeString.
I think the definition can be safely
On Wednesday, 15 July 2015 at 21:57:50 UTC, badlink wrote:
Hello, I can't figure how to write a template function that
accept either strings or array of strings.
This is my current code:
bool hasItemParent(T)(const(char)[] itemId, const(T)[] parentId)
if (is(typeof(T) == char) || (isArray!T
On Wednesday, 15 July 2015 at 21:57:50 UTC, badlink wrote:
Hello, I can't figure how to write a template function that
accept either strings or array of strings.
This is my current code:
bool hasItemParent(T)(const(char)[] itemId, const(T)[] parentId)
if (is(typeof(T) == char) || (isArray!T
Hello, I can't figure how to write a template function that
accept either strings or array of strings.
This is my current code:
bool hasItemParent(T)(const(char)[] itemId, const(T)[] parentId)
if (is(typeof(T) == char) || (isArray!T is(typeof(T[]) ==
char)))
{...}
I used const(T)[] because
12 matches
Mail list logo