Re: reinterpret_cast float to uint

2015-03-29 Thread ketmar via Digitalmars-d-learn
On Sun, 29 Mar 2015 13:45:10 +, matovitch wrote: you can also use unions. signature.asc Description: PGP signature

Re: reinterpret_cast float to uint

2015-03-29 Thread ketmar via Digitalmars-d-learn
On Sun, 29 Mar 2015 16:00:05 +, matovitch wrote: > On Sunday, 29 March 2015 at 14:50:24 UTC, ketmar wrote: >> On Sun, 29 Mar 2015 13:45:10 +, matovitch wrote: >> >> you can also use unions. > > Good idea ! In my case I think it was better to cast, but this could be > helpful another time

Re: reinterpret_cast float to uint

2015-03-29 Thread ketmar via Digitalmars-d-learn
On Sun, 29 Mar 2015 17:33:02 +, Namespace wrote: > On Sunday, 29 March 2015 at 16:29:40 UTC, ketmar wrote: >> On Sun, 29 Mar 2015 16:00:05 +, matovitch wrote: >> >>> On Sunday, 29 March 2015 at 14:50:24 UTC, ketmar wrote: On Sun, 29 Mar 2015 13:45:10 +, matovitch wrote:

Re: Passing myself, a struct, as a C callback context

2015-03-29 Thread ketmar via Digitalmars-d-learn
On Sun, 29 Mar 2015 22:53:35 -0400, Paul O'Neil wrote: > I'm registering a callback with some C code. The simplified story is > here, but the actual code is on GitHub [1] at the end if you care. > > The call looks something like this. > > void register(void(*fp)(void*), void* context); > > I h

Re: Associative Array of Const Objects?

2015-03-29 Thread ketmar via Digitalmars-d-learn
On Sun, 29 Mar 2015 20:29:49 +, bitwise wrote: > The verbosity and blatant disregard for DRY makes me CRY. > See what I did there.. ;) you can always `alias` it to something funny or obscene. signature.asc Description: PGP signature

D1 operator overloading in D2

2015-03-29 Thread ketmar via Digitalmars-d-learn
it's still working. moreover, it is used in Phobos! and yet it's not documented anywhere. what i want to know is whether they will be removed for good, or brought back and properly documented? the current situation is awful: compiler has special treatment for some aggregate members, but nothing

Re: D1 operator overloading in D2

2015-03-30 Thread ketmar via Digitalmars-d-learn
On Mon, 30 Mar 2015 11:25:01 -0400, Steven Schveighoffer wrote: > On 3/30/15 1:42 AM, ketmar wrote: >> it's still working. moreover, it is used in Phobos! and yet it's not >> documented anywhere. what i want to know is whether they will be >> removed for good, or brought back and properly document

Re: using exceptions in @nogc

2015-03-30 Thread ketmar via Digitalmars-d-learn
On Tue, 31 Mar 2015 01:40:52 +, weaselcat wrote: > was this ever solved? nope. there were some suggestions, but no decision was made. signature.asc Description: PGP signature

Re: Mapping with partial

2015-03-30 Thread ketmar via Digitalmars-d-learn
On Mon, 30 Mar 2015 19:36:49 +, matovitch wrote: >> The index is the problem. Generally, foreach doesn't do automatic >> indices for ranges. You can use std.range.enumerate or count yourself >> explicitly. >> >> foreach(i, t; myRange.enumerate) {...} >> >> size_t i = 0; >> foreach(t; myRange)

Re: D1 operator overloading in D2

2015-03-30 Thread ketmar via Digitalmars-d-learn
On Mon, 30 Mar 2015 11:25:01 -0400, Steven Schveighoffer wrote: here is ER with patches: https://issues.dlang.org/show_bug.cgi?id=14382 sorry for breaking my promise of not making ERs anymore. ;-) signature.asc Description: PGP signature

Re: using exceptions in @nogc

2015-03-30 Thread ketmar via Digitalmars-d-learn
On Tue, 31 Mar 2015 05:34:11 +, weaselcat wrote: > On Tuesday, 31 March 2015 at 03:12:42 UTC, ketmar wrote: >> On Tue, 31 Mar 2015 01:40:52 +, weaselcat wrote: >> >>> was this ever solved? >> >> nope. there were some suggestions, but no decision was made. > > sigh do you know if there's a

Re: Mutual optimization of tail recursion does not work in D

2015-03-31 Thread ketmar via Digitalmars-d-learn
On Tue, 31 Mar 2015 11:57:49 +, w0rp wrote: > You might want to try GDC or LDC. I am not certain if they implement > tail call optimisations, but they might do, and it seems like a good > optimisation to have. I'm sure this has been discussed before. gdc does, as this is gcc backend optimisat

Re: lambda code

2015-04-01 Thread ketmar via Digitalmars-d-learn
On Tue, 31 Mar 2015 13:25:46 +, John Colvin wrote: > Short answer: no. .codeof for functions is something I've wanted for > ages, but no movement so far. 'cause `.codeof` is a can of worms. it is just a bad replace for AST macros, and having it means that internal string representation shoul

