Re: Clash When Using Function as Template Value-Parameters?

2018-05-30 Thread Vijay Nayar via Digitalmars-d
On Tuesday, 29 May 2018 at 19:17:37 UTC, Vijay Nayar wrote: On Tuesday, 29 May 2018 at 12:58:20 UTC, Yuxuan Shui wrote: [...] I tried this again, this time completely ignoring lambdas and completely specifying the desired type like so: [...] Issue created:

Re: Clash When Using Function as Template Value-Parameters?

2018-05-29 Thread Vijay Nayar via Digitalmars-d
On Tuesday, 29 May 2018 at 12:58:20 UTC, Yuxuan Shui wrote: I believe that is the case. Normally that will be fine, because you can't modify them. Type-deduced lambda is a very special case, as in their parameter types are deduced on first use, so in a sense, they are "modified" by the first

Re: Clash When Using Function as Template Value-Parameters?

2018-05-29 Thread Yuxuan Shui via Digitalmars-d
On Tuesday, 29 May 2018 at 12:37:04 UTC, Vijay Nayar wrote: On Tuesday, 29 May 2018 at 11:36:11 UTC, Yuxuan Shui wrote: No, wait a second. (a)=>a is in default argument list, so it is in the global scope. And it was instantiated when you instantiate BTree with char. Could you explain that

Re: Clash When Using Function as Template Value-Parameters?

2018-05-29 Thread Vijay Nayar via Digitalmars-d
On Tuesday, 29 May 2018 at 11:36:11 UTC, Yuxuan Shui wrote: No, wait a second. (a)=>a is in default argument list, so it is in the global scope. And it was instantiated when you instantiate BTree with char. Could you explain that part a bit for me? Yes, (a) => a is a default value, but

Re: Clash When Using Function as Template Value-Parameters?

2018-05-29 Thread Yuxuan Shui via Digitalmars-d
On Tuesday, 29 May 2018 at 11:34:03 UTC, Yuxuan Shui wrote: On Saturday, 26 May 2018 at 11:56:30 UTC, Vijay Nayar wrote: I've been experimenting with code that uses std.functional : binaryFun and unaryFun, but I have found that using these methods makes it impossible to add function attributes

Re: Clash When Using Function as Template Value-Parameters?

2018-05-29 Thread Yuxuan Shui via Digitalmars-d
On Saturday, 26 May 2018 at 11:56:30 UTC, Vijay Nayar wrote: I've been experimenting with code that uses std.functional : binaryFun and unaryFun, but I have found that using these methods makes it impossible to add function attributes like @safe, @nogc, pure, and nothrow, because no guarantee

Re: Clash When Using Function as Template Value-Parameters?

2018-05-28 Thread Vijay Nayar via Digitalmars-d
On Sunday, 27 May 2018 at 20:38:25 UTC, Daniel Kozak wrote: I would rewrite it to something like this: template BTree(ValueT, KeyT = ValueT,alias KeyF = unaryFun!"cast(const)a") { class BTree { This is roughly what I originally had, but it creates a number of problems that I wanted

Re: Clash When Using Function as Template Value-Parameters?

2018-05-27 Thread Daniel Kozak via Digitalmars-d
I would rewrite it to something like this: import std.stdio; import std.functional; template BTree(ValueT, KeyT = ValueT,alias KeyF = unaryFun!"cast(const)a") { class BTree { auto getKey(ValueT val) { return KeyF(val); } } } void main() { auto btree1

Re: Clash When Using Function as Template Value-Parameters?

2018-05-27 Thread Vijay Nayar via Digitalmars-d
On Saturday, 26 May 2018 at 11:56:30 UTC, Vijay Nayar wrote: The error is: ``` onlineapp.d(8): Error: function literal `__lambda6(char a)` is not callable using argument types `(int)` onlineapp.d(8):cannot pass argument `val` of type `int` to parameter `char a` onlineapp.d(15): Error:

Clash When Using Function as Template Value-Parameters?

2018-05-26 Thread Vijay Nayar via Digitalmars-d
I've been experimenting with code that uses std.functional : binaryFun and unaryFun, but I have found that using these methods makes it impossible to add function attributes like @safe, @nogc, pure, and nothrow, because no guarantee can be made about the functions created via a stream. For