Re: Patterns for functions in template parameters

2014-10-24 Thread via Digitalmars-d-learn
On Friday, 24 October 2014 at 16:12:48 UTC, ketmar via Digitalmars-d-learn wrote: On Fri, 24 Oct 2014 16:00:41 + via Digitalmars-d-learn wrote: On Friday, 24 October 2014 at 14:06:08 UTC, ketmar via Digitalmars-d-learn wrote: > On Thu, 23 Oct 2014 18:28:04 + > Max Samukha via Digita

Re: Patterns for functions in template parameters

2014-10-24 Thread Max Samukha via Digitalmars-d-learn
On Friday, 24 October 2014 at 17:08:00 UTC, Max Samukha wrote: Apparently, D doesn't allow type variables in value parameters at all. Nor does it allow passing delegates to value parameters, only alias parameters.

Re: Patterns for functions in template parameters

2014-10-24 Thread Max Samukha via Digitalmars-d-learn
On Friday, 24 October 2014 at 14:13:10 UTC, ketmar via Digitalmars-d-learn wrote: sorry if this is not what you mean, template magic sometimes scares me and i'm loosing my mind. ;-) What I meant was your example with the delegate parameter moved to the template list: template Foo(T delega

Re: Patterns for functions in template parameters

2014-10-24 Thread ketmar via Digitalmars-d-learn
On Fri, 24 Oct 2014 16:00:41 + via Digitalmars-d-learn wrote: > On Friday, 24 October 2014 at 14:06:08 UTC, ketmar via > Digitalmars-d-learn wrote: > > On Thu, 23 Oct 2014 18:28:04 + > > Max Samukha via Digitalmars-d-learn > > > > wrote: > > > > um-hm... maybe this: > > > > void Foo(

Re: Patterns for functions in template parameters

2014-10-24 Thread via Digitalmars-d-learn
On Friday, 24 October 2014 at 14:06:08 UTC, ketmar via Digitalmars-d-learn wrote: On Thu, 23 Oct 2014 18:28:04 + Max Samukha via Digitalmars-d-learn wrote: um-hm... maybe this: void Foo(T, U) (T delegate (U) a) { // here T is bool, U is int for the following sample import std.s

Re: Patterns for functions in template parameters

2014-10-24 Thread ketmar via Digitalmars-d-learn
On Fri, 24 Oct 2014 17:05:57 +0300 ketmar via Digitalmars-d-learn wrote: > On Thu, 23 Oct 2014 18:28:04 + > Max Samukha via Digitalmars-d-learn > wrote: > > um-hm... maybe this: > > void Foo(T, U) (T delegate (U) a) { > // here T is bool, U is int for the following sample > impor

Re: Patterns for functions in template parameters

2014-10-24 Thread ketmar via Digitalmars-d-learn
On Thu, 23 Oct 2014 18:28:04 + Max Samukha via Digitalmars-d-learn wrote: um-hm... maybe this: void Foo(T, U) (T delegate (U) a) { // here T is bool, U is int for the following sample import std.stdio; writeln(a(3)); } Foo((int x) => x%2 == 0); signature.asc Description:

Re: Patterns for functions in template parameters

2014-10-24 Thread Max Samukha via Digitalmars-d-learn
On Friday, 24 October 2014 at 08:53:05 UTC, Kagamin wrote: maybe template Foo(T a, T: T[U], U) No luck. Error: undefined identifier T

Re: Patterns for functions in template parameters

2014-10-24 Thread Kagamin via Digitalmars-d-learn
maybe template Foo(T a, T: T[U], U)

Re: Patterns for functions in template parameters

2014-10-23 Thread Max Samukha via Digitalmars-d-learn
On Thursday, 23 October 2014 at 11:25:01 UTC, Kagamin wrote: Maybe, argument deduction? template Foo(T: T[U], U) { ... } Foo!(int[long]) // instantiates Foo with T set to int, U set to long Yes, but for a value template parameter. template Foo(int[long] a); { } Foo!([1: 2]); // ok, thi

Re: Patterns for functions in template parameters

2014-10-23 Thread Kagamin via Digitalmars-d-learn
Maybe, argument deduction? template Foo(T: T[U], U) { ... } Foo!(int[long]) // instantiates Foo with T set to int, U set to long

Patterns for functions in template parameters

2014-10-23 Thread Max Samukha via Digitalmars-d-learn
If I remember correctly, at some point a syntax was introduced for pattern-matching functions passed to templates. Something like: template Foo(B(A) foo, A, B) { } alias f = Foo!((int x) => x % 2 == 0); That would instantiate Foo with B == bool, A == int and foo bound to the lambda. The co