Re: Check whether a range is empty

2018-07-17 Thread Gary Willoughby via Digitalmars-d-learn
On Friday, 13 July 2018 at 18:37:35 UTC, vino.B wrote: Hi All, How do i check whether a range is empty. eg. (!PFResutl.toRange).empty. I tired the below, but it is no printing Empty if the range is empty it just prints blank line. if (!(!PFResutl.toRange).empty) { writeln("Empty"); } Fro

Re: Is there a way to anonymously execute some sh script contents?

2018-08-01 Thread Gary Willoughby via Digitalmars-d-learn
On Wednesday, 1 August 2018 at 14:58:56 UTC, Ky-Anh Huynh wrote: This works well with user interaction. However I don't really like the idea of using temporary files. Is there any better way? Maybe take a look at: https://dlang.org/library/std/process/pipe_shell.html

Why do some attributes have an @ symbol and others don't?

2018-09-15 Thread Gary Willoughby via Digitalmars-d-learn
Why do some attributes have an @ symbol and others don't? I thought it might be because some are used as keywords for other things but then 'pure' doesn't follow that rule. Any ideas? Is it just a legacy thing?

Re: Converting a character to upper case in string

2018-09-21 Thread Gary Willoughby via Digitalmars-d-learn
On Friday, 21 September 2018 at 12:15:52 UTC, NX wrote: How can I properly convert a character, say, first one to upper case in a unicode correct manner? In which code level I should be working on? Grapheme? Or maybe code point is sufficient? There are few phobos functions like asCapitalized()

Re: Which Docker to use?

2018-10-17 Thread Gary Willoughby via Digitalmars-d-learn
On Wednesday, 17 October 2018 at 03:37:21 UTC, Ky-Anh Huynh wrote: Hi, I need to build some static binaries with LDC. I also need to execute builds on both platform 32-bit and 64-bit. From Docker Hub there are two image groups: * language/ldc (last update 5 months ago) * dlang2/ldc-ubuntu (

Re: How do I install a library?

2018-11-09 Thread Gary Willoughby via Digitalmars-d-learn
On Friday, 9 November 2018 at 00:18:28 UTC, H. S. Teoh wrote: It's not true that you're stuck with dub. And I'm not among the people who think dub is the way to go (though it's true that that's a minority opinion around here). Where I have a choice, my own D projects do not use dub. Me neit

Re: D vs perl6

2018-11-22 Thread Gary Willoughby via Digitalmars-d-learn
On Monday, 19 November 2018 at 06:46:55 UTC, dangbinghoo wrote: So, can you experts give a more comprehensive compare with perl6 and D? Sure! 1). You can actually read and understand D code.

Re: C style 'static' functions

2017-07-19 Thread Gary Willoughby via Digitalmars-d-learn
On Wednesday, 19 July 2017 at 07:22:48 UTC, John Burton wrote: In C++ I could use static or an anonymous namespace for implementation functions, but there doesn't seem to be anything similar in D. Is there any way to achieve what I want in D (Private implementation functions) Try the package

Re: What does ! mean?

2017-09-27 Thread Gary Willoughby via Digitalmars-d-learn
On Wednesday, 27 September 2017 at 14:23:01 UTC, Ky-Anh Huynh wrote: Can you please explain and give any link where I can learn more about these things? Thanks a lot. http://nomad.so/2013/07/templates-in-d-explained/

Re: Does dmd not always compile all of the source code?

