Re: use variant as associative array

2010-02-11 Thread downs
On 10.02.2010 22:28, GG wrote: > I try to use variant as associative array with dmd2.039, > > Variant[char[]][int] aa; > aa[0]["Month"] = "Jan"; > aa[0]["Profit"] = 500; > aa[1]["Month"] = "Feb"; > aa[1]["Profit"] = 800; > > I got core.exception.rangeer...@main(28): Range violation > I'm doing s

Re: Unexpected behaviour on socket

2010-02-11 Thread downs
On 10.02.2010 14:41, daoryn wrote: >> >> The buffer you are passing to receive is 0 bytes long. The >> std.socket.Socket.receive function is a wrapper over the normal socket >> function, and includes a test for an empty buffer. >> >> Daniel > > Ohh, I see. Thank you! > > I thought that the fun

Re: Are named variadic arguments possible?

2010-01-05 Thread downs
Alex wrote: > Is it possible, using templates, tuples, or some other mechanism, to > implement named variadic arguments in D? > > For example, I'd like to be able to do something like... > foo( 2, &bar, age : 10, status : "down"); > > and so forth. Yes, with a small hack. typedef int age_type;

Re: something "weird" about polymorphism

2009-11-15 Thread downs
funog wrote: > The following code : > > -- > import std.stdio; > class A { > void foo(A a) { > writefln("A"); > } > } > > class B : A { > void foo(B b) { > writefln("B"); > } > } > > void main() { > B b = new B; > A a = b; > assert(a is

Re: Different class template args to generate same template instance?

2009-11-02 Thread downs
Nick Sabalausky wrote: > "BCS" wrote in message > news:a6268ffc3898cc29d1f554d...@news.digitalmars.com... >> Hello Nick, >> >> >>> So...is there any trickery I >>> could do so that SubFoo!("sam") and SubFoo!("sam", "human") would >>> resolve to the same subclass of Foo? >> Make a SubFoo!(char[] s

Re: Associative array trouble

2009-10-16 Thread downs
Bill Baxter wrote: > You query presence of a key in an AA using 'in' > > if (id in symtab) { > Symbol sym = symtab[id]; > ... > } else { > .. > } > > Or this avoids a double lookup if the symbol is present: > > Symbol* pSym = id in symtab; > if (pSym !is null) { >

Re: Getting started - D meta-program question

2009-10-07 Thread downs
auto like this to? > Sadly, it's an if-specific syntax. > Thank you for taking the time downs, > > -- Justin Anytime.

Re: Member functions C to D

2009-10-07 Thread downs
Craig Kuhnert wrote: > Hi > I am trying to convert some code I wrote in C++ to D to give it a try and I > have come across some code that I dont know how to convert. > I have simplified the code to illustrate the problem I have. > How do I do this in D? > > class IFieldSetter > { > public: >

Re: Getting started - D meta-program question

2009-10-04 Thread downs
Justin Johansson wrote: > Daniel Keep Wrote: > >> Justin Johansson wrote: >>> There was mention** on the general discussion group that the D >>> foreach_reverse >>> language construct could be replaced (emulated?) with a (D) meta-program. >>> >>> ** "Even a novice programmer can write a meta-prog

Re: D1: std.md5: corrections for the given example

2009-09-17 Thread downs
Stewart Gordon wrote: > downs wrote: > >> while (auto len = file.readBlock(buffer.ptr, buffer.sizeof)) > > > md5_example_2.d(7): expression expected, not 'auto' > md5_example_2.d(7): found 'len' when expecting ')' > md5_example_2.d(7): fo

Re: D1: std.md5: corrections for the given example

2009-09-17 Thread downs
notna wrote: > Stewart Gordon schrieb: >> The .ptr is necessary, but the cast(uint) isn't. Even if a change of >> type were necessary, just 1U would do. (U is a suffix meaning >> unsigned. There's also L meaning long.) >> >> Stewart. > > Thank Stewart. > > As the std.md5-example is not working

Re: CRTP in D?

2009-08-19 Thread downs
bearophile wrote: > I don't know much C++. Can CRTP be used in D1 too, to improve the performance > of some D1 code? > > http://en.wikipedia.org/wiki/Curiously_Recurring_Template_Pattern > > Bye, > bearophile We have this, except we call it "template mixin" :)

Re: Precision, new prices

2009-07-25 Thread downs
Saaa wrote: > I thought my previous precision question was so retarded it didn't need any > explanation; anybody here could easily tell me my fault in reasoning. > > Here is my question again but this time with examples. > > Is there some formatting which lets me print out a floating point in full

Re: Precision, new prices

2009-07-25 Thread downs
Saaa wrote: > I thought my previous precision question was so retarded it didn't need any > explanation; anybody here could easily tell me my fault in reasoning. > > Here is my question again but this time with examples. > > Is there some formatting which lets me print out a floating point in fu

Re: Specify the type but not number of function arguments in an interface?

2009-07-08 Thread downs
Jarrett Billingsley wrote: > On Tue, Jul 7, 2009 at 8:29 AM, downs wrote: >> But then isn't what he asks for kinda impossible by design? I mean, >> interfaces are bound at runtime. That's what they _do_. >> > > Now read *my* post, downs. ;) :blushes:

Re: Specify the type but not number of function arguments in an interface?

2009-07-07 Thread downs
downs wrote: > Jarrett Billingsley wrote: >> On Sun, Jul 5, 2009 at 5:44 AM, downs wrote: >>> Doctor J wrote: >>>> I want to write an interface that expresses the following idea: "classes >>>> implementing this interface must have a void function nam

Re: Specify the type but not number of function arguments in an interface?

2009-07-07 Thread downs
Jarrett Billingsley wrote: > On Sun, Jul 5, 2009 at 5:44 AM, downs wrote: >> Doctor J wrote: >>> I want to write an interface that expresses the following idea: "classes >>> implementing this interface must have a void function named update, with a >&

Re: How to release memory? (D2.0.30)

2009-07-05 Thread downs
BCS wrote: > Hello AxelS, > >> BCS Wrote: >> >>> You can't. The D runtime (and most other runtimes) don't ever reduce >>> the amount of memory they keep in the heap. If you where to allocate >>> another 25MB right after that function you would see no change in the >>> memory usage. The good news i

Re: Specify the type but not number of function arguments in an interface?

2009-07-05 Thread downs
Doctor J wrote: > I want to write an interface that expresses the following idea: "classes > implementing this interface must have a void function named update, with a > fixed but indeterminate number of parameters of the same (template parameter) > type." Use a typesafe variadic function, i.e

Re: bitfields

2009-06-30 Thread downs
novice2 wrote: > downs Wrote: >> Here's a way to do it. >> >> Enjoy! :) >> >> Usage example: >> >> struct Test { >> ... skipped... > > Thank you, downs, for your job! > > but, heh, i can't use something, that i can

Re: bitfields

2009-06-27 Thread downs
novice2 wrote: > does anyone know: is D2 std.bitmanip compatible with C bitfields? > can i use it, if i need translate .h file with something like this: > > typedef struct { > unsigned int can_compress : 1; > unsigned int can_uncompress : 1; > unsigned int can_get_info : 1; > unsig

Re: A public apology.

2009-06-15 Thread downs
Jarrett Billingsley wrote: > On Mon, Jun 15, 2009 at 10:15 PM, Derek Parnell wrote: >> On Mon, 15 Jun 2009 21:47:53 -0400, Jarrett Billingsley wrote: >> I've actually given up trying to influence D ... the patricians have made >> it too hard to contribute and I've haven't got *that* much free time.

Re: Should be easy

2009-06-12 Thread downs
Saaa wrote: > Thanks! > I thought about the idea of just creating the code and mix it in, but now I > can see why I failed at that: Your code is kind of read-only to me, for now, > because I need to change it a bit to accept an array instead of seperat > indices. > > Wouldn't it be nice if it w

Re: Should be easy

2009-06-12 Thread downs
Saaa wrote: > I can't figure out how to create the IndexArray function, > it should work on arrays of any depth > > int[][][] array; //any depth > array.length=10; > array[1].length=3; > array[1][2].length=4; > array[1][2][1]=99; > > writefln(array); > //[[],[[],[],[0,99,0,0]],[],[],[],[],[],[],[

Re: legal identifier check

2009-05-30 Thread downs
Saaa wrote: > Is there a function to check whether some string is a legal identifier? > > Sure. static if(is(typeof({ /* code to be checked for validity goes here */ }))) ...

Re: convert *void to void[]

2009-05-06 Thread downs
gabrielsylar wrote: > can anybody please tell me how to properly convert from void* to void[] > as the code below? > > void[] get_bytes(int n) { return sqlite3_column_blob(stmt, n); } In unrelated matters: if you're writing a sqlite3 binding, take a look at tools.sqlite3. :) http://dsource.org/

Re: SQLite with D

2009-04-26 Thread downs
reimi gibbons wrote: > downs Wrote: > >> reimi gibbons wrote: >>> im failry new to D, is there any D library project with support for SQLite, >>> if not is there any guide so i can integrate sqlite amalgamated c source >>> (sqlite3.c, sqlite3.h) into my

Re: SQLite with D

2009-04-24 Thread downs
reimi gibbons wrote: > im failry new to D, is there any D library project with support for SQLite, > if not is there any guide so i can integrate sqlite amalgamated c source > (sqlite3.c, sqlite3.h) into my D code. tools.sqlite3 might work for you. Ask me if you have any questions about it. htt

Open GL extensions, dglut style

2009-04-14 Thread downs
AxelS wrote: > Hello evrybody... > > I want to use all the opengl extensions like Shaders in my D2.0 prog... > I already got the opengl32.lib and also the headers... > > I tried it wglGetProc (similar name...)! I could compile it but it hangs up > runtime and creates errors which dont tell me th

Re: wchar[] and wchar*

2009-04-09 Thread downs
doesn't it? > > I wouldn't want to mention the 'T' word for fear of Downs accusing me > of proselytizing. :snort: I do agree in this case. I just don't like it when Tango is proposed as an alternative and the existence of a perfectly valid Phobos solution is ignored.

Re: Sockets and D?

2009-04-05 Thread downs
Jimi_Hendrix wrote: > Hi, I am new to D but not to programming. I have had some socket experience > before. How would i connect to a server using sockets in D? A link to a D > socket tutorial (if one exists) would also be appreciated. > > by the way, first post to a newsgroup for me As certa

Re: -profile and threaded code

2009-03-28 Thread downs
BCS wrote: > Hello BCS, > >> I have a program that runs an "easily" parallelizable loop. When I run >> it as a single thread it only takes about 10% longer than 2 threads >> (on a dual-core). I'm trying to track down the lossed time and am >> wondering if turning on -profile is even worth looking

Re: lvalue - opIndexAssign - Tango

2009-03-15 Thread downs
The Anh Tran wrote: > Hi, > > When porting from c++ to D, i encounter this strange discrimination: > 1. Built-in AA: > int[int] arr; > arr[123] += 12345; > arr[321]++; > > 2. Tango HashMap: > auto hm = new HashMap!(int, int)(); > hm[123] += 12345; // error not lvalue > hm[

Re: Reading and writing Unicode files

2009-02-28 Thread downs
downs wrote: > jicman wrote: >> Greetings. >> >> Sorry guys, please be patient with me. I am having a hard time >> understanding this Unicode, ANSI, UTF* ideas. I know how to get an UTF8 >> File and turn it into ANSI. and I know how to take a ANSI file and t

Re: Access Vialotation

2009-02-28 Thread downs
BCS wrote: > Reply to Jarrett, > >> On Fri, Feb 27, 2009 at 9:01 AM, Qian Xu >> wrote: >> >>> Hi All, >>> >>> Is there any way to keep program alive, when an AV takes place? >>> >> It's possible on Windows in D, but that's because Windows reports >> segfaults with the same mechanism that D uses f

Re: Reading and writing Unicode files

2009-02-28 Thread downs
jicman wrote: > Greetings. > > Sorry guys, please be patient with me. I am having a hard time understanding > this Unicode, ANSI, UTF* ideas. I know how to get an UTF8 File and turn it > into ANSI. and I know how to take a ANSI file and turn it into an UTF file. > But, now I have a Unicode f

Re: object splitting in multiple threads

2009-01-10 Thread downs
Jarrett Billingsley wrote: > On Sat, Jan 10, 2009 at 12:30 AM, Jarrett Billingsley > wrote: >> On Sat, Jan 10, 2009 at 12:18 AM, yes wrote: >>> Does Phobos also do threadpools? >> From what I understand, not without modification. At least, not >> efficiently. D