Re: Static if to compare two types are the exact same

2015-04-06 Thread ketmar via Digitalmars-d-learn
On Mon, 06 Apr 2015 19:16:33 +, Jonathan wrote: > What's the best way to do this? I'm assuming this should be best > practice: > http://dlang.org/traits.html#isSame > > struct S { } > writeln(__traits(isSame, S, S)); struct S {} auto s0 = S(); auto s1 = S(); static if (is(typeof(s0) == ty

Re: why cant function parameters be grouped by type ?

2015-04-12 Thread ketmar via Digitalmars-d-learn
On Sun, 12 Apr 2015 11:49:18 +, Baz wrote: > Is there anything in the grammar that prevents this syntax ? yes: nameless args. i would like to see 'em burned with napalm, but it seems to be too late to do that... signature.asc Description: PGP signature

Re: writefln patterns with mismatching compile-time known number of arguments

2015-04-12 Thread ketmar via Digitalmars-d-learn
On Sun, 12 Apr 2015 14:18:21 +, JR wrote: > But the compiler has all the pieces of information needed to see it's > wrong, doesn't it? no, it doesn't. compiler doesn't know about `std.format.format` and it's special abilities. while it is possible to add such checks to the compiler, it will

Re: writefln patterns with mismatching compile-time known number of arguments

