Re: Treat memory as a file with a name.

2014-02-21 Thread Vladimir Panteleev
On Saturday, 22 February 2014 at 07:26:26 UTC, Steve Teale wrote: This is probably not exactly a D question. The library librsvg expects to get an SVG file filename. I have the data of such a file in memory. If it's the same librsvg as below, then it looks like it has an API function which c

Treat memory as a file with a name.

2014-02-21 Thread Steve Teale
This is probably not exactly a D question. The library librsvg expects to get an SVG file filename. I have the data of such a file in memory. How do I dress up that memory as a file with a name so that I can pass the name to the librsvg open function. I've looked at std.mmfile, and played w

Re: Cannot implicitly convert derived type

2014-02-21 Thread Eric Suen
Generic? "Frustrated" ... > interface iGui > { > @property iButton button(ref iButton button); > } > > class WindowsGui : iGui > { > WindowsButton _button; > > @property WindowsButton button(ref WindowsButton button) > //@property iButton button(ref iButton button) > { > _button = button; > retur

Re: Container templates

2014-02-21 Thread Meta
On Thursday, 20 February 2014 at 18:55:06 UTC, Frustrated wrote: This should work. Just have to add the overrides and call the base function(e.g., "override" insert and then call x's insert). This at least gets the job done... I wonder if there is a better way? If you want a.Add() (insert() in

Re: Cannot implicitly convert derived type

2014-02-21 Thread Steven Schveighoffer
On Fri, 21 Feb 2014 17:54:06 -0500, Frustrated wrote: interface iGui { @property iButton button(ref iButton button); } class WindowsGui : iGui { WindowsButton _button; @property WindowsButton button(ref WindowsButton button) //@property iButton button(ref iButt

Re: signatures

2014-02-21 Thread voyager
thanks. works nice

Re: Cannot implicitly convert derived type

2014-02-21 Thread Frustrated
On Friday, 21 February 2014 at 23:19:19 UTC, Ali Çehreli wrote: On 02/21/2014 02:54 PM, Frustrated wrote: interface iGui { @property iButton button(ref iButton button); } class WindowsGui : iGui { WindowsButton _button; @property WindowsButton button(ref WindowsButton button) /

Re: signatures

2014-02-21 Thread Brad Anderson
On Friday, 21 February 2014 at 23:46:10 UTC, voyager wrote: is there some thing like typedef? alias int XXX; alias int YYY; void a1(XXX a, YYY b) {int c = a+b;} void a1(int a, YYY b) {int c = a+b;} gives an error: Building Debug\bgitest.exe... bgitest.obj : fatal error LNK1179: invalid or cor

signatures

2014-02-21 Thread voyager
is there some thing like typedef? alias int XXX; alias int YYY; void a1(XXX a, YYY b) {int c = a+b;} void a1(int a, YYY b) {int c = a+b;} gives an error: Building Debug\bgitest.exe... bgitest.obj : fatal error LNK1179: invalid or corrupt file: duplicate COMDAT '_D4main2a1FiiZv (void main.a1(i

Re: Cannot implicitly convert derived type

2014-02-21 Thread Ali Çehreli
On 02/21/2014 02:54 PM, Frustrated wrote: interface iGui { @property iButton button(ref iButton button); } class WindowsGui : iGui { WindowsButton _button; @property WindowsButton button(ref WindowsButton button) //@property iButton button(ref iButton button) {

Re: Optimization ???

2014-02-21 Thread rumbu
D version of to!string(uint): size_t index = 12; char[12] buffer = void; uint div = void; uint mod = void; char baseChar = 'A'; do { div = cast(uint)(mValue / 10); mod = mValue % 10 + '0'; buffer[--index] = cast(char)mod; mValue = div; } while (mValue); return cast(string)buffer[index

Cannot implicitly convert derived type

2014-02-21 Thread Frustrated
interface iGui { @property iButton button(ref iButton button); } class WindowsGui : iGui { WindowsButton _button; @property WindowsButton button(ref WindowsButton button) //@property iButton button(ref iButton button) { _button = button;

Re: Is there kind of "associative tuple" - like syntax in D?

2014-02-21 Thread Philippe Sigaud
Justin: > alias MyFoo = Foo!(opt1(23), opt2("foo")); That's also my preferred solution. I find it easy to read and it's quite typesafe (also, it allows for more complex possibilities like n-params options). Another solution could be to use an associative array literal for each option (you have to

Re: Is there kind of "associative tuple" - like syntax in D?

2014-02-21 Thread Justin Whear
On Fri, 21 Feb 2014 19:09:56 +, Uranuz wrote: >> You could do something like this: >> >> alias Foo!( >> OptionType.optType1, 100, OptionType.optType2, "example, >> ...etc... >> ) MyFoo; > > Yes. I already use this. But it makes it not semanticaly obvious that > OptionType.optType1 is

Re: convert int[][] to int**

2014-02-21 Thread Chris Williams
On Friday, 21 February 2014 at 19:13:13 UTC, Chris Williams wrote: On Thursday, 20 February 2014 at 17:02:15 UTC, Dicebot wrote: You can't do it without allocation because memory layout is different for int** and int[][] in D - are.ptr in latter points to slice struct (pointer+length) as oppose

Re: convert int[][] to int**

2014-02-21 Thread Chris Williams
On Thursday, 20 February 2014 at 17:02:15 UTC, Dicebot wrote: You can't do it without allocation because memory layout is different for int** and int[][] in D - are.ptr in latter points to slice struct (pointer+length) as opposed to raw pointer in former. You should only have to copy the top

Re: Is there kind of "associative tuple" - like syntax in D?

2014-02-21 Thread Uranuz
You could do something like this: alias Foo!( OptionType.optType1, 100, OptionType.optType2, "example, ...etc... ) MyFoo; Yes. I already use this. But it makes it not semanticaly obvious that OptionType.optType1 is a kind of `key` and 100 is `value`. Also it needs to parse it and

Re: Is there kind of "associative tuple" - like syntax in D?

2014-02-21 Thread Justin Whear
On Fri, 21 Feb 2014 17:57:57 +, Uranuz wrote: > My idea is that pass these options using syntax like this: > > alias Foo!( [ >OptionType.optType1 : 100, OptionType.optType2 : "example", >"someOtherOpt1": "someOtherOptValue", "someOtherOpt2": true > ] ) MyFoo; > > Using [] brackets

Is there kind of "associative tuple" - like syntax in D?

2014-02-21 Thread Uranuz
In my template functions, classes it's necessary to write variadic template parameter list, where elements are options to this class/function changing it's behaviour. But they are optional and may be not set at all. These options may be folowed by variadic template parameter list that will be

Re: Method template optimization that works in C++, but not very well D

2014-02-21 Thread Vladimir
On Thursday, 20 February 2014 at 22:36:58 UTC, Ali Çehreli wrote: int proccessRowTemplate(size_t optionVariant)(in Row table) { int sum = 0; foreach(size_t i; StaticRange!(Row.numberField)) { static if (optionVariant & 1< This version of the program looks more graceful than m

Re: immutable int n = Test(); int[n] x;---- compiles, but __ctfe is false. How?

2014-02-21 Thread Ali Çehreli
On 02/21/2014 08:46 AM, Gopan wrote: > On Friday, 21 February 2014 at 14:04:45 UTC, FreeSlave wrote: >> Another strange thing: >> >> import std.stdio; >> >> uint Test() >> { >> if (!__ctfe) >> { >> return 3; >> } >> return 2; >> } >> >> >> >> void main() >> { >> immuta

Re: immutable int n = Test(); int[n] x;---- compiles, but __ctfe is false. How?

2014-02-21 Thread Gopan
On Friday, 21 February 2014 at 14:04:45 UTC, FreeSlave wrote: Another strange thing: import std.stdio; uint Test() { if (!__ctfe) { return 3; } return 2; } void main() { immutable n = Test(); int[n] arr; writeln("arrary length = ", arr.length, " ; n = ", n

Re: Optimization ???

2014-02-21 Thread Mattdef
On Friday, 21 February 2014 at 13:39:08 UTC, Orvid King wrote: The single biggest reason that this is slower in D than in C# is because of the GC. By default with MS.Net, and Mono (when compiled with sgen) an allocation is almost literally just a bump-the-pointer, with an occasional scan (no co

Re: Why function template 'among' is of complexity O(1) and not O(n)?

2014-02-21 Thread anonymous
On Thursday, 20 February 2014 at 13:40:38 UTC, anonymous wrote: When a value is needed at compile time (e.g. initializer for a static variable, length of a static array), then CTFE is forced. When the value is not needed at compile time, the optimizer may go for it, but that's not guaranteed.

Re: immutable int n = Test(); int[n] x;---- compiles, but __ctfe is false. How?

2014-02-21 Thread anonymous
On Friday, 21 February 2014 at 13:38:58 UTC, Gopan wrote: Attempting to learn CTFE, I tried the following test. size_t counter; uint Test() { if (!__ctfe) { ++counter;// This code is for execution at run time } return 2; } void main() { w

Re: immutable int n = Test(); int[n] x;---- compiles, but __ctfe is false. How?

2014-02-21 Thread FreeSlave
Another strange thing: import std.stdio; uint Test() { if (!__ctfe) { return 3; } return 2; } void main() { immutable n = Test(); int[n] arr; writeln("arrary length = ", arr.length, " ; n = ", n); } Output: arrary length = 2 ; n = 3 When you think about i

Re: immutable int n = Test(); int[n] x;---- compiles, but __ctfe is false. How?

2014-02-21 Thread FreeSlave
On Friday, 21 February 2014 at 13:38:58 UTC, Gopan wrote: Attempting to learn CTFE, I tried the following test. size_t counter; uint Test() { if (!__ctfe) { ++counter;// This code is for execution at run time } return 2; } void main() { w

immutable int n = Test(); int[n] x; ---- compiles, but __ctfe is false. How?

2014-02-21 Thread Gopan
Attempting to learn CTFE, I tried the following test. size_t counter; uint Test() { if (!__ctfe) { ++counter;// This code is for execution at run time } return 2; } void main() { writeln("counter = ", counter); immutable i

Re: Optimization ???

2014-02-21 Thread Orvid King
The single biggest reason that this is slower in D than in C# is because of the GC. By default with MS.Net, and Mono (when compiled with sgen) an allocation is almost literally just a bump-the-pointer, with an occasional scan (no compaction for this code) and collection of the 64kb (on MS.Net it ac

Re: Optimize my code =)

2014-02-21 Thread John Colvin
On Thursday, 20 February 2014 at 21:32:10 UTC, Robin wrote: Hiho, here are the results of both compilers (DMD and LDC2) on my system: LDC: = allocationTest ... Time required: 5 secs, 424 msecs multiplicationTest ... Time required: 1 secs

Re: Static arrays and std.algorithm.sort

2014-02-21 Thread John Colvin
On Thursday, 20 February 2014 at 17:24:55 UTC, D Apprentice wrote: Greetings, D wizards. Given a static array, int[5] a, presumed to be filled with random numbers, how does one sort it using std.algorithm.sort? Calling sort(a) by itself errors out with: test.d(7): Error: template std.algorith

Re: Optimization ???

2014-02-21 Thread John Colvin
On Friday, 21 February 2014 at 09:29:42 UTC, Mattdef wrote: Thanks for yours replies. I know it is the conversion of uint that is the problem but my C# code has the same conversion. So C# is better than D for string conversions ? (sorry for my english) It's quite possible that C# has faster

Re: [video tutorial] Defensive programming with Design By Contract basics

2014-02-21 Thread Mengu
On Friday, 21 February 2014 at 09:59:04 UTC, simendsjo wrote: On Friday, 21 February 2014 at 09:46:20 UTC, Mengu wrote: On Thursday, 20 February 2014 at 10:28:45 UTC, simendsjo wrote: http://youtu.be/wFqHTCBt72M enjoyed it, thanks! what are you going to talk about next? I only have a rough

Re: [video tutorial] Defensive programming with Design By Contract basics

2014-02-21 Thread simendsjo
On Friday, 21 February 2014 at 09:46:20 UTC, Mengu wrote: On Thursday, 20 February 2014 at 10:28:45 UTC, simendsjo wrote: http://youtu.be/wFqHTCBt72M enjoyed it, thanks! what are you going to talk about next? I only have a rough outline in my head that will probably change as I go: * Split

Re: [video tutorial] Defensive programming with Design By Contract basics

2014-02-21 Thread Mengu
On Thursday, 20 February 2014 at 10:28:45 UTC, simendsjo wrote: http://youtu.be/wFqHTCBt72M enjoyed it, thanks! what are you going to talk about next?

Re: Optimization ???

2014-02-21 Thread Mattdef
Thanks for yours replies. I know it is the conversion of uint that is the problem but my C# code has the same conversion. So C# is better than D for string conversions ? (sorry for my english)