unqualified types in tuple

2012-11-21 Thread Dan
If I have a type tuple TL, which happens to be: alias TypeTuple!(const(int), immutable(double), string) TL; How can I convert it into a tuple of (int, double, string)? Effectively I need a way to get a new UnqualTL where each type in the list is itself unqualified. I need to do this without k

Re: template library like Jinja

2012-11-21 Thread Tobias Pankrath
On 21.11.2012 21:56, Masahiro Nakagawa wrote: On Tuesday, 20 November 2012 at 11:38:46 UTC, Tobias Pankrath wrote: Is there any template library like Jinja? (jinja.pocoo.org). I'm pretty sure we can do even better by leveraging CTFE and a precompiler, but speed is no concern for me. I'm not f

Re: template library like Jinja

2012-11-21 Thread Masahiro Nakagawa
On Tuesday, 20 November 2012 at 11:38:46 UTC, Tobias Pankrath wrote: Is there any template library like Jinja? (jinja.pocoo.org). I'm pretty sure we can do even better by leveraging CTFE and a precompiler, but speed is no concern for me. I'm not familiar with Jinja. So I may not meet your exp

Re: runtime static arrays

2012-11-21 Thread Timon Gehr
On 11/20/2012 11:56 PM, Jonathan M Davis wrote: ... clearly, as if with static arrays, you'd have to be careful with slices being passed around, since they're not owned by the GC. And I'm not sure what would happen if you were foolish enough to try and append to them. ... It works as expected.

Re: template ref parameter

2012-11-21 Thread Jack Applegame
Ugly C++ like template and mixin magic solution: struct r(T){ alias T type;} template str(alias A) if(is(A == r!(A.type))) { const char[] str = "ref " ~ A.type.stringof; } template str(T) { const char[] str = T.stringof; } template str(T, A...) { const char[] str = str!T ~ ", " ~ str!A; } stru

Re: making COW and ownership

2012-11-21 Thread Era Scarecrow
On Wednesday, 21 November 2012 at 10:15:52 UTC, Timon Gehr wrote: This also duplicates the data if you move the struct in memory and then mutate. Probably you just need to have a boolean owner flag and set it to false on postblit. Hadn't thought of a move being involved.. I was trying to use

Re: making COW and ownership

2012-11-21 Thread Dan
On Wednesday, 21 November 2012 at 04:23:56 UTC, Era Scarecrow wrote: Here's a quick thrown together example of what I'm talking about. I think I see where you are going. After the copy creation of new_ca you have two objects referencing exactly the same data. It doesn't show it, but the bene

Re: template ref parameter

2012-11-21 Thread Andrej Mitrovic
On 11/21/12, Jack Applegame wrote: > This problem appears also in std.signals. > There is no possibility to use functions with ref parameters as > signal handler. > > import std.signals; > > class Foo { >mixin Signal!(int); > } > class Bar { >void handler(ref int a) {} > } > > void main()

Re: template ref parameter