2015-04-13 Thread ketmar via Digitalmars-d-learn
On Sun, 12 Apr 2015 14:31:40 -0700, H. S. Teoh via Digitalmars-d-learn wrote: > It's not hard to write a CTFE version of writef/writeln/etc., that takes > the format argument at compile-time, since std.format itself is already > CTFE-able. i didn't know that (didn't checked, actually), so i rewro

Re: CTFE UFCs?

2015-04-14 Thread ketmar via Digitalmars-d-learn
On Tue, 14 Apr 2015 11:20:38 -0400, bitwise wrote: i believe that you can't do what you want in a way you want, 'cause UFCS is not working for template args. but you can do this: alias base(alias CC) = reflect!(CC.baseName()); ... static const(Refl) baseRefl = base!refl; signature.asc Descripti

Re: About @ and UDA

2015-04-15 Thread ketmar via Digitalmars-d-learn
On Wed, 15 Apr 2015 08:53:05 +, Andrea Fontana wrote: > My 2 cents. If I remember correctly, "@" prefix in @safe, @trusted, > @system, etc was added just to avoid keywords pollution, right? > > Now UDA uses the same prefix: if some new keywords/properties/attributes > will be added to D, the

Re: Where is COFFIMPLIB

2015-04-17 Thread ketmar via Digitalmars-d-learn
On Fri, 17 Apr 2015 19:48:05 +, rumbu wrote: > On Friday, 17 April 2015 at 14:39:52 UTC, Adam D. Ruppe wrote: >> coffimplib is a paid utility out of the $15 extended utility package >> >> http://digitalmars.com/eup.html >> >> buy from here (be sure javascript is enabled or the form won't even

Re: Where is COFFIMPLIB

2015-04-17 Thread ketmar via Digitalmars-d-learn
On Fri, 17 Apr 2015 20:05:42 +, rumbu wrote: > On Friday, 17 April 2015 at 19:50:13 UTC, ketmar wrote: >> On Fri, 17 Apr 2015 19:48:05 +, rumbu wrote: >> >>> On Friday, 17 April 2015 at 14:39:52 UTC, Adam D. Ruppe wrote: coffimplib is a paid utility out of the $15 extended utility pac

Re: Templates: Array slices not recognized

2015-04-18 Thread ketmar via Digitalmars-d-learn
On Sat, 18 Apr 2015 17:50:56 +, Chris wrote: > Doh! You're right! My bad. However, this makes the function less > generic, but it doesn't matter here. maybe `auto ref` can help here? signature.asc Description: PGP signature

Re: Adding pointers to GC with destructers

2015-04-19 Thread ketmar via Digitalmars-d-learn
On Sun, 19 Apr 2015 23:38:47 +, Freddy wrote: > C libraries have a pattern of > HiddenType* getObj(); > void freeObj(HiddenType*); > > Is there any way I can make the GC search for a "HiddenType*" and run > "freeObj" when the pointer is not found. wrap it in class/struct and run `fr

Re: Templates: Array slices not recognized

2015-04-20 Thread ketmar via Digitalmars-d-learn
On Mon, 20 Apr 2015 10:14:25 +, Chris wrote: > string a = "bla"; > string b = "blub"; > > auto res = doSomething(a, b); > > If I didn't use "auto ref" or "ref", string would get copied, wouldn't > it? no, it wont -- not unless you'll append something to it. slicing arrays (and string is ar

Re: CT-String as a Symbol

2015-04-20 Thread ketmar via Digitalmars-d-learn
On Mon, 20 Apr 2015 13:31:03 +, Nordlöw wrote: > On Thursday, 16 April 2015 at 18:12:35 UTC, Nordlöw wrote: >> Is there a way to CT-query the arity of all opIndex and opSlice >> overloads? > > Ping. as long as they aren't templates, you can use any function traits on 'em. like `ParameterT

Re: Observing exceptions in a destructor

2015-04-21 Thread ketmar via Digitalmars-d-learn
On Wed, 22 Apr 2015 01:02:15 +, Mark Isaacson wrote: > I'd like to be able to know if my destructor is being called because an > exception was thrown. Any way to do that? sorry, you can't. signature.asc Description: PGP signature

Re: setjmp / longjmp

2015-04-25 Thread ketmar via Digitalmars-d-learn
On Sat, 25 Apr 2015 23:25:13 +, Cassio Butrico wrote: > Hello everyone , first congratulations for the wonderful forum , I wish > someone could help me , I am writing a small basic interpreter in D and > I am with some difficulties. > > estoutentando manupular the setjmp / longjmp buffers , b

Re: setjmp / longjmp

2015-04-27 Thread ketmar via Digitalmars-d-learn
On Sun, 26 Apr 2015 21:45:41 +0100, Stewart Gordon wrote: > On 26/04/2015 06:56, ketmar wrote: > >> you shouldn't use setjmp/longjmp in D. use exceptions instead. >> something like this: > > > True in the general case. Still, there must be some reason that trying > it in D causes an AV (even i

shouldn't this code at least trigger a warning?

2015-04-28 Thread ketmar via Digitalmars-d-learn
subj. the code: void main () { import std.stdio; char ch = '!'; switch (ch) { int n = 42; case '!': writeln(n, ": wow!"); break; default: } } i think that such abomination should: 1. be forbidden, or 2. trigger a warning, or 3. execute initializer anyway. c

Re: shouldn't this code at least trigger a warning?

2015-04-30 Thread ketmar via Digitalmars-d-learn
On Wed, 29 Apr 2015 07:57:07 -0700, H. S. Teoh via Digitalmars-d-learn wrote: > Switch statements in D allow all sorts of abominations, if only you > would try it. I think it was originally designed to support a particular > loop idiom (sorry I forgot what it was called, and don't have time to > l

Re: shouldn't this code at least trigger a warning?

2015-04-30 Thread ketmar via Digitalmars-d-learn
On Wed, 29 Apr 2015 10:48:36 +, Gary Willoughby wrote: > Please raise an issue in bugzilla. This is obviously an error. done: https://issues.dlang.org/show_bug.cgi?id=14532 signature.asc Description: PGP signature

Re: UDA and ReturnType!(__traits...) doesn't work

2015-05-03 Thread ketmar via Digitalmars-d-learn
On Sun, 03 May 2015 17:21:58 +, filcuc wrote: > Hi all, > i'm working in the generation of the code but i'm failing in extracting > a function return type when invoking the ReturnType!(T) type trait and > mixing it with __traits(getMember) function. > Can anyone help me? or explaining what is

Re: Struct lifetime wrt function return?

2015-05-03 Thread ketmar via Digitalmars-d-learn
On Mon, 04 May 2015 02:29:19 +, rsw0x wrote: > This says "Goodbye!" exactly once, indicating(?) that S was NRVO'd which > means the scope of s went from foo to main. However, is this a guarantee > by the standard? Is an implementation allowed to define foo such that it > returns by copy and ca

Re: Is this expected? default to public members in private class

2015-05-03 Thread ketmar via Digitalmars-d-learn
On Sun, 03 May 2015 18:07:20 -0700, Dan Olson wrote: > It seems a private class or struct defaults to public members. Just > curious if this is intended. I would have expected private all the way > down unless overriden. i bet it is intended. protection of struct/class members is independed of

Re: UDA and ReturnType!(__traits...) doesn't work

2015-05-03 Thread ketmar via Digitalmars-d-learn
On Sun, 03 May 2015 18:02:37 +, filcuc wrote: > Yep sorry, > i'm still learning :) i'm not blaming you at all. what i mean i that i'm bad at explanations, so you'd better read one of the D books to better understand my cryptic "don't do that, do this" comments. ;-) signature.asc Descriptio

Re: CTFE & enums & static assert

2015-05-04 Thread ketmar via Digitalmars-d-learn
On Mon, 04 May 2015 18:21:59 +0200, Robert M. Münch wrote: > I find this a bit strange: > > // get all rules that start with p... > enum BolRules = StaticFilter!(beginsWithP, > __traits(allMembers,BolSource)); > static assert(is(BolRules == enum)); > > Compiling using dmd... > source/app.d(114)

Re: CTFE & enums & static assert

2015-05-04 Thread ketmar via Digitalmars-d-learn
On Mon, 04 May 2015 20:07:27 +0200, Robert M. Münch wrote: > > Gives this: > > (string, string, string) > playground.d(9): Error: no type for typeid(members1) > playground.d(9):while evaluating pragma(msg, typeid(members1)) `typeid` is runtime thing, you can't use it in compile-time.

Re: Signs by which to recognize D1

2015-05-07 Thread ketmar via Digitalmars-d-learn
On Wed, 06 May 2015 14:26:43 +, rumbu wrote: > operator overloads: opCom, opAdd, opSub ... phobos' std.xml, std.variand and std.bitmanip are D1! ;-) signature.asc Description: PGP signature

Re: ICE?

2015-05-18 Thread ketmar via Digitalmars-d-learn
On Sun, 17 May 2015 10:09:10 +, Daniel Kozak wrote: > On Sunday, 17 May 2015 at 09:25:33 UTC, Namespace wrote: >> Is this error an ICE? I think so, because I see the internal filename, >> but I'm not sure. >> >> Error: e2ir: cannot cast malloc(length * 8u) of type void* to type >> char[] > >

Re: -vgc Info ok?

2015-05-18 Thread ketmar via Digitalmars-d-learn
On Mon, 18 May 2015 14:30:42 +, Chris wrote: > The following > > string[string] myarray = ["key":"value"]; > string entry; > entry = myarray["key"]; // => vgc: indexing an associative array may > cause GC allocation > > Why is _accessing_ an assoc treated as indexing it? it can throw "out o

Re: -vgc Info ok?

2015-05-18 Thread ketmar via Digitalmars-d-learn
On Mon, 18 May 2015 14:41:19 +, Chris wrote: > On Monday, 18 May 2015 at 14:34:38 UTC, ketmar wrote: >> On Mon, 18 May 2015 14:30:42 +, Chris wrote: >> >>> The following >>> >>> string[string] myarray = ["key":"value"]; >>> string entry; >>> entry = myarray["key"]; // => vgc: indexing an

Re: Associative array on the heap

2015-05-18 Thread ketmar via Digitalmars-d-learn
On Mon, 18 May 2015 23:55:38 +, Freddy wrote: > How do you allocate an associative array on the heap? > > void main(){ > alias A=int[string]; > auto b=new A; > } > > $ rdmd test test.d(4): Error: new can only create structs, dynamic > arrays or class objects, not int[stri

Re: -vgc Info ok?

2015-05-19 Thread ketmar via Digitalmars-d-learn
On Tue, 19 May 2015 11:36:32 +, Chris wrote: > On Tuesday, 19 May 2015 at 11:08:52 UTC, thedeemon wrote: >> On Monday, 18 May 2015 at 14:30:43 UTC, Chris wrote: >> >>> Why is _accessing_ an assoc treated as indexing it? >> >> Are you sure you understand "indexing" as we do? It's not like index

Re: -vgc Info ok?

2015-05-19 Thread ketmar via Digitalmars-d-learn
On Tue, 19 May 2015 13:17:15 +, anonymous wrote: > On Monday, 18 May 2015 at 14:34:38 UTC, ketmar wrote: >> it can throw "out of range" error, which is `new`ed. > > Array access can also throw RangeError, but -vgc and @nogc don't mind > that: > > void main() @nogc { > int[] a; >

Re: Internal Compiler Error Help

2015-05-21 Thread ketmar via Digitalmars-d-learn
On Thu, 21 May 2015 11:36:14 +, Saurabh Das wrote: > PS: The original expression: > http://dpaste.dzfl.pl/raw/e7a66aa067ab > > double someFunction(double AvgPriceChangeNormalized, double DayFactor, > double TicksTenMinutesNormalized) > { > return > AvgPriceChangeNormalized)*(0.0868))

Re: Idiomatic way to call base method in generic code

2015-05-25 Thread ketmar via Digitalmars-d-learn
On Sun, 24 May 2015 23:32:50 +, ZombineDev wrote: > I know I can call a base implementation of a method like in 3), but I > need to do it generically like in 2). Does anybody now how I can achieve > this? i don't know why you want that, but something like this may do: auto callBaseMethod(str

Re: Idiomatic way to call base method in generic code

2015-05-25 Thread ketmar via Digitalmars-d-learn
On Mon, 25 May 2015 09:24:56 +, ZombineDev wrote: > On Monday, 25 May 2015 at 07:57:49 UTC, ketmar wrote: >> i don't know why you want that, but something like this may do: >> >> auto callBaseMethod(string MTN, C, Args...) (inout C self, Args args) { >> alias FSC = BaseClassesTuple!(C)[0]; >

Re: Idiomatic way to call base method in generic code

2015-05-25 Thread ketmar via Digitalmars-d-learn
On Mon, 25 May 2015 09:24:56 +, ZombineDev wrote: > alias can't refer to a nested member: > - > struct Point2 { > float x; > float y; > } > > struct Line2 { > Point2 start; > Point2 end; > > mixin Access; > > // alias x1 = this.start.x; <- this does

Re: Null argument and function resolution

2015-05-27 Thread ketmar via Digitalmars-d-learn
On Wed, 27 May 2015 14:09:47 +, Adam D. Ruppe wrote: > Two options: > > 1) add an overload that takes typeof(null) > > this(typeof(null)) { /* handles the null literal specially */ } you keep breaking my "box of thinking". ;-) never thought about such declaration. signature.asc Descriptio

