Generic method that takes in either delegate or function

2011-01-12 Thread %u
Hi, Is there any way to specify a parameter as something that can be called with parameter types A, B, C and that returns a value of type D, without caring whether it's a delegate, a function, or an object that overloads opCall? (This might require the use of templates, but I still can't figure

Re: Generic method that takes in either delegate or function

2011-01-12 Thread Jonathan M Davis
On Wednesday 12 January 2011 00:21:54 %u wrote: Hi, Is there any way to specify a parameter as something that can be called with parameter types A, B, C and that returns a value of type D, without caring whether it's a delegate, a function, or an object that overloads opCall? (This might

Re: Generic method that takes in either delegate or function

2011-01-12 Thread Lutger Blijdestijn
%u wrote: Hi, Is there any way to specify a parameter as something that can be called with parameter types A, B, C and that returns a value of type D, without caring whether it's a delegate, a function, or an object that overloads opCall? (This might require the use of templates, but I

Struct constructors callable twice?

2011-01-12 Thread Guilherme Vieira
I've found this behavior while toying with opCall() in a struct: import std.stdio; struct Struct { this(int value) { writeln(Struct.this(, value, )); } ~this() { writeln(Struct.~this()); } } void main() { Struct s = Struct(1); // prints `Struct.this(1)` s(2); //

toDelegate() for D1

2011-01-12 Thread %u
is it available?

Re: Struct constructors callable twice?

2011-01-12 Thread bearophile
See also: http://d.puremagic.com/issues/show_bug.cgi?id=4053 Bye, bearophile

Re: Struct constructors callable twice?

2011-01-12 Thread Guilherme Vieira
Yes, it was meddling with that bug that I cooked this one. I think Adam got it right: There should be no problem between an instance opCall and a constructor. In your case, it seems, a static opCall was clashing with the constructor. But it turns out a non-static opCall clashes with a constructor

Re: std.encoding Usage