2012-11-21 Thread Jack Applegame
alias void function(ref int) funcType; void foo(ref int a) { a--; } struct functor(A...) { A[0] func; } void main() { functor!funcType f; f.func = &foo; } I think the best way is using @property. alias void function(ref int) funcType; void foo(ref int a) { a--; } struct functor(A...) {

Re: template ref parameter

2012-11-21 Thread Jack Applegame
This problem appears also in std.signals. There is no possibility to use functions with ref parameters as signal handler. import std.signals; class Foo { mixin Signal!(int); } class Bar { void handler(ref int a) {} } void main() { Foo foo = new Foo; Bar bar = new Bar; foo.connect(&b

Re: template ref parameter

2012-11-21 Thread Regan Heath
On Wed, 21 Nov 2012 12:32:24 -, Regan Heath wrote: On Wed, 21 Nov 2012 12:30:08 -, Regan Heath wrote: On Wed, 21 Nov 2012 12:02:45 -, Jack Applegame wrote: void foo(ref int a) { a--; } struct functor(A...) { void function(A) functor; } functor!int f;// functor!(ref

Re: template ref parameter

2012-11-21 Thread Jack Applegame
storage classes on function parameters affect the type of the function, but they do not affect the type of the parameter. If a function has a parameter named foo, then typeof(foo) is going to be the same whether ref is on it or not. - Jonathan M Davis Ok. But how to pass storage class to tem

Re: template ref parameter

2012-11-21 Thread Regan Heath
On Wed, 21 Nov 2012 12:30:08 -, Regan Heath wrote: On Wed, 21 Nov 2012 12:02:45 -, Jack Applegame wrote: void foo(ref int a) { a--; } struct functor(A...) { void function(A) functor; } functor!int f;// functor!(ref int) - wrong f.functor = &foo; // Error: cannot implicitly

Re: template ref parameter

2012-11-21 Thread Regan Heath
On Wed, 21 Nov 2012 12:02:45 -, Jack Applegame wrote: void foo(ref int a) { a--; } struct functor(A...) { void function(A) functor; } functor!int f;// functor!(ref int) - wrong f.functor = &foo; // Error: cannot implicitly convert expression (& foo) of type void function(ref int a

Re: template ref parameter

2012-11-21 Thread Jonathan M Davis
On Wednesday, November 21, 2012 13:09:05 Jack Applegame wrote: > On Wednesday, 21 November 2012 at 12:05:23 UTC, bearophile wrote: > > In one case the function expects a pointer and in one case it > > expects a int value. The assembly code of the two functions is > > different and does different th

Re: template ref parameter

2012-11-21 Thread Jack Applegame
On Wednesday, 21 November 2012 at 12:05:23 UTC, bearophile wrote: In one case the function expects a pointer and in one case it expects a int value. The assembly code of the two functions is different and does different things. Of course. And it is mean that ref indeed is a part of type.

Re: template ref parameter

2012-11-21 Thread bearophile
Jack Applegame: A brony? :-) But sometimes ref becomes a part of type. For example "void delegate(ref int)" and "void delegate(int)" are different types. Is it possible to cast from one to another safely? For example: void foo(ref int); void function(int) fp; fp = cast(typeof(fp)) foo; ///

Re: template ref parameter

2012-11-21 Thread Jonathan M Davis
On Wednesday, November 21, 2012 12:57:57 Jack Applegame wrote: > But sometimes ref becomes a part of type. For example "void > delegate(ref int)" and "void delegate(int)" are different types. > Is it possible to cast from one to another safely? For example: That's because ref is being used on a fu

Re: template ref parameter

2012-11-21 Thread Jack Applegame
How to implement functor-like objects if ref is storage class? void foo(ref int a) { a--; } struct functor(A...) { void function(A) functor; } functor!int f;// functor!(ref int) - wrong f.functor = &foo; // Error: cannot implicitly convert expression (& foo) of type void function(ref int a

Re: template ref parameter

2012-11-21 Thread Jack Applegame
But sometimes ref becomes a part of type. For example "void delegate(ref int)" and "void delegate(int)" are different types. Is it possible to cast from one to another safely? For example: void foo(ref int); void function(int) fp; fp = cast(typeof(fp)) foo; /// is it safe???

Re: template ref parameter

2012-11-21 Thread Jonathan M Davis
On Wednesday, November 21, 2012 11:55:53 Jack Applegame wrote: > Why this could not compile? > > struct Foo(T) {} > Foo!(ref int) foo; > > Output: > > Error: expression expected, not 'ref' > Error: found 'int' when expecting ')' following template argument > list > Error: no identifier for decla

template ref parameter

2012-11-21 Thread Jack Applegame
Why this could not compile? struct Foo(T) {} Foo!(ref int) foo; Output: Error: expression expected, not 'ref' Error: found 'int' when expecting ')' following template argument list Error: no identifier for declarator Foo!(0) Error: semicolon expected, not ')' Error: found ')' instead of state

Re: making COW and ownership

2012-11-21 Thread Timon Gehr
On 11/21/2012 05:23 AM, Era Scarecrow wrote: I was thinking briefly and glancing over documentation regarding cluts and non-cluts (Reference vs value types), and considering my BitArray implementation. I was having a problem trying to solve how to avoid duplicating it unless it actually was nee