2017-12-06 Thread Gary Willoughby via Digitalmars-d-learn
On Wednesday, 6 December 2017 at 16:47:17 UTC, A Guy With a Question wrote: abstract class Test(T) { private: T thing; public: this(T theThing) { thing = theThing; thisdoesnotexist(); // expect compiler error right here } } ...but this compiles just fine. I

Re: Garbage collected pointers?

2018-03-01 Thread Gary Willoughby via Digitalmars-d-learn
On Thursday, 1 March 2018 at 10:10:27 UTC, John Burton wrote: My question is how do I tell if a pointer is "garbage collected" or not? You could try `GC.addrOf()` or `GC.query()` in core.memory.

Re: Garbage collected pointers?

2018-03-02 Thread Gary Willoughby via Digitalmars-d-learn
On Thursday, 1 March 2018 at 12:20:08 UTC, Steven Schveighoffer wrote: On 3/1/18 7:05 AM, Gary Willoughby wrote: On Thursday, 1 March 2018 at 10:10:27 UTC, John Burton wrote: My question is how do I tell if a pointer is "garbage collected" or not? You could try `GC.addrOf()` or `GC.query()` i

Re: Garbage collected pointers?

2018-03-02 Thread Gary Willoughby via Digitalmars-d-learn
On Friday, 2 March 2018 at 08:44:53 UTC, Gary Willoughby wrote: It would be interesting to test whether those methods handle these scenarios. Yeah, it doesn't work. https://dpaste.dzfl.pl/55116efd0c9c

Re: DMD Compiler 'switches'

2015-10-12 Thread Gary Willoughby via Digitalmars-d-learn
On Monday, 12 October 2015 at 15:38:27 UTC, ric maicle wrote: I'm relearning D. I'm using the reference compiler (DMD) and I am a bit confused with how the compiler 'switches' are supposed to be used. I find some 'switches' that require an equal (=) symbol when a value is required to be passe

Writing a screen saver in D what libraries will help?

2015-10-12 Thread Gary Willoughby via Digitalmars-d-learn
If I was writing a screensaver in D what libraries are available for opening a window and drawing sprites, etc on it. GPU accelerated if possible. I'm using Ubuntu 14.04 and latest DMD compiler.

Re: Writing a screen saver in D what libraries will help?

2015-10-12 Thread Gary Willoughby via Digitalmars-d-learn
On Monday, 12 October 2015 at 19:16:10 UTC, Gary Willoughby wrote: If I was writing a screensaver in D what libraries are available for opening a window and drawing sprites, etc on it. GPU accelerated if possible. I'm using Ubuntu 14.04 and latest DMD compiler. I've found Dgame which looks s

How to install DMD 64bit on Windows?

2015-10-21 Thread Gary Willoughby via Digitalmars-d-learn
How to install DMD 64bit on Windows? Is it just a case of downloading from here and it just works? http://dlang.org/download.html Or do I need Visual Studio installed?

Re: How can I distinguish an enum constant from an actual enum at compile time?

2015-10-30 Thread Gary Willoughby via Digitalmars-d-learn
On Friday, 30 October 2015 at 12:03:50 UTC, TheFlyingFiddle wrote: pragma(msg, is(b == enum)); //True pragma(msg, is(a == enum)); //False. enum isEnum(alias e) = is(e == enum); isEnum!(a) isEnum!(b) ;)

Re: How can I distinguish an enum constant from an actual enum at compile time?

2015-10-30 Thread Gary Willoughby via Digitalmars-d-learn
On Friday, 30 October 2015 at 12:18:21 UTC, Gary Willoughby wrote: On Friday, 30 October 2015 at 12:03:50 UTC, TheFlyingFiddle wrote: pragma(msg, is(b == enum)); //True pragma(msg, is(a == enum)); //False. enum isEnum(alias e) = is(e == enum); isEnum!(a) isEnum!(b) ;) isEnum!(isEnum)

Re: Capturing __FILE__ and __LINE in a variadic templated function

2015-11-02 Thread Gary Willoughby via Digitalmars-d-learn
On Monday, 2 November 2015 at 08:23:16 UTC, Nordlöw wrote: I need `T` to be an alias in order for .stringof to work. typeof(T).stringof

Re: Associative array with duplicated keys?

2015-11-05 Thread Gary Willoughby via Digitalmars-d-learn
On Thursday, 5 November 2015 at 10:04:02 UTC, Andrea Fontana wrote: Anyway: are duplicated keys on declaration allowed? IMHO This should at least be a warning.

Re: @property

2015-11-10 Thread Gary Willoughby via Digitalmars-d-learn
On Monday, 9 November 2015 at 22:42:16 UTC, Fyodor Ustinov wrote: If this feature will be removed, it will be very lacking code, like: writeln = "Hello, world!"; :) WBR, Fyodor. The feature is not being removed. Only the @property attribute and compiler check is being removed.

Re: When a variable is passed into a function, is its name kept somewhere for the function to acceess

2015-11-10 Thread Gary Willoughby via Digitalmars-d-learn
On Tuesday, 10 November 2015 at 14:14:33 UTC, DlangLearner wrote: Please enlighten me if this can be done, thanks. If i understand you, you could use a templated function: import std.stdio; void foo(alias a)() { writefln("%s was passed in.", a.stringof); } void main(string[] args) {

Re: How to use readText to read utf16 file?

2015-11-17 Thread Gary Willoughby via Digitalmars-d-learn
On Tuesday, 17 November 2015 at 02:40:14 UTC, Domain wrote: How to use readText to read utf16 file? Or other encoding file. Here's a helpful resource when working with text files in D. http://nomad.so/2015/09/working-with-files-in-the-d-programming-language/

Re: TreeViews in tkd

2015-12-17 Thread Gary Willoughby via Digitalmars-d-learn
On Thursday, 17 December 2015 at 09:47:42 UTC, TheGag96 wrote: I've been trying to get into tkd to make some GUI apps, since it looked like the simplest/intuitive library out there so far. I've been attempting to use their TreeViews to make interactable lists of things, but it almost looks like

Is this an rvalue reference problem?

2015-12-27 Thread Gary Willoughby via Digitalmars-d-learn
See the following code: import std.stdio; void foo(ref int x) { writefln("%s", x); } void main(string[] args) { int y = 0; foo(y++); } When compiled it produces this error: test.d(11): Error: function test.foo (ref int x) is not callable using argument types (int) I

Is it possible to elegantly create a range over a binary heap?

2015-12-27 Thread Gary Willoughby via Digitalmars-d-learn
I have a binary tree storing ints implemented using an array. The internal state looks like this: 8,7,6,4,1,3,5,2 When extracting this data, it is returned as 8,7,6,5,4,3,2,1. Is it possible to elegantly add a range on top of the internal state to return the correct value order I would expect

Re: Is it possible to elegantly create a range over a binary heap?

2015-12-27 Thread Gary Willoughby via Digitalmars-d-learn
On Sunday, 27 December 2015 at 17:23:35 UTC, Gary Willoughby wrote: I have a binary tree storing ints implemented using an array. The internal state looks like this: 8,7,6,4,1,3,5,2 When extracting this data, it is returned as 8,7,6,5,4,3,2,1. Is it possible to elegantly add a range on top of

Re: Is this an rvalue reference problem?

2015-12-27 Thread Gary Willoughby via Digitalmars-d-learn
On Sunday, 27 December 2015 at 18:54:25 UTC, Adam D. Ruppe wrote: On Sunday, 27 December 2015 at 16:05:39 UTC, Gary Willoughby wrote: [...] Yes, but more than that, what, exactly, would you expect from that? The order of operations with the postfix ++ operator and ref would probably lead to

Re: Is it possible to elegantly create a range over a binary heap?

2015-12-28 Thread Gary Willoughby via Digitalmars-d-learn
On Sunday, 27 December 2015 at 22:42:21 UTC, Ivan Kazmenko wrote: If you implement a struct with range primitives over it, you can use it as a range. See the second code example in std.container.binaryheap's docs at http://dlang.org/phobos/std_container_binaryheap.html#.BinaryHeap. Or do you

Re: Is it possible to elegantly create a range over a binary heap?

2015-12-28 Thread Gary Willoughby via Digitalmars-d-learn
On Monday, 28 December 2015 at 14:05:42 UTC, Ivan Kazmenko wrote: 1. You can find maximum, then second maximum, then third maximum and so on - each in constant memory and linear time. So, if performance is somehow not an issue, there is a way to do it @nogc but in N^2 operations. That's perh

Re: Call C function - Access violation

2016-01-03 Thread Gary Willoughby via Digitalmars-d-learn
On Sunday, 3 January 2016 at 12:30:34 UTC, TheDGuy wrote: I get an access violation with this code: ... There are a few things you can do to improve your code to make it easier to debug. 1. When converting a D string to a char pointer for use with C, use `std.string.toStringz`: http://dl

Re: Call C function - Access violation

2016-01-03 Thread Gary Willoughby via Digitalmars-d-learn
On Sunday, 3 January 2016 at 13:23:25 UTC, Gary Willoughby wrote: I think I've noticed one problem with the code above. You are using `text.ptr`. You shouldn't do that because you are passing a pointer not an array. Just use `text`. Forget this line, my mistake. Use `toStringz` and pass a poin

Re: Call C function - Access violation

2016-01-03 Thread Gary Willoughby via Digitalmars-d-learn
On Sunday, 3 January 2016 at 19:24:46 UTC, TheDGuy wrote: On Sunday, 3 January 2016 at 13:25:04 UTC, Gary Willoughby wrote: On Sunday, 3 January 2016 at 13:23:25 UTC, Gary Willoughby wrote: I think I've noticed one problem with the code above. You are using `text.ptr`. You shouldn't do that bec

Re: GC greediness

2016-01-05 Thread Gary Willoughby via Digitalmars-d-learn
On Tuesday, 5 January 2016 at 17:20:07 UTC, Justin Whear wrote: On Tue, 05 Jan 2016 16:07:36 +, Jack Applegame wrote: On a server with 4GB of RAM our D application consumes about 1GB. Today we have increased server memory to 6 Gb and the same application under the same conditions began to

Re: A few range questions

2016-01-05 Thread Gary Willoughby via Digitalmars-d-learn
On Tuesday, 5 January 2016 at 18:47:30 UTC, Charles Smith wrote: 1. `arr[].sort` is changing arr in place. Any way to not do that? Use this instead: auto result = sort(arr[].dup); .dup duplicates the array and sort(...) uses the std.algorithm sort and not the built-in array sort method. 2.

Re: [Dlang] Delegate Syntax Question

2016-01-10 Thread Gary Willoughby via Digitalmars-d-learn
On Sunday, 10 January 2016 at 14:32:02 UTC, Jack wrote: ... Just to make your code a little more clear, try using aliases when defining delegate parameters. Like this: alias Action = void delegate(); Then in your code you use the alias, like this: class Bar() { private Action _action;

Re: How can i track the GC when it's runing?

2016-01-25 Thread Gary Willoughby via Digitalmars-d-learn
On Monday, 25 January 2016 at 09:33:15 UTC, Dsby wrote: I want to know How can i track the GC when it's runing? And Which algorithm is D's GC used,only Scan-Mark? There is a good resource here: https://dlang.org/spec/garbage.html It details compiler flags to use to profile and log the GC usa

Re: What is the best declaration type for a string like parameter?

2016-01-28 Thread Gary Willoughby via Digitalmars-d-learn
On Thursday, 28 January 2016 at 15:10:38 UTC, Adam D. Ruppe wrote: On Thursday, 28 January 2016 at 13:36:46 UTC, Puming wrote: I searched the forum and found that people use `const(char)[]` or `in char[]` to accept both string and char[] arguments. There's also the hyper-generic signatures Pho

Re: Call D from TCL

2016-02-03 Thread Gary Willoughby via Digitalmars-d-learn
On Wednesday, 3 February 2016 at 12:20:42 UTC, Vasileios Anagnostopoulos wrote: Is there any example,framework or tutorial on how to call D from Tcl (write new commands in D for Tcl)? I am on Windows 10 x86_64. thank you. I've created a wrapper around Tcl/Tk to create GUI's here: https://gi

Re: Call D from TCL

2016-02-03 Thread Gary Willoughby via Digitalmars-d-learn
On Wednesday, 3 February 2016 at 14:19:32 UTC, Vasileios Anagnostopoulos wrote: Thank you very much. I investigate Tcl_CmdProc more closely. On Wed, Feb 3, 2016 at 3:50 PM, Gary Willoughby via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: On Wednesday, 3 February 2

Re: How do you check if object o has base type B?

2016-02-04 Thread Gary Willoughby via Digitalmars-d-learn
On Thursday, 4 February 2016 at 05:51:22 UTC, Enjoys Math wrote: Consider: class C { } class B : C { } class A : B { } class D : C { } C[] objList; how do we test if objLis[k] is of base type "B"? Ie for [new A(), new B(), new D(), new C()] would give output [true, true, false, false]

Re: Printing a C "string" with write(f)ln

2016-02-09 Thread Gary Willoughby via Digitalmars-d-learn
On Tuesday, 9 February 2016 at 12:50:27 UTC, Jakob Ovrum wrote: writefln et al sensibly does *not* assume that a pointer to char is a C string, for memory safety purposes. Print the result of std.string.fromStringz[1] instead: writeln(fromStringz(pString)); writefln("%s", fromStringz(pString))

Re: Printing a C "string" with write(f)ln

2016-02-09 Thread Gary Willoughby via Digitalmars-d-learn
On Tuesday, 9 February 2016 at 16:58:03 UTC, Daniel Kozak wrote: Or use `to` like this: import std.conv; writefln("%s", pString.to!(string)); this will allocate new string which can be performance problem. Which is good in most cases. It's better to have the GC take care of the D string ins

Re: Printing a C "string" with write(f)ln

2016-02-09 Thread Gary Willoughby via Digitalmars-d-learn
On Tuesday, 9 February 2016 at 17:02:28 UTC, Jakob Ovrum wrote: to!string behaving like that was a poor design choice[1]. Please use fromStringz. [1] https://github.com/D-Programming-Language/phobos/pull/1607 It's not a poor design choice. It ensures the string is handled by the D GC instead

Re: Printing a C "string" with write(f)ln

2016-02-10 Thread Gary Willoughby via Digitalmars-d-learn
On Wednesday, 10 February 2016 at 07:20:03 UTC, Jakob Ovrum wrote: You clearly didn't read the discussion in the link. I did and I fully agree with jmdavis.

Re: Three Cool Things about D?

2016-03-02 Thread Gary Willoughby via Digitalmars-d-learn
On Tuesday, 1 March 2016 at 20:26:36 UTC, Ali Çehreli wrote: On 03/01/2016 12:17 PM, Wulfrick wrote: On Tuesday, 1 March 2016 at 20:15:00 UTC, Wulfrick wrote: It looks like the link in wiki.dlang.org/Videos to Andrei's "Three Cool Things about D" is dead. Do you know of another link? Maybe

Re: D GUI Toolkit Comparison

2016-04-29 Thread Gary Willoughby via Digitalmars-d-learn
On Friday, 29 April 2016 at 13:52:59 UTC, Nordlöw wrote: Could somebody briefly outline the different GUI toolkits available in D and how they differ especially in terms of cleverly the make use of all idioms available in the language aswell as in Phobos. For instance: DlangUI and Adams D Rup

Re: Accepting function or delegate as function argument

2016-05-06 Thread Gary Willoughby via Digitalmars-d-learn
On Wednesday, 4 May 2016 at 15:23:20 UTC, Rene Zwanenburg wrote: On Wednesday, 4 May 2016 at 14:54:39 UTC, chmike wrote: Two constructors, one accepting a function and the other one accepting a delegate would do the job for the API. Is there a simple method to convert a function pointer into a

Re: D equivalent of C++ bind ?

2016-05-10 Thread Gary Willoughby via Digitalmars-d-learn
On Tuesday, 10 May 2016 at 09:39:53 UTC, chmike wrote: Is there an equivalent in D of the C++11 std.bind template class See http://dlang.org/phobos/std_functional.html#partial

Is there an easy way to convert a pointer to malloc'd memory to an array?

2016-05-24 Thread Gary Willoughby via Digitalmars-d-learn
I have a T* pointer to the start of a malloc'd chunk of memory, the type T and the number of T's stored in the chunk. Is there an efficient way of converting this information to a D array of type T[] or even T[n]?

Re: Is there an easy way to convert a pointer to malloc'd memory to an array?

2016-05-24 Thread Gary Willoughby via Digitalmars-d-learn
On Tuesday, 24 May 2016 at 18:43:22 UTC, Adam D. Ruppe wrote: On Tuesday, 24 May 2016 at 18:42:41 UTC, Gary Willoughby wrote: I have a T* pointer to the start of a malloc'd chunk of memory, the type T and the number of T's stored in the chunk. Is there an efficient way of converting this infor

Re: Is there a way to clear an OutBuffer?

2016-05-25 Thread Gary Willoughby via Digitalmars-d-learn
On Monday, 23 May 2016 at 03:03:12 UTC, Jon Degenhardt wrote: Currently not possible. Enhancement request perhaps? Looking at the implementation, setting its 'offset' member seems to work. Based on example from documentation: import std.outbuffer; void main() { OutBuffer b = new OutBuffe

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: How to hash any type to an integer?

2016-05-30 Thread Gary Willoughby via Digitalmars-d-learn
On Sunday, 29 May 2016 at 16:26:58 UTC, Seb wrote: 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 hash

Is there any overhead iterating over a pointer using a slice?

2016-05-31 Thread Gary Willoughby via Digitalmars-d-learn
In relation to this thread: http://forum.dlang.org/thread/ddckhvcxlyuvuiyaz...@forum.dlang.org Where I asked about slicing a pointer, I have another question: If I have a pointer and iterate over it using a slice, like this: T* foo = &data; foreach (element; foo[0 .. length])

Re: Is there any overhead iterating over a pointer using a slice?

2016-06-01 Thread Gary Willoughby via Digitalmars-d-learn
On Tuesday, 31 May 2016 at 20:52:20 UTC, Johan Engelen wrote: On Tuesday, 31 May 2016 at 18:55:18 UTC, Gary Willoughby wrote: If I have a pointer and iterate over it using a slice, like this: T* foo = &data; foreach (element; foo[0 .. length]) { ...

Re: D, GTK, Qt, wx,…

2016-06-04 Thread Gary Willoughby via Digitalmars-d-learn
On Saturday, 4 June 2016 at 08:27:53 UTC, Russel Winder wrote: On Sun, 2016-05-29 at 14:01 +0200, Jordi Sayol via Digitalmars-d-learn wrote: […] https://github.com/nomad-software/tkd I am not a great fan of tk even in Python. It is true that Tk is everywhere and so meets the portability r

Creating a reference counted type?

2016-06-12 Thread Gary Willoughby via Digitalmars-d-learn
I'm wondering if it's this easy to create a reference counted type: struct Foo { int _refCount = 1; this(...) { // allocate resources, etc. } this(this) { this._refCount++; } ~this() {

Re: Creating a reference counted type?

2016-06-12 Thread Gary Willoughby via Digitalmars-d-learn
On Sunday, 12 June 2016 at 14:29:19 UTC, Gary Willoughby wrote: Another thing that is puzzling me is that when creating an instance of the above struct and passing as an argument to a function, the copy constructor is called and the reference count is incremented. This is expected. However, whe

Re: Creating a reference counted type?

2016-06-12 Thread Gary Willoughby via Digitalmars-d-learn
On Sunday, 12 June 2016 at 14:45:12 UTC, ketmar wrote: ahem... wut?! we have one copy of our struct freed half the way, and another copy has refcount of 2, so it won't be freed at all. it doesn't so innocent as it looks: we may try to use `f` in `main`... just to find out that resources was my

Re: Creating a reference counted type?

2016-06-12 Thread Gary Willoughby via Digitalmars-d-learn
On Sunday, 12 June 2016 at 15:05:53 UTC, ketmar wrote: this is basically how refcounted structs are done. note that i just typed the code into reply box, so it may not compile or contain some small bugs, but i think you got the idea. Thanks for the replies guys.

Default initialization of structs?

2016-06-17 Thread Gary Willoughby via Digitalmars-d-learn
I have a struct where I need to perform default initialization of some members but the compiler doesn't allow to define a default constructor which allow optional arguments. struct Foo(T) { private int _bar; this(int bar = 1) { this._bar = bar; } } auto foo = Foo!(stri

Re: Default initialization of structs?

2016-06-17 Thread Gary Willoughby via Digitalmars-d-learn
On Friday, 17 June 2016 at 10:53:40 UTC, Lodovico Giaretta wrote: struct Foo(T) { private int _bar = 1; this(int bar) { this._bar = bar; } } auto foo = Foo!(string)(); This should do the trick. Thanks, I forgot to mention I'm also doing lots of other stuff in the con

Is there a more elegant way of testing T for multiple types?

2016-06-18 Thread Gary Willoughby via Digitalmars-d-learn
Here I'm testing T is either a class or interface: void foo(T)(T bar) if (is(T == class) || is(T == interface)) { ... } Is there a more elegant way of testing T for multiple types? Because it doesn't scale well if I need to add more. I would love to use something like this: void foo(T)(T

Is it possible to create a static factory method on a templated struct?

2016-06-18 Thread Gary Willoughby via Digitalmars-d-learn
I've tried the following code and I get the error: Error: template Foo(A) does not have property 'of' struct Foo(A) { private int _foo; @disable this(); public this(int foo) { this._foo = foo; } public static auto of(B)()

Why do I get this error when casting to an immutable or shared byRef return type?

2016-06-19 Thread Gary Willoughby via Digitalmars-d-learn
In the following code, the `foo` function doesn't work when casting to an immutable or shared type. Can anyone please explain what is happening here? Is there any way of returning such variables byRef from a malloc'd chunk of memory? import core.stdc.stdlib; ref T foo(T)() { int* foo

Re: Why do I get this error when casting to an immutable or shared byRef return type?

2016-06-19 Thread Gary Willoughby via Digitalmars-d-learn
On Sunday, 19 June 2016 at 10:35:59 UTC, Gary Willoughby wrote: ... A more correct example: import core.stdc.stdlib; import std.traits; ref T foo(T)() { alias Type = Unqual!(T); Type* foo = cast(Type*) malloc(Type.sizeof * 8); return *foo; } void main(string[] args)

What exactly does the compiler switch -betterC do?

2016-06-19 Thread Gary Willoughby via Digitalmars-d-learn
When compiling, what exactly does the -betterC flag do? The command help says "omit generating some runtime information and helper functions" but what does this really mean? Is there any specifics somewhere?

Is there anyway to make opApply @nogc?

2016-06-20 Thread Gary Willoughby via Digitalmars-d-learn
Is there any way to make opApply @nogc? or provide the same foreach functionality without implementing a range interface? I want to iterate over a piece of memory using a pointer. I thought about using opSlice but that doesn't provide information for an index in a foreach loop. auto opSlice(

Re: Is there anyway to make opApply @nogc?

2016-06-20 Thread Gary Willoughby via Digitalmars-d-learn
On Monday, 20 June 2016 at 14:34:33 UTC, Mathias Lang wrote: Can't `opApply` with `auto` return type works since it infers attributes ? I think the problem is that the delegate which is required by opApply is allocated using the GC.

Re: Is there anyway to make opApply @nogc?

2016-06-20 Thread Gary Willoughby via Digitalmars-d-learn
On Monday, 20 June 2016 at 15:27:32 UTC, Adam D. Ruppe wrote: On Monday, 20 June 2016 at 15:13:53 UTC, Gary Willoughby wrote: I think the problem is that the delegate which is required by opApply is allocated using the GC. make the delegate in opApply scope int opApply(scope int delegate(what

Re: Is there anyway to make opApply @nogc?

2016-06-20 Thread Gary Willoughby via Digitalmars-d-learn
On Monday, 20 June 2016 at 15:47:44 UTC, Gary Willoughby wrote: On Monday, 20 June 2016 at 15:27:32 UTC, Adam D. Ruppe wrote: On Monday, 20 June 2016 at 15:13:53 UTC, Gary Willoughby wrote: I think the problem is that the delegate which is required by opApply is allocated using the GC. make t

Re: Is there anyway to make opApply @nogc?

2016-06-21 Thread Gary Willoughby via Digitalmars-d-learn
On Monday, 20 June 2016 at 15:27:32 UTC, Adam D. Ruppe wrote: On Monday, 20 June 2016 at 15:13:53 UTC, Gary Willoughby wrote: I think the problem is that the delegate which is required by opApply is allocated using the GC. make the delegate in opApply scope int opApply(scope int delegate(what

Re: Is there anyway to make opApply @nogc?

2016-06-21 Thread Gary Willoughby via Digitalmars-d-learn
On Tuesday, 21 June 2016 at 12:53:11 UTC, Adam D. Ruppe wrote: On Tuesday, 21 June 2016 at 12:48:04 UTC, Gary Willoughby wrote: I have no idea what that means. Can anyone shed more light on this, please? So when you use local variables in a delegate, the compiler usually makes a copy of them

Re: Is there anyway to make opApply @nogc?

2016-06-22 Thread Gary Willoughby via Digitalmars-d-learn
On Wednesday, 22 June 2016 at 13:36:54 UTC, Marc Schütz wrote: On Tuesday, 21 June 2016 at 19:21:01 UTC, Gary Willoughby wrote: Right ok, thanks! It doesn't seem to help though as the compiler complains about it being not @nogc. You probably need to declare the delegate and opApply() itself a

Re: Endiannes & Splitting Values

2016-07-07 Thread Gary Willoughby via Digitalmars-d-learn
On Wednesday, 6 July 2016 at 21:44:37 UTC, BitGuy wrote: I'm trying to implement a feistel cipher that'll give the same results regardless of the endianness of the machine it runs on. To make the cipher I need to split a 64bit value into two 32bit values, mess with them, and then put them back

Re: Endiannes & Splitting Values

2016-07-07 Thread Gary Willoughby via Digitalmars-d-learn
On Thursday, 7 July 2016 at 08:21:53 UTC, Lodovico Giaretta wrote: Are you sure that this works in both big-endian and little-endian systems? It shouldn't matter. You're just interested in the high and low 4 byte chunks (which are to be interpreted as an int) which will return in the relevant

Re: Endiannes & Splitting Values

2016-07-07 Thread Gary Willoughby via Digitalmars-d-learn
On Thursday, 7 July 2016 at 10:48:56 UTC, Lodovico Giaretta wrote: On Thursday, 7 July 2016 at 10:45:12 UTC, Gary Willoughby wrote: On Thursday, 7 July 2016 at 08:21:53 UTC, Lodovico Giaretta wrote: Are you sure that this works in both big-endian and little-endian systems? It shouldn't matter

Trailing commas in constructor arguments?

2014-05-04 Thread Gary Willoughby via Digitalmars-d-learn
In the following snippet is the line marked WOAH legal? The compiler doesn't complain about the trailing comma in the constructor arguments. import std.stdio; class Foo { public this(string foo) { } } void main(string[] args) { auto foo = new Foo("bar", ); // <

How to make sure GC allocated resources stay around when used in C functions?

2014-05-12 Thread Gary Willoughby via Digitalmars-d-learn
Based on this conversation in another thread: http://forum.dlang.org/thread/wdddgiowaidcojbrk...@forum.dlang.org?page=5#post-yjmrqgesjtadecutvkye:40forum.dlang.org I've realised i may have a nasty bug lurking in the code. Now i want to completely understand what is happening. Take the followin

Re: How to make sure GC allocated resources stay around when used in C functions?

2014-05-12 Thread Gary Willoughby via Digitalmars-d-learn
On Monday, 12 May 2014 at 19:13:28 UTC, Kagamin wrote: AFAIK, addRoot is for memory allocated in GC heap, and addRange is for other types of memory, so you can't add non-gc memory as root (just a guess, see docs). I would allocate whole Args in GC heap and add is as root, yes, it would prevent

Re: How to make sure GC allocated resources stay around when used in C functions?

2014-05-12 Thread Gary Willoughby via Digitalmars-d-learn
On Monday, 12 May 2014 at 20:03:46 UTC, Kagamin wrote: Why many? I'd say, you typically have 0 subscriptions (label, textbox) per widget, seldom - 1 (button, combobox, checkbox). There are many events that can be bound to on any widget. https://github.com/nomad-software/tkd/blob/master/source/t

Re: How to make sure GC allocated resources stay around when used in C functions?

2014-05-13 Thread Gary Willoughby via Digitalmars-d-learn
On Tuesday, 13 May 2014 at 06:27:14 UTC, Kagamin wrote: Do you always bind all of them? They are not bound automatically but may be bound later. You can bind to events such as mouse-enter, mouse-click, keypresses, etc. In fact this is how keyboard shortcuts are handled. I've added a potenti

Re: DFL is the best UIcontrols for D,compare it to dwt, tkd,dtk,dlangui,anchovy......

2014-05-13 Thread Gary Willoughby via Digitalmars-d-learn
On Tuesday, 13 May 2014 at 20:42:11 UTC, jack death wrote: "It would be cool if somebody will handle developing of DFL. It's better to have one such toolkit, than tons of complex and not finished toolkits." Tkd is finished. Gtk-D is finished. You aren't going to get very far unless you actual

Re: How to make sure GC allocated resources stay around when used in C functions?

2014-05-14 Thread Gary Willoughby via Digitalmars-d-learn
On Wednesday, 14 May 2014 at 07:11:45 UTC, Kagamin wrote: It must be scanned, so you shouldn't specify NO_SCAN attribute, it's for memory blocks, which are guaranteed to not hold pointers to GC memory, like ubyte[] buffers for i/o, so managed blocks can be safely collected without looking at co

Re: TKD set focus on window?

2014-05-14 Thread Gary Willoughby via Digitalmars-d-learn
On Wednesday, 14 May 2014 at 17:08:21 UTC, Joakim wrote: Hi, Quick question regarding TKD (tkinter): Is there a way to set focus on the application window automatically on run? I'm on Mac OS X if that's of any importance. I have tried to grep the documentation but I can't find anything rel

Re: TKD AddProtocolCommand example

2014-05-14 Thread Gary Willoughby via Digitalmars-d-learn
On Wednesday, 14 May 2014 at 21:41:04 UTC, DaveG wrote: Hopefully better formatting of code here: import tkd.tkdapplication; class Application : TkdApplication { private void exitCommand(CommandArgs args) { this.exit(); } private void saveMeCommand(CommandArgs args)

Re: TKD AddProtocolCommand example

2014-05-15 Thread Gary Willoughby via Digitalmars-d-learn
On Wednesday, 14 May 2014 at 21:23:02 UTC, DaveG wrote: tkd\window\window.d(426): Error: undefined identifier CommandCallback Added the missing import and now all works fine. Fixed in v1.0.5-beta. Any more issues open them up in github and i'll deal with them there. :) https://github.com/no

Re: TKD AddProtocolCommand example

2014-05-15 Thread Gary Willoughby via Digitalmars-d-learn
On Thursday, 15 May 2014 at 19:02:58 UTC, Mengu wrote: On Thursday, 15 May 2014 at 17:30:22 UTC, Gary Willoughby wrote: On Wednesday, 14 May 2014 at 21:23:02 UTC, DaveG wrote: tkd\window\window.d(426): Error: undefined identifier CommandCallback Added the missing import and now all works fine

Re: D Newbie Trying to Use D with Major C Libraries

2014-05-16 Thread Gary Willoughby via Digitalmars-d-learn
On Thursday, 15 May 2014 at 22:25:47 UTC, Tom Browder via Digitalmars-d-learn wrote: I am a volunteer developer with the well-known 3D CAD FOSS project BRL-CAD: http://brlcad.org I have wanted to use D for a long time but I hadn't taken the plunge. Yesterday I advertised to the BRL-CAD comm

Re: D Newbie Trying to Use D with Major C Libraries

2014-05-16 Thread Gary Willoughby via Digitalmars-d-learn
On Friday, 16 May 2014 at 19:17:05 UTC, Dicebot wrote: On Friday, 16 May 2014 at 19:05:25 UTC, Tom Browder via Digitalmars-d-learn wrote: On Fri, May 16, 2014 at 1:05 PM, Gary Willoughby via Digitalmars-d-learn wrote: ... Then take a look at one of my projects in which i've ported C he

Re: D Newbie Trying to Use D with Major C Libraries

2014-05-16 Thread Gary Willoughby via Digitalmars-d-learn
On Friday, 16 May 2014 at 20:28:31 UTC, Tom Browder via Digitalmars-d-learn wrote: On Fri, May 16, 2014 at 2:31 PM, Gary Willoughby via Digitalmars-d-learn wrote: On Friday, 16 May 2014 at 19:17:05 UTC, Dicebot wrote: Using .di is more idiomatic as those are supposed to denote declaration

Re: Programming a Game in D? :D

2014-05-22 Thread Gary Willoughby via Digitalmars-d-learn
On Thursday, 22 May 2014 at 15:39:36 UTC, David wrote: Hey, I'm really new to D, and pretty new to programming overall too, But I want to make a 3d Game, (just sth. small). I really like D and want to do it in D, but in the Internet there is no shit about programming a game in D ^^ Is there an

Re: Passing a function as an argument to another function : what is this sorcery ?

2014-05-25 Thread Gary Willoughby via Digitalmars-d-learn
On Sunday, 25 May 2014 at 09:37:46 UTC, Derix wrote: Hello everyone, So I'm "Getting Started With Gtkd" [1] and the tuto includes this piece of code : ... DrawingArea da = new DrawingArea(590, 200); da.addOnDraw(&onDraw); layout.put(da, 5, 30); add(layout); // A

Re: TDPL - Andrei Alexandrescu

2014-05-25 Thread Gary Willoughby via Digitalmars-d-learn
On Sunday, 25 May 2014 at 15:07:56 UTC, DLearner wrote: Does the current D specification differ from that used in the book (and, if it does, is there a link to the changes)? http://erdani.com/tdpl/errata/

Re: floating point conversion

2014-06-02 Thread Gary Willoughby via Digitalmars-d-learn
I have a couple of functions that you may find useful for comparing floats. https://github.com/nomad-software/dunit/blob/master/source/dunit/toolkit.d#L42 https://github.com/nomad-software/dunit/blob/master/source/dunit/toolkit.d#L134

Re: '!' and naming conventions

2014-06-18 Thread Gary Willoughby via Digitalmars-d-learn
On Wednesday, 18 June 2014 at 20:55:36 UTC, cym13 wrote: Hello, I see a lot of functions and other stuff with a '!' in the name such as 'bitfields!' or 'ctRegex!'. What does it mean exactly? I think this will be helpful: http://nomad.so/2013/07/templates-in-d-explained/

Re: dub "--annotate" option

2014-06-19 Thread Gary Willoughby via Digitalmars-d-learn
On Thursday, 19 June 2014 at 17:45:56 UTC, FreeSlave wrote: Dub has option called "--annotate". It's described like this: Do not perform any action, just print what would be done I supposed it's something similar to "-n" option of Jam build system (I really like this feature). But dub's "annot

Help to find crash in simple stack type?

2014-07-12 Thread Gary Willoughby via Digitalmars-d-learn
I've created a simple stack type using calloc/free which seems to work nicely. Then instead of using C functions i've tried to implement the same type using the GC. However i'm experiencing a crash. I've been staring at this snippet for hours now any help would be appreciated. This is a simplif

  1   2   3   >