Re: Template problem - if arg[0]==something; call arg[1];

2015-05-27 Thread ketmar via Digitalmars-d-learn
On Wed, 27 May 2015 22:35:54 +, wobbles wrote: quick looking thru your code raises two questions: 1. didn't you forgot to add `.stringof` in `constructCases`? 2. didn't you forgot `!` in `constructCases(Aliases[2..$])`? i.e. `constructCases~(Aliases[2..$])` it may work with that. signatu

Re: Template problem - if arg[0]==something; call arg[1];

2015-05-27 Thread ketmar via Digitalmars-d-learn
On Wed, 27 May 2015 22:49:18 +, ketmar wrote: >i.e. `constructCases~(Aliases[2..$])` `constructCases!(Aliases[2..$])`, of course ;-) signature.asc Description: PGP signature

Re: convert base

2015-06-02 Thread ketmar via Digitalmars-d-learn
On Mon, 01 Jun 2015 21:43:56 -0400, Steven Schveighoffer wrote: > I don't think a general function such as to with radix is good for this. > You can probably do better with a custom function, I'm not sure if > there's any base-64 libraries out there. std.base64? ;-) signature.asc Description: PG

Re: Call-ie return on behalf of caller?

2015-06-03 Thread ketmar via Digitalmars-d-learn
On Wed, 03 Jun 2015 22:37:52 +, Tofu Ninja wrote: > I don't want to have to put try catch blocks every > time I call the caller. write mixin template for that. ;-) signature.asc Description: PGP signature

Re: Call-ie return on behalf of caller?

2015-06-03 Thread ketmar via Digitalmars-d-learn
On Thu, 04 Jun 2015 01:07:10 +, Tofu Ninja wrote: > On Thursday, 4 June 2015 at 01:01:08 UTC, ketmar wrote: >> On Wed, 03 Jun 2015 22:37:52 +, Tofu Ninja wrote: >> >>> I don't want to have to put try catch blocks every time I call the >>> caller. >> >> write mixin template for that. ;-) >

Re: string to char array?

2015-06-03 Thread ketmar via Digitalmars-d-learn
On Wed, 03 Jun 2015 11:59:56 +, Kyoji Klyden wrote: > That's what I found so confusing about the opengl docs. Just guessing > here but char* is a pointer to the first char in the string, then what > exactly is char**? Is it pointing to the first char of the first string > in an array? it's a

Re: Is there a way to get the types of all template parameters?

2015-06-04 Thread ketmar via Digitalmars-d-learn
On Thu, 04 Jun 2015 13:38:18 +, Atila Neves wrote: > For regular runtime parameters, there's ParameterTypeTuple. How would I > write an equivalent template for template parameters? i.e. > > void fun(Foo foo, Bar bar)() {} > > alias types = CtParameterTypeTuple!fun; //TypeTuple!(Foo

Re: Idiomatic way to check for UDA?

2015-06-06 Thread ketmar via Digitalmars-d-learn
On Sun, 07 Jun 2015 05:32:46 +, Tofu Ninja wrote: > Whats the idiomatic way to check if an identifier has a specific UDA > attached to it. > > Also what should I use to define a UDA that doesn't need to carry any > data? Just an empty template? Or does something else make more sense? there i

Re: Idiomatic way to check for UDA?

2015-06-07 Thread ketmar via Digitalmars-d-learn
On Sun, 07 Jun 2015 11:37:29 +, Marc Schütz wrote: > On Sunday, 7 June 2015 at 06:20:55 UTC, ketmar wrote: >> On Sun, 07 Jun 2015 05:32:46 +, Tofu Ninja wrote: >> >>> Whats the idiomatic way to check if an identifier has a specific UDA >>> attached to it. >>> >>> Also what should I use t

Re: Why is there no named parameter support?

2015-06-09 Thread ketmar via Digitalmars-d-learn
On Mon, 08 Jun 2015 20:32:56 -0700, Jonathan M Davis via Digitalmars-d-learn wrote: > is, but personally, I think that named arguments are a terrible idea in > general, so I'm not about to try and support a position that tries to > bring them into D. it's a perfect thing. i always hate that "Flag

Re: Why is there no named parameter support?

2015-06-09 Thread ketmar via Digitalmars-d-learn
On Mon, 08 Jun 2015 22:58:10 -0700, Jonathan M Davis via Digitalmars-d-learn wrote: > Personally, I hate how named arguments affect the API (e.g. the names of > the parameters suddenly become part of the API), and for the most part, > the only times that they're worth much is when you have so many

Re: Why is there no named parameter support?

2015-06-09 Thread ketmar via Digitalmars-d-learn
On Tue, 09 Jun 2015 09:50:15 +, Marc Schütz wrote: > On Tuesday, 9 June 2015 at 05:39:06 UTC, Timothee Cour wrote: >> I'd be very interested in reading more about those reasons beyond FUD. >> The arguments in favor have been repeated many times over, and the only >> argument against that I've

Re: setjmp / longjmp