2011-01-12 Thread Mandeep Singh Brar
Putting here that the following worked for me. string str ubyte[] buffer; foreach(ch;str) { ubyte[4] buf; int len = encodingScheme.encode(ch, buf); buffer~=buf[0..len]; } ubyte[] encodedBuffer; string decodedString; while(encodedBuffer.length0) {

Parse Time using std.date

2011-01-12 Thread Mandeep Singh Brar
Hi, Is there a way to parse a Time string like 15:45 to a Date structure. Parse method in std.date returns it as invalid. As a hack it works by prepending it with something like 1-1-1970. But is there a cleaner way to it. Thanks Mandeep

Re: Using template typetuples?

2011-01-12 Thread Simen kjaeraas
Sean Eskapp eatingstap...@gmail.com wrote: The language documentation covers some basic uses of TypeTuples in templates, but nothing about using them with classes. I would like a template class, which essentially wraps a function, which has template parameters for return value and template

Re: interface function overloading

2011-01-12 Thread Stanislav Blinov
09.01.2011 15:22, %u пишет: == Quote from bearophile (bearophileh...@lycos.com)'s article %u: func(cast(I2)(new C())); That code smells a bit (http://en.wikipedia.org/wiki/Code_smell ). Bye, bearophile Extract the construction and you get: module main; interface I1{} interface I2 :

Re: toDelegate() for D1

2011-01-12 Thread %u
I only need something to make a void deleg() from a void func().

Re: interface function overloading

2011-01-12 Thread %u
== Quote from Stanislav Blinov (bli...@loniir.ru)'s article In C++ I sometimes have similar problems, especially with multiple inheritance. Though, as Jonathan mentioned, those problems are even more annoying because of hijacking: you don't always immediately notice them. Long ago I've decided

Re: toDelegate() for D1

2011-01-12 Thread Simen kjaeraas
%u e...@ee.com wrote: I only need something to make a void deleg() from a void func(). This works for me: ReturnType!( F ) delegate( ParameterTypeTuple!( F ) ) toDelegate( F )( F fn ) { return ( ParameterTypeTuple!( F ) args ){ return fn( args ); }; } -- Simen

Re: Assertion failure: '!cases' on line 2620 in file 'statement.c'

2011-01-12 Thread %u
Should I post it as a bug, even though I have no code to accompany it? I have no clue as to where to start my directed search for a minimal case.

Re: Assertion failure: '!cases' on line 2620 in file 'statement.c'

2011-01-12 Thread Simen kjaeraas
%u e...@ee.com wrote: Should I post it as a bug, even though I have no code to accompany it? I have no clue as to where to start my directed search for a minimal case. Please do post it, yes. As for searching, if you are willing to share the code , others may be willing to do the search.

Re: toDelegate() for D1

2011-01-12 Thread %u
== Quote from Simen kjaeraas (simen.kja...@gmail.com)'s article %u e...@ee.com wrote: I only need something to make a void deleg() from a void func(). This works for me: ReturnType!( F ) delegate( ParameterTypeTuple!( F ) ) toDelegate( F )( F fn ) { return ( ParameterTypeTuple!( F )

Re: Parse Time using std.date

2011-01-12 Thread Jesse Phillips
Mandeep Singh Brar Wrote: Hi, Is there a way to parse a Time string like 15:45 to a Date structure. Parse method in std.date returns it as invalid. As a hack it works by prepending it with something like 1-1-1970. But is there a cleaner way to it. Thanks Mandeep No. Though std.date

Re: Parse Time using std.date

2011-01-12 Thread Jonathan M Davis
On Wednesday, January 12, 2011 07:29:39 Mandeep Singh Brar wrote: Hi, Is there a way to parse a Time string like 15:45 to a Date structure. Parse method in std.date returns it as invalid. As a hack it works by prepending it with something like 1-1-1970. But is there a cleaner way to it.

Re: Assertion failure: '!cases' on line 2620 in file 'statement.c'

2011-01-12 Thread Don
%u wrote: Should I post it as a bug, even though I have no code to accompany it? I have no clue as to where to start my directed search for a minimal case. Can you post the entire source code? It's important that it be reproducible. It doesn't need to be minimal - someone else can reduce it.

Re: Assertion failure: '!cases' on line 2620 in file 'statement.c'

2011-01-12 Thread %u
== Quote from Don (nos...@nospam.com)'s article %u wrote: Should I post it as a bug, even though I have no code to accompany it? I have no clue as to where to start my directed search for a minimal case. Can you post the entire source code? It's important that it be reproducible. It doesn't

Re: Using template typetuples?

2011-01-12 Thread Sean Eskapp
That looks like it.. only, it's not working: void main() { TypeTuple!(int, int) foo; foo[0] = 1; foo[1] = 2; double MakeStuff(in int bar) { return cast(double)bar; } auto foobar = staticMap!(MakeStuff)(foo); } This fails

Re: Using template typetuples?

2011-01-12 Thread Sean Eskapp
Nevermind, I see my error. Thank you!

Casting between tuples

2011-01-12 Thread Sean Eskapp
I have a variable of type TypeTuple!(int, int), and I want to convert all its elements into a variable of type TypeTuple!(string, string). Is there a way to do this? Using a loop fails compilation with Error: Integer constant expression expected instead of i. I'd also like to be able to convert

Re: Casting between tuples

2011-01-12 Thread Simen kjaeraas
Sean Eskapp eatingstap...@gmail.com wrote: I have a variable of type TypeTuple!(int, int), and I want to convert all its elements into a variable of type TypeTuple!(string, string). Is there a way to do this? Using a loop fails compilation with Error: Integer constant expression expected

Re: Casting between tuples

2011-01-12 Thread Jesse Phillips
Sean Eskapp Wrote: I have a variable of type TypeTuple!(int, int), and I want to convert all its elements into a variable of type TypeTuple!(string, string). Is there a way to do this? Using a loop fails compilation with Error: Integer constant expression expected instead of i. I'd also

Re: Casting between tuples

2011-01-12 Thread Jesse Phillips
Wow, missed the part where TypeTuples can hold values. I suggest looking into using Tuple from std.typecons. What you need to remember is that you are not casting the tuple, you are casting the data in the tuple which creates a completely different tuple. It seems you are trying to use the

Re: std.container.Array/RefCounted(T) leaking memory?

2011-01-12 Thread %u
Sorry to bump this up, but is RefCounted(T) really leaking, or am I missing something? I would like to use this in my program, and I'm curious as to why no one responded, since if it's actually leaking, it would be an important issue. Thanks!

Re: std.container.Array/RefCounted(T) leaking memory?

2011-01-12 Thread Jonathan M Davis
On Wednesday, January 12, 2011 15:29:51 %u wrote: Sorry to bump this up, but is RefCounted(T) really leaking, or am I missing something? I would like to use this in my program, and I'm curious as to why no one responded, since if it's actually leaking, it would be an important issue. There