Legal operator overloading

2016-05-29 Thread Nicholas Wilson via Digitalmars-d-learn
Is it legal/possible to overload the unary * operator? Also is it legal/possible to individually overload the comparison operators and not return a bool? (Before you ask no I'm not crazy, I am trying to make a library solution to multiple address spaces for supporting OpenCL/CUDA in D, and

Re: String compare in words?

2016-05-29 Thread chmike via Digitalmars-d-learn
On average there would be less than 4 bytes remaining to compare. So a simple straightforward byte comparison should do the job efficiently.

Re: String compare in words?

2016-05-29 Thread chmike via Digitalmars-d-learn
On Sunday, 29 May 2016 at 20:40:52 UTC, qznc wrote: On Sunday, 29 May 2016 at 18:15:16 UTC, qznc wrote: On Sunday, 29 May 2016 at 17:38:17 UTC, Jonathan M Davis wrote: And if you're not simply comparing for equality, what are you looking to figure out? Without more information about what

Re: Read registry keys recursively

2016-05-29 Thread Era Scarecrow via Digitalmars-d-learn
On Sunday, 29 May 2016 at 16:46:34 UTC, Era Scarecrow wrote: you should see the problem. Here's the correct line! writeRegistryKeys(k.getKey(key.name())); this just occurred to me i tried to keep to the example but i shouldn't have. Since you already have the inner key, just pass

Re: String compare in words?

2016-05-29 Thread Stefan Koch via Digitalmars-d-learn
On Sunday, 29 May 2016 at 20:51:19 UTC, Seb wrote: On Sunday, 29 May 2016 at 20:40:52 UTC, qznc wrote: [...] Isn't that something that the compiler should optimize for you when you do an equality comparison? Is it really faster than ldc (with all optimzations turned on)? It can be faster

Re: full copies on assignment

2016-05-29 Thread John Nixon via Digitalmars-d-learn
On Friday, 27 May 2016 at 08:59:43 UTC, Marc Schütz wrote: Yes indeed it does. Thanks. Something in my version must have been different.

Re: String compare in words?

2016-05-29 Thread Seb via Digitalmars-d-learn
On Sunday, 29 May 2016 at 20:40:52 UTC, qznc wrote: On Sunday, 29 May 2016 at 18:15:16 UTC, qznc wrote: [...] Ok, to answer my own question, this looks good: bool string_cmp_opt(immutable(ubyte)[] x, immutable(ubyte)[] y) { pragma(inline, false); if (x.length != y.length) return

Re: String compare in words?

2016-05-29 Thread qznc via Digitalmars-d-learn
On Sunday, 29 May 2016 at 17:42:48 UTC, Era Scarecrow wrote: Worse I'm not sure if the code generation already does that and possibly does a better job than what we could do by hand... Not with dmd v2.071.0 or ldc 0.17.1. At least not in all the variations I tried to trick them with, like

Re: String compare in words?

2016-05-29 Thread qznc via Digitalmars-d-learn
On Sunday, 29 May 2016 at 18:15:16 UTC, qznc wrote: On Sunday, 29 May 2016 at 17:38:17 UTC, Jonathan M Davis wrote: And if you're not simply comparing for equality, what are you looking to figure out? Without more information about what you're trying to do, it's kind of hard to help you. If

Re: Keeping a mutable reference to a struct with immutable members

2016-05-29 Thread pineapple via Digitalmars-d-learn
On Sunday, 29 May 2016 at 19:52:37 UTC, Basile B. wrote: Do yo have a simple, concise runnable example to show ? This is the example I was using to test solutions, it's similar to where I encountered the problem in the first place import core.stdc.stdlib : malloc, free; import

Re: Keeping a mutable reference to a struct with immutable members

2016-05-29 Thread Basile B. via Digitalmars-d-learn
On Sunday, 29 May 2016 at 19:09:13 UTC, pineapple wrote: On Sunday, 29 May 2016 at 18:52:36 UTC, pineapple wrote: What's the best way to handle something like this? Well I did get something to work but it's ugly and I refuse to believe there isn't a better way to handle this. Where `Range`

Re: Keeping a mutable reference to a struct with immutable members

2016-05-29 Thread pineapple via Digitalmars-d-learn
On Sunday, 29 May 2016 at 18:52:36 UTC, pineapple wrote: What's the best way to handle something like this? Well I did get something to work but it's ugly and I refuse to believe there isn't a better way to handle this. Where `Range` is an alias to a struct with an immutable member, and

Keeping a mutable reference to a struct with immutable members

2016-05-29 Thread pineapple via Digitalmars-d-learn
I found another post on this subject and the advice there was "don't put const members in your structs" - http://forum.dlang.org/thread/m87ln2$idv$1...@digitalmars.com This doesn't work out so well when the templated struct is referring to what happens to be a const array. I thought I could

Re: String compare in words?

2016-05-29 Thread qznc via Digitalmars-d-learn
On Sunday, 29 May 2016 at 17:38:17 UTC, Jonathan M Davis wrote: And if you're not simply comparing for equality, what are you looking to figure out? Without more information about what you're trying to do, it's kind of hard to help you. If I write the comparison naively, the assembly clearly

Re: @trusting generic functions

2016-05-29 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/28/16 7:50 AM, Lodovico Giaretta wrote: Let's say I have a generic function that uses pointers. It will be inferred @system by the compiler, but I know that the pointer usage can be @trusted. The problem is that if I declare the function @trusted, I'm also implicitly trusting any call to

Re: String compare in words?

2016-05-29 Thread Era Scarecrow via Digitalmars-d-learn
On Sunday, 29 May 2016 at 17:38:17 UTC, Jonathan M Davis wrote: In what way are you trying to compare them? If all you're doing is comparing them for equality, then just use ==. e.g. if(str1 == str2) { } And if you're not simply comparing for equality, what are you looking to figure out?

Re: String compare in words?

2016-05-29 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, May 29, 2016 17:13:49 qznc via Digitalmars-d-learn wrote: > Given two string (or char[] or ubyte[]) objects, I want to > compare them. The naive loop accesses the arrays byte-wise. How > could I turn this into a word-wise compare for better performance? > > Is a cast into size_t[] ok?

Re: String compare in words?

2016-05-29 Thread Era Scarecrow via Digitalmars-d-learn
On Sunday, 29 May 2016 at 17:13:49 UTC, qznc wrote: Given two string (or char[] or ubyte[]) objects, I want to compare them. The naive loop accesses the arrays byte-wise. How could I turn this into a word-wise compare for better performance? Is a cast into size_t[] ok? Some Phobos helper

String compare in words?

2016-05-29 Thread qznc via Digitalmars-d-learn
Given two string (or char[] or ubyte[]) objects, I want to compare them. The naive loop accesses the arrays byte-wise. How could I turn this into a word-wise compare for better performance? Is a cast into size_t[] ok? Some Phobos helper functions?

Re: Read registry keys recursively

2016-05-29 Thread Era Scarecrow via Digitalmars-d-learn
On Sunday, 29 May 2016 at 15:48:49 UTC, TheDGuy wrote: Hello, i am wondering what is wrong with my code: import std.windows.registry; import std.stdio; void main(){ Key lclM = Registry.localMachine(); Key hrdw = lclM.getKey("HARDWARE"); writeRegistryKeys(hrdw); } void

Re: How to hash any type to an integer?

2016-05-29 Thread Seb via Digitalmars-d-learn
On Sunday, 29 May 2016 at 11:05:21 UTC, Gary Willoughby wrote: I'm currently implementing a hash map as an exercise and wondered if there is a built-in function I could use to hash keys effectively? What I'm looking for is a function that hashes any variable (of any type) to an integer. I've

Read registry keys recursively

2016-05-29 Thread TheDGuy via Digitalmars-d-learn
Hello, i am wondering what is wrong with my code: import std.windows.registry; import std.stdio; void main(){ Key lclM = Registry.localMachine(); Key hrdw = lclM.getKey("HARDWARE"); writeRegistryKeys(hrdw); } void writeRegistryKeys(Key k){ foreach(Key key; k.keys){

Re: D, GTK, Qt, wx,…

2016-05-29 Thread Max Samukha via Digitalmars-d-learn
On Sunday, 29 May 2016 at 11:03:36 UTC, Russel Winder wrote: From what I can tell QtD is in need of effort or restarting. I will probably give it another shot when D has better interop with C++. Particularly, when multiple inheritance of C++ interfaces is implemented, Walter admits that

Re: Why does std.container.array does not work with foraech( i, a; array ) {} ?

2016-05-29 Thread ParticlePeter via Digitalmars-d-learn
On Sunday, 29 May 2016 at 09:07:07 UTC, Jonathan M Davis wrote: On Sunday, May 29, 2016 07:14:12 ParticlePeter via Digitalmars-d-learn wrote: Which of the op(Index) operators is responsible for enabling this kind of syntax? Would it be possible to get it work with UFCS or would I have to

Re: D, GTK, Qt, wx,…

2016-05-29 Thread Jordi Sayol via Digitalmars-d-learn
El 29/05/16 a les 13:03, Russel Winder via Digitalmars-d-learn ha escrit: > GKT+ has a reputation for being dreadful on OSX and even worse on > Windows. Qt on the other hand has a reputation for being the most > portable – though clearly wx is (arguable) the most portable. > > We have GtkD which

Re: is my code to get CTFE instantiated object valid D ?

2016-05-29 Thread Steven Schveighoffer via Digitalmars-d-learn
On Sunday, 29 May 2016 at 05:43:31 UTC, Mike Parker wrote: On Sunday, 29 May 2016 at 05:35:33 UTC, Mike Parker wrote: Well then, this completely breaks my understanding of variable scope. OK, I see now at [1] the following: " Immutable data doesn't have synchronization problems, so the

Re: Why does std.container.array does not work with foraech( i, a; array ) {} ?

2016-05-29 Thread Mithun Hunsur via Digitalmars-d-learn
On Sunday, 29 May 2016 at 09:07:07 UTC, Jonathan M Davis wrote: On Sunday, May 29, 2016 07:14:12 ParticlePeter via Digitalmars-d-learn wrote: [...] std.container.array.Array works with foreach via ranges. foreach(e; myContainer) { } gets lowered to foreach(e; myContainer[]) { } which in

How to hash any type to an integer?

2016-05-29 Thread Gary Willoughby via Digitalmars-d-learn
I'm currently implementing a hash map as an exercise and wondered if there is a built-in function I could use to hash keys effectively? What I'm looking for is a function that hashes any variable (of any type) to an integer. I've been looking at the `getHash` function of the `TypeInfo` class

Re: Newbie to D, first impressions and feedback on the 5 (and more) first minutes.

2016-05-29 Thread Russel Winder via Digitalmars-d-learn
On Wed, 2016-05-25 at 13:57 +, qznc via Digitalmars-d-learn wrote: > On Wednesday, 25 May 2016 at 09:41:10 UTC, Russel Winder wrote: > > I do not really have the proper resources to host such a  > > repository and because of this I have not built one. I know I  > > should rather than just

D, GTK, Qt, wx,…

2016-05-29 Thread Russel Winder via Digitalmars-d-learn
GKT+ has a reputation for being dreadful on OSX and even worse on Windows. Qt on the other hand has a reputation for being the most portable – though clearly wx is (arguable) the most portable. We have GtkD which is brilliant, especially as it has GStreamer support. From what I can tell QtD is

Re: Why does std.container.array does not work with foraech( i, a; array ) {} ?

2016-05-29 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, May 29, 2016 07:14:12 ParticlePeter via Digitalmars-d-learn wrote: > Which of the op(Index) operators is responsible for enabling this > kind of syntax? > Would it be possible to get it work with UFCS or would I have to > wrap the array? std.container.array.Array works with foreach via

Re: is my code to get CTFE instantiated object valid D ?

2016-05-29 Thread chmike via Digitalmars-d-learn
On Sunday, 29 May 2016 at 06:49:42 UTC, chmike wrote: What is the right way to use it ? I answer to my self after testing so that people looking for that info can find it here. The right way would be immutable Category category_; Rebindable!(immutable Category) instance() { return

Weird "nested function cannot be accessed" error

2016-05-29 Thread Max Samukha via Digitalmars-d-learn
This code fails to compile: void bar(alias f)() { f(); } void foo(alias f)() { bar!f(); } void main() { void f()() { } foo!f(); } Error: function test.main.f!().f is a nested function and cannot be accessed from test.bar!(f).bar But non-template nested functions are

Re: Operator overloading through UFCS doesn't work

2016-05-29 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, May 27, 2016 09:08:20 Marc Schütz via Digitalmars-d-learn wrote: > On Thursday, 26 May 2016 at 06:23:17 UTC, Jonathan M Davis wrote: > > The difference is that it's impossible to do > > 10.opBinary!"+"(15), so if you're forced to do > > foo.opBinary!"+"(bar) to get around a symbol

Why does std.container.array does not work with foraech( i, a; array ) {} ?

2016-05-29 Thread ParticlePeter via Digitalmars-d-learn
Which of the op(Index) operators is responsible for enabling this kind of syntax? Would it be possible to get it work with UFCS or would I have to wrap the array?

Re: is my code to get CTFE instantiated object valid D ?

2016-05-29 Thread chmike via Digitalmars-d-learn
On Saturday, 28 May 2016 at 21:21:34 UTC, ag0aep6g wrote: On 05/28/2016 09:54 PM, chmike wrote: The only inconvenience left is that we can't have mutable references to immutable objects. There is std.typecons.Rebindable for that. That would be a good news. What is the right way to use it ?