2015-06-09 Thread ketmar via Digitalmars-d-learn
On Tue, 09 Jun 2015 11:57:03 +0100, Stewart Gordon wrote: > On 27/04/2015 10:41, ketmar wrote: > >> i believe this has something to do with exception frames. but it needs >> further investigation. > > What is an exception frame, exactly? to correctly do unwinding and other interesting things ex

Re: __traits getMember is context sensetive?

2015-06-13 Thread ketmar via Digitalmars-d-learn
On Sat, 13 Jun 2015 10:36:39 +, John Colvin wrote: > *for some reason it's not public, but it's very short and simple: it's funny how many useful things are there in Phobos, carefully hidden from user. i believe each D book should include an advice like this: "to fully learn what you can do

Re: Conditional Compilation Multiple Versions

2015-06-13 Thread ketmar via Digitalmars-d-learn
On Fri, 12 Jun 2015 20:41:59 -0400, bitwise wrote: > Is there a way to compile for multiple conditions? > > Tried all these: > > version(One | Two){ } > version(One || Two){ } > version(One && Two){ } > version(One) | version(Two){ } > version(One) || version(Two){ } > version(One) && version(T

Re: Conditional Compilation Multiple Versions

2015-06-13 Thread ketmar via Digitalmars-d-learn
On Sat, 13 Jun 2015 12:01:29 -0400, bitwise wrote: >> nope. Walter is against that, so we'll not have it, despite the >> triviality of the patch. > > Any idea what the rationale was for not allowing it? i don't remember. that murmuring about "it makes the code harder to read" goes beyond me, so

Re: Conditional Compilation Multiple Versions

2015-06-13 Thread ketmar via Digitalmars-d-learn
On Sat, 13 Jun 2015 13:49:49 +, anonymous wrote: > Taking it one step further: > > template Version(string name) > { > mixin(" > version("~name~") enum Version = true; > else enum Version = false; > "); > } > > static if(Version!"One" || Version!"Two") > { >

Re: how come is this legal? 'void fun(int){ }' ?

2015-06-13 Thread ketmar via Digitalmars-d-learn
On Sun, 14 Jun 2015 05:11:17 +, Maxim Fomin wrote: > On Sunday, 14 June 2015 at 01:20:39 UTC, Timothee Cour wrote: >> I understand this is legal for declaration wo definition (void >> fun(int);) >> but why allow this: >> void test(int){} ? > > Actually it is void test(int _param_0) { } > You

Re: __traits getMember is context sensetive?

2015-06-13 Thread ketmar via Digitalmars-d-learn
oh, seems that i managed to make everything even less understandable... signature.asc Description: PGP signature

Re: __traits getMember is context sensetive?

2015-06-13 Thread ketmar via Digitalmars-d-learn
On Sat, 13 Jun 2015 23:55:53 +, JDemler wrote: > After a bit of rethinking: > > I guess the compiler goes through 2 loops: > the first resolves __traits, the second does ctfe. > > That would explain this behavior. "a" is not present to the compiler > while it tries to resolve my __traits cal

Re: More type-flexible arrays?

2015-06-13 Thread ketmar via Digitalmars-d-learn
On Sun, 14 Jun 2015 06:12:29 +, Ozan wrote: > Hallo! > > Is it possible to create arrays which has more then one type, > f. ex. array[0] = 1; array[1] = "z"; array[2] = new clazz(), > > I tried "Variant", but it slow down heavily my app. it is possible. with Variant. ;-) chances are t

Re: More type-flexible arrays?

2015-06-13 Thread ketmar via Digitalmars-d-learn
p.s. faster weak typing solution is definitely possible if you'll narrow possible type set. but as i said, i'd not recommend to go this way. there can be dragon in the end. signature.asc Description: PGP signature

Re: __traits getMember is context sensetive?

2015-06-14 Thread ketmar via Digitalmars-d-learn
On Sun, 14 Jun 2015 09:46:54 +, JDemler wrote: > On Sunday, 14 June 2015 at 05:52:00 UTC, ketmar wrote: >> oh, seems that i managed to make everything even less understandable... > > Your code works perfectly and makes at least some sense to me. > Thank you. > > If i understand it correctly:

Re: __traits getMember is context sensetive?

2015-06-14 Thread ketmar via Digitalmars-d-learn
On Sun, 14 Jun 2015 10:29:08 +, anonymous wrote: > One important thing I didn't see stated clearly by anyone in here: > > CTFE may run at compile time but it follows the same rules as run time > evaluation (plus some restrictions). > > This means, you can't use dynamic values (e.g. function

Re: @property on free function for UFCS?

2015-06-14 Thread ketmar via Digitalmars-d-learn
On Sun, 14 Jun 2015 12:26:52 +, rcorre wrote: > Suppose I have a function defined like so: > > void foo(int i) { } > > intended to be called like: > > 5.foo > > Should it be labeled with @property? > Or is @property only for true member functions? only if you plan to use it like `foo = 5;

Re: @property on free function for UFCS?

2015-06-14 Thread ketmar via Digitalmars-d-learn
On Sun, 14 Jun 2015 18:21:39 +0200, Timon Gehr wrote: >> only if you plan to use it like `foo = 5;`. > > You can use it like that anyway. sure, but i'm talking about style, not about compiler demands. >> i.e. exactly like field variable. > > struct S{ > void delegate() dg; > } > > int m

Re: Casting MapResult

2015-06-15 Thread ketmar via Digitalmars-d-learn
On Mon, 15 Jun 2015 15:10:20 +, jmh530 wrote: you shouldn't cast it like that. use `std.array.array` to get the actual array. like this: import std.array; auto y = x.map!(a => exp(a)).array; the thing is that `map` returns so-called "lazy range". lazy ranges trying to not do any work

Re: Casting MapResult

2015-06-15 Thread ketmar via Digitalmars-d-learn
On Mon, 15 Jun 2015 17:07:55 +, jmh530 wrote: > I have a little bit of a follow up. > > After making the recommended changes, the function seems to work with > both static and dynamic arrays. I then noticed that all of the examples > for functions that pass arrays in http://dlang.org/function

Re: Does anyone get line numbers in stack traces on Linux?

2015-06-17 Thread ketmar via Digitalmars-d-learn
i have that. with GCD. ;-) signature.asc Description: PGP signature

Re: Defining constant values in struct

2015-06-17 Thread ketmar via Digitalmars-d-learn
On Wed, 17 Jun 2015 09:49:56 +0900, Mike Parker wrote: > On 6/17/2015 6:17 AM, tcak wrote: >> As far as I known, when I define a string with enum and it is used at >> different parts of code, that string is repeated again and again in >> executable file instead of passing a pointer to string. So,

Re: Are stack+heap classes possible in D?

2015-06-17 Thread ketmar via Digitalmars-d-learn
On Wed, 17 Jun 2015 06:02:46 +, WhatMeWorry wrote: > I guess the question would be why would one want a struct on the heap > and a class on the stack? Performance reasons? struct on the heap: some containers, for example, doing their own memory management. class on the stack: guaranteed de

is it safe to call `GC.removeRange` in dtor?

2015-06-27 Thread ketmar via Digitalmars-d-learn
is it safe to call `GC.removeRange` in dtor? i believe it should be safe, so one can perform various cleanups, but documentation says nothing about guarantees. signature.asc Description: PGP signature

Re: how to skip sub functions in __traits(allMembers)

2015-06-27 Thread ketmar via Digitalmars-d-learn
On Sat, 27 Jun 2015 16:28:40 +, BBaz wrote: > I try to build a symbol table: > > --- > module aveb; > > import std.stdio; > import std.algorithm.searching; > import std.ascii; > > void* [string] sig; > > void ana(alias mod)() > { > import std.traits; foreach(memb;__traits(allMembers,m

Re: Static constructors guaranteed to run?

2015-06-27 Thread ketmar via Digitalmars-d-learn
On Fri, 26 Jun 2015 22:00:51 +, Tofu Ninja wrote: > Are static constructors guaranteed to run if the module is imported? > Also are static constructors in templated types guaranteed to run for > every instantiation? Even if the instantiation is never actually used > outside of compile time cod

Re: Static constructors guaranteed to run?

2015-06-30 Thread ketmar via Digitalmars-d-learn
On Mon, 29 Jun 2015 02:19:54 +, Tofu Ninja wrote: > On Monday, 29 June 2015 at 02:07:57 UTC, ketmar wrote: >> On Sat, 27 Jun 2015 22:49:13 +, Tofu Ninja wrote: >> >>> On Saturday, 27 June 2015 at 22:20:40 UTC, ketmar wrote: 2. no. >>> >>> Hmm... any reason why? >> >> if instantiated

Re: Static constructors guaranteed to run?

2015-06-30 Thread ketmar via Digitalmars-d-learn
On Sat, 27 Jun 2015 22:49:13 +, Tofu Ninja wrote: > On Saturday, 27 June 2015 at 22:20:40 UTC, ketmar wrote: >> 2. no. > > Hmm... any reason why? p.s. note that static ctors are *intended* to run in runtime, not in compile time. if compiler decides that some code is not required in runtim

Re: Static constructors guaranteed to run?

2015-06-30 Thread ketmar via Digitalmars-d-learn
On Mon, 29 Jun 2015 03:10:44 +, Tofu Ninja wrote: > On Monday, 29 June 2015 at 02:31:18 UTC, ketmar wrote: >> yes. it doesn't do that now, afair, but i can't see any sense in >> running code that obviously does nothing, as it's owner is not used. >> module ctors was designed for such things --

Re: Static constructors guaranteed to run?

2015-06-30 Thread ketmar via Digitalmars-d-learn
On Sat, 27 Jun 2015 22:49:13 +, Tofu Ninja wrote: > On Saturday, 27 June 2015 at 22:20:40 UTC, ketmar wrote: >> 2. no. > > Hmm... any reason why? if instantiated template was not used in any code that makes into compiled binary, compiler is free to remove it with all it's ctors. it may do

Re: Static constructors guaranteed to run?

2015-06-30 Thread ketmar via Digitalmars-d-learn
p.s. also note that module can has several static ctors, i.e. this works fine: === z00.d === module z00; import std.stdio; static this () { writeln("ctor0"); } static this () { writeln("ctor1"); } === z01.d === module z01; import z00; void main () {} this prints: ctor0 ctor1 so you c

Re: Static constructors guaranteed to run?

2015-06-30 Thread ketmar via Digitalmars-d-learn
On Mon, 29 Jun 2015 10:19:33 +, Marc Schütz wrote: > On Monday, 29 June 2015 at 02:07:57 UTC, ketmar wrote: >> On Sat, 27 Jun 2015 22:49:13 +, Tofu Ninja wrote: >> >>> On Saturday, 27 June 2015 at 22:20:40 UTC, ketmar wrote: 2. no. >>> >>> Hmm... any reason why? >> >> if instantiat

Re: Packing enums

2015-07-01 Thread ketmar via Digitalmars-d-learn
On Monday, 29 June 2015 at 22:05:47 UTC, qznc wrote: Something like this: enum X { A, B, C }; enum Y { foo, bar, baz }; alias both = TwoEnums!(X,Y); static assert(both.sizeof == 1); both z; z.X = B; z.Y = bar; that's so easy that it's not even funny... enum X { A, B, C }; enum Y { foo, bar,

Re: is it safe to call `GC.removeRange` in dtor?

2015-07-01 Thread ketmar via Digitalmars-d-learn
thank you both. then i think that it should be explicitly stated in core.memory.

Re: Static constructors guaranteed to run?

2015-07-01 Thread ketmar via Digitalmars-d-learn
On Mon, 29 Jun 2015 17:22:17 +, Marc Schütz wrote: > On Monday, 29 June 2015 at 11:36:42 UTC, ketmar wrote: >> it doesn't, afair, but it's quite natural. if user type was throwed out >> as unused, it would be very strange to insist on keeping it's >> initialization code. > > Yes, but I would

Re: how to avoid "cycle detected"?

2015-07-01 Thread ketmar via Digitalmars-d-learn
On Wed, 01 Jul 2015 09:09:52 +, aki wrote: > Following code causes run-time error. > How can I use static this() without causing error? you currently can't, sorry. signature.asc Description: PGP signature

Re: Static constructors guaranteed to run?

2015-07-01 Thread ketmar via Digitalmars-d-learn
On Wed, 01 Jul 2015 09:42:31 +, Marc Schütz wrote: > The behaviour you expect makes more sense, for sure, but I was trying to > guess what the current implementation might be doing without actually > having to try it :-) ah, sorry. i was talking about "the ideal case with ideal compiler", no

Re: code review based on what I learned from D

2015-07-05 Thread ketmar via Digitalmars-d-learn
On Sun, 05 Jul 2015 06:53:34 +, Szabo Bogdan wrote: > For both of these issues I was told that swift is not Java and if the > situations that I described happens, you don't want to crash the user > app, because this will make the user unhappy. i completely agree. it's way better to keep going

Re: code review based on what I learned from D

2015-07-05 Thread ketmar via Digitalmars-d-learn
On Sun, 05 Jul 2015 19:01:59 +1200, Rikki Cattermole wrote: > Failing gracefully. Not something most developers do. usually that is not related. i mean that if program entered invalid state, it may be too late to save user data. it may be even undesirable to do so, as the data may be already co

Re: code review based on what I learned from D

2015-07-05 Thread ketmar via Digitalmars-d-learn
On Sun, 05 Jul 2015 21:39:23 +1200, Rikki Cattermole wrote: > Of course of course. > Valid options in failing gracefully include resetting the data and > informing the user. Also giving them an option to send a bug report to > the devs. > Point being, having it just fail on start each time is not

Re: FFMPEG Bindings

2015-07-06 Thread ketmar via Digitalmars-d-learn
On Mon, 06 Jul 2015 16:42:08 +, Per Nordlöw wrote: > How stable has the FFMPEG API since beginning 2015? don't know, but various players stop bundling ffmpeg long time ago. i assume that API is stable enough to stop worrying about it. warning. information deduced, but not checked. signatu

Re: FFMPEG Bindings

2015-07-06 Thread ketmar via Digitalmars-d-learn
p.s. "stop bundling" means "stop bundling their own private versions in source tree, and started to use system version" here. signature.asc Description: PGP signature

Re: Wrapping a C-style Array (Pointer + Length) in a Range Interface

2015-07-07 Thread ketmar via Digitalmars-d-learn
On Tue, 07 Jul 2015 12:36:09 +, Rikki Cattermole wrote: > I'm not aware of much docs regarding these sort of tricks. But I believe > it was Adam who originally discovered this little trick. > Atleast I'm pretty sure he is how I learnt about it. On D.learn as well. i bet this trick was planned

<    4   5   6   7   8   9   10   11   12   >