Re: tell if __traits(allMembers, ... ) is an enum (not manifest constant)

2016-02-24 Thread Nicholas Wilson via Digitalmars-d-learn
On Thursday, 25 February 2016 at 04:32:24 UTC, Adam D. Ruppe wrote: On Thursday, 25 February 2016 at 04:25:25 UTC, Nicholas Wilson wrote: foreach(m; __traits(allMembers, ...) { static if(is(m== enum)) } That's close but not quite there... try static if(is(typeof(__traits(getMember,

tell if __traits(allMembers, ... ) is an enum (not manifest constant)

2016-02-24 Thread Nicholas Wilson via Digitalmars-d-learn
there is no __traits(isEnum, ...) I've tried foreach(m; __traits(allMembers, ...) { static if (__traits(compiles,EnumMembers!(m))) static if (EnumMembers!(m).length) static if(is(m== enum)) } I can detect static functions with __traits(isStaticFunction, ...)

Re: Dynamic pitch shift

2016-02-24 Thread Nicholas Wilson via Digitalmars-d-learn
On Wednesday, 24 February 2016 at 10:33:56 UTC, Tanel Tagaväli wrote: Hello! I've been making some progress on the native D audio front: https://github.com/clinei/daud/tree/28ac042a16ae6785605a9a501b5f867c8f962055 It's a continuous waveform generator, currently outputting a saw wave that

Re: vk.xml

2016-02-23 Thread Nicholas Wilson via Digitalmars-d-learn
On Sunday, 21 February 2016 at 15:18:44 UTC, ZombineDev wrote: On Sunday, 21 February 2016 at 12:52:33 UTC, Nicholas Wilson wrote: [...] I'm glad to see more people looking to create a D binding from vk.xml! I was also working on this

arsd.dom getElementsByTagNameChildrenOnly?

2016-02-23 Thread Nicholas Wilson via Digitalmars-d-learn
So the vulkan spec has a lot of stuff like VkStructureType sType const void* pNext optional="true">VkBufferCreateFlags flags VkDeviceSize

Re: call to super trashes pointer?

2016-02-23 Thread Nicholas Wilson via Digitalmars-d-learn
On Tuesday, 23 February 2016 at 10:47:17 UTC, Rene Zwanenburg wrote: On Tuesday, 23 February 2016 at 09:16:08 UTC, Nicholas Wilson wrote: struct A { int blah; } class B { A* a; this(A* _a) { writeln(_a) a =_a; } } class C : B { this(A* _a) {

Re: call to super trashes pointer?

2016-02-23 Thread Nicholas Wilson via Digitalmars-d-learn
On Tuesday, 23 February 2016 at 09:16:08 UTC, Nicholas Wilson wrote: struct A { int blah; } class B { A* a; this(A* _a) { writeln(_a) a =_a; } } class C : B { this(A* _a) { writeln(_a) super(_a); } } int main(string[] args) { A

call to super trashes pointer?

2016-02-23 Thread Nicholas Wilson via Digitalmars-d-learn
struct A { int blah; } class B { A* a; this(A* _a) { writeln(_a) a =_a; } } class C : B { this(A* _a) { writeln(_a) super(_a); } } int main(string[] args) { A a; writeln(); C c = new C(); } prints 7FFF56E787F8

Re: constant expression

2016-02-23 Thread Nicholas Wilson via Digitalmars-d-learn
On Tuesday, 23 February 2016 at 07:43:37 UTC, Ali Çehreli wrote: On 02/22/2016 11:38 PM, Nicholas Wilson wrote: I've tried with both mutable and immutable a module scope. Scope I want is global (don't care about mutability) Uncomment immutable if you want immutable and remove 'shared' if

Re: constant expression

2016-02-22 Thread Nicholas Wilson via Digitalmars-d-learn
On Tuesday, 23 February 2016 at 07:26:01 UTC, Ali Çehreli wrote: On 02/22/2016 09:52 PM, Nicholas Wilson wrote: How is this not a constant expression ? auto ctodtypes = [ "void" : "void", "uint32_t" : "uint", "uint64_t" : "ulong", "int32_t" : "int", "int64_t"

constant expression

2016-02-22 Thread Nicholas Wilson via Digitalmars-d-learn
How is this not a constant expression ? auto ctodtypes = [ "void" : "void", "uint32_t" : "uint", "uint64_t" : "ulong", "int32_t" : "int", "int64_t" : "long", "char" : "char", "uint8_t" : "ubyte", "size_t": "size_t", "float" : "float"

Re: vk.xml

2016-02-22 Thread Nicholas Wilson via Digitalmars-d-learn
On Monday, 22 February 2016 at 07:00:42 UTC, Nicholas Wilson wrote: On Sunday, 21 February 2016 at 15:18:44 UTC, ZombineDev wrote: [...] Thanks for the tips. I used AA and just got it to compile! :) :| :( but fails to link. Undefined symbols for architecture x86_64:

Re: vk.xml

2016-02-21 Thread Nicholas Wilson via Digitalmars-d-learn
On Sunday, 21 February 2016 at 15:18:44 UTC, ZombineDev wrote: On Sunday, 21 February 2016 at 12:52:33 UTC, Nicholas Wilson wrote: So I was going through the vulcan spec to try to create a better D bindings for it. (pointer /len pairs to arrays adhering to D naming conventions and prettying up

vk.xml

2016-02-21 Thread Nicholas Wilson via Digitalmars-d-learn
So I was going through the vulcan spec to try to create a better D bindings for it. (pointer /len pairs to arrays adhering to D naming conventions and prettying up the *Create functions functions like vkResult *Create( arg ,, retptr) to a fancy throw on misuse struct with constructors and that

Re: Modify Function Pointer to Take Additional Parameters

2016-02-19 Thread Nicholas Wilson via Digitalmars-d-learn
On Friday, 19 February 2016 at 05:41:01 UTC, jmh530 wrote: I'm trying to write a function that will adjust the parameters of a function pointer. I think the problem is that it defaults to a delegate not that it cannot be one does clarifying this to the compiler work Like alias fp1 = int

Re: How to force evaluation of range?

2016-02-12 Thread Nicholas Wilson via Digitalmars-d-learn
On Friday, 12 February 2016 at 20:43:24 UTC, Taylor Hillegeist wrote: So I have this code and I have to add the element .each!(a => a.each!("a")); to the end in order for it to evaluate the range completely and act like I expect it too. Is there a better thing to put in the place of .each!(a

Re: Overloading free functions & run-time dispatch based on parameter types

2016-02-05 Thread Nicholas Wilson via Digitalmars-d-learn
On Friday, 5 February 2016 at 10:54:27 UTC, Robert M. Münch wrote: From the docs: class A { } class B : A { } class C : B { } void foo(A); void foo(B); [...] sounds like foo should just be a method in the class rather than a free function

Re: Call D from TCL

2016-02-03 Thread Nicholas Wilson 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'm not sure about the specifics but if it can be done in C you can

Re: chain(const(array of class)) fails

2016-01-31 Thread Nicholas Wilson via Digitalmars-d-learn
On Sunday, 31 January 2016 at 21:22:06 UTC, SimonN wrote: Hi, we start with the following code snippet, which works. import std.algorithm; import std.range; import std.stdio; class A { int val; } class B : A { this() { val = 3; } } class C : A { this() { val = 4; }

Dense multidimensional std.container.array?

2016-01-26 Thread Wilson via Digitalmars-d-learn
Just wondering how to create a dense multidimensional array with the GC free array container? I don't want to use an array of arrays but I do want the array[0][0] notation.

Re: Struct Union behavior

2016-01-06 Thread Nicholas Wilson via Digitalmars-d-learn
On Wednesday, 6 January 2016 at 11:39:44 UTC, Voitech wrote: Hello, i am new to D language and trying to learn it by coding. I compile my programs on Xubuntu 14.04 with DMD64 D Compiler v2.069.2. So i have a struct/union which contains two fields representing real and string values: public

Re: Storing and Searching large text lists

2015-12-31 Thread Nicholas Wilson via Digitalmars-d-learn
On Friday, 1 January 2016 at 00:41:56 UTC, brian wrote: I have a large list, B, of string items. For each item in that large list, I need to see if it is in the smaller list, A. I have been using a simple string array for the storage of A string[] A and then using foreach to go through all

Re: D float types operations vs C++ ones

2015-12-17 Thread Nicholas Wilson via Digitalmars-d-learn
On Thursday, 17 December 2015 at 11:58:35 UTC, drug wrote: On 17.12.2015 14:52, Andrea Fontana wrote: You should publish some code to check... Too much code to public - operations are simple, but there are many branches and reducing may take much time . In fact I asked to understand _in

Re: D float types operations vs C++ ones

2015-12-17 Thread Nicholas Wilson via Digitalmars-d-learn
On Thursday, 17 December 2015 at 13:30:11 UTC, drug wrote: On 17.12.2015 16:09, Nicholas Wilson wrote: [...] Thanks for answer. My C++ version is tracing D version so commutativity and distributivity aren't requred because order of operations is the same (I guess so at least), so I hoped for

Re: check variable for undefinedness

2015-12-11 Thread Nicholas Wilson via Digitalmars-d-learn
On Saturday, 12 December 2015 at 07:39:47 UTC, Suliman wrote: if(a is null) How to check if variable "is not null" ? a !is null or !(a is null)

Re: Which type it better to use for array's indices?

2015-12-04 Thread Nicholas Wilson via Digitalmars-d-learn
On Friday, 4 December 2015 at 13:24:16 UTC, ref2401 wrote: Which type it better to use for array's indices? float[] arr = new float[10]; int i; long j; size_t k; // which one is better arr[i], a[j]or arr[k] ? It seem like `size_t` suites well because 'is large enough to represent an

Re: __traits and string mixins

2015-12-04 Thread Nicholas Wilson via Digitalmars-d-learn
On Thursday, 3 December 2015 at 13:36:16 UTC, Christian Köstlin wrote: Hi, I started an experiment with the informations that are available for compile time reflection. [...] I think CyberShadow (aka Vladimir Panteleev) has done something similar to this

Re: need help with Windows CreateNamedPipe Security attributes process with undefined symbols at compile time

2015-11-30 Thread Nicholas Wilson via Digitalmars-d-learn
On Tuesday, 1 December 2015 at 04:10:55 UTC, Jonathan Villa wrote: Hi, I've been trying to create a NamedPipe with security attributes but at compile time throws: Error 42: Symbol Undefined _InitializeSecurityDescriptor@8 Error 42: Symbol Undefined _SetSecurityDescriptorDacl@16 What is

Re: Derelict3 object.Error@(0): Access Violation?

2015-11-27 Thread Nicholas Wilson via Digitalmars-d-learn
On Friday, 27 November 2015 at 07:48:15 UTC, Alexander wrote: import std.stdio; import derelict.opengl3.gl3; import derelict.sdl2.sdl; pragma(lib, "DerelictUtil.lib"); pragma(lib, "DerelictGL3.lib"); pragma(lib, "derelictSDL2.lib"); void main(){ DerelictGL3.load();

Re: Multidimensional AA question

2015-11-26 Thread Nicholas Wilson via Digitalmars-d-learn
On Thursday, 26 November 2015 at 17:27:34 UTC, André wrote: Hi, I have a maybe trivial question on how to insert or update a given entry in a multidimensional AA. So I have this AA: /// language, chapter, section. Content is a magic struct Content[int][string][string] contentAA; In

Re: How do I read one character from stdin? (getc in C)

2015-11-14 Thread Nicholas Wilson via Digitalmars-d-learn
On Saturday, 14 November 2015 at 13:33:49 UTC, Fer22f wrote: Hello! I'm starting to make some simple command line programs and one thing I miss from C is a function for getting one character from the input. This is for example, an "Press Any Key Program". Anyone that has more experience can

Re: Bug? Bad file name?

2015-11-14 Thread Nicholas Wilson via Digitalmars-d-learn
On Saturday, 14 November 2015 at 05:44:44 UTC, Anonymous wrote: I was playing with some code someone posted on the forum that involved opDispatch and compile time parameters. I pasted it in a file named templOpDispatch.d, ran it, and got an error. Then I noticed if I renamed the file it

Re: Epoch time + msecs

2015-11-14 Thread Nicholas Wilson via Digitalmars-d-learn
On Saturday, 14 November 2015 at 12:14:42 UTC, Handyman wrote: The D docs seem very thorough and complete to me but less accessible in comparison to, e.g., Perl docs, Php docs, or Ruby docs. In particular I have difficulties in understanding the headers of the standard library function

Re: DUB library prefix - rules ?

2015-11-11 Thread Nicholas Wilson via Digitalmars-d-learn
On Wednesday, 11 November 2015 at 05:03:47 UTC, BBaz wrote: quoted from the website: Sets the base name of the output file; type and platform specific pre- and suffixes are added automatically - this setting does not support platform suffixes I must be blind but I can't find the code that

Re: Cannot use local 'i' as parameter to non-global template

2015-11-08 Thread Nicholas Wilson via Digitalmars-d-learn
On Saturday, 7 November 2015 at 15:04:41 UTC, maik klein wrote: template IsSame(T){ template As(alias t){ enum As = is(T : typeof(t)); } } void main() { int i; enum b = IsSame!int.As!(i); } Err: Error: template instance As!(i) cannot use local 'i' as parameter to non-global

Re: question about using std.bitmanip.read

2015-11-06 Thread Nicholas Wilson via Digitalmars-d-learn
On Saturday, 7 November 2015 at 03:19:44 UTC, Charles wrote: Hi guys, It's me again... still having some issues pop up getting started, but I remain hopeful I'll stop needing to ask so many questions soon. I'm trying to use std.bitmanip.read; however, am having some issues using it. For

Re: Align a variable on the stack.

2015-11-03 Thread Nicholas Wilson via Digitalmars-d-learn
On Tuesday, 3 November 2015 at 23:29:45 UTC, TheFlyingFiddle wrote: Is there a built in way to do this in dmd? Basically I want to do this: auto decode(T)(...) { while(...) { T t = T.init; //I want this aligned to 64 bytes. } } Currently I am using: align(64) struct

Re: Help with Concurrency

2015-11-03 Thread Nicholas Wilson via Digitalmars-d-learn
On Tuesday, 3 November 2015 at 23:16:59 UTC, bertg wrote: I am having trouble with a simple use of concurrency. Running the following code I get 3 different tid's, multiple "sock in" messages printed, but no receives. I am supposed to get a "received!" for each "sock in", but I am getting

Re: Access violation when calling C DLL from D

2015-11-02 Thread Nicholas Wilson via Digitalmars-d-learn
On Monday, 2 November 2015 at 01:02:45 UTC, AnoHito wrote: Hi, I am trying to write a simple interface to the MRuby Ruby interpreter so I can use ruby scripts in my D program. I was able to get MRuby compiled as a DLL without too much difficulty, but the headers are very long and complicated,

Re: Check template parameter whether it has "length"

2015-10-08 Thread Nicholas Wilson via Digitalmars-d-learn
On Thursday, 8 October 2015 at 09:29:30 UTC, tcak wrote: I am "trying" to write a function that takes an array of items, and returns the length of longest item. [code] size_t maxLength(A)( const A[] listOfString ) if( __traits( hasMember, A, "length" ) ) { return 0; // not

Re: std.Algebraic alias this

2015-10-06 Thread Nicholas Wilson via Digitalmars-d-learn
On Monday, 5 October 2015 at 11:31:32 UTC, Radu wrote: There is a weird rule on how compiler treats alias this for the N and S types bellow. [...] Please file a bug report. Also do the errors change if you reverse the order in T i.e. alias T = Algebraic!(S,N); ?

Re: enum to flags

2015-09-29 Thread Nicholas Wilson via Digitalmars-d-learn
On Tuesday, 29 September 2015 at 06:08:03 UTC, Cauterite wrote: On Tuesday, 29 September 2015 at 03:31:44 UTC, Nicholas Wilson wrote: so I have a bunch of enums (0 .. n) that i also want to represent as flags ( 1 << n foreach n ). Is there anyway to do this other than a string mixin? You

Re: enum to flags

2015-09-29 Thread Nicholas Wilson via Digitalmars-d-learn
On Tuesday, 29 September 2015 at 09:18:52 UTC, John Colvin wrote: On Tuesday, 29 September 2015 at 03:31:44 UTC, Nicholas Wilson wrote: so I have a bunch of enums (0 .. n) that i also want to represent as flags ( 1 << n foreach n ). Is there anyway to do this other than a string mixin? use

enum to flags

2015-09-28 Thread Nicholas Wilson via Digitalmars-d-learn
so I have a bunch of enums (0 .. n) that i also want to represent as flags ( 1 << n foreach n ). Is there anyway to do this other than a string mixin? use like: enum blah { foo, bar, baz, } alias blahFlags = EnumToFlags!blah; static assert(blahFlags.baz == 1 << blah.baz)

Re: pi program

2015-09-25 Thread Nicholas Wilson via Digitalmars-d-learn
On Friday, 25 September 2015 at 05:50:58 UTC, Charanjit Singh wrote: import std.stdio; import std.math; void main() { float sum,pi,t; int n=1; sum=0; while (n<100 ) { t=1/( n*n); n=n+1; sum=sum+t; } writeln("value of PI= " , (sum*6)^^.5); that is pi

Re: Why is the constructor of B called?

2015-09-24 Thread Nicholas Wilson via Digitalmars-d-learn
On Thursday, 24 September 2015 at 11:26:12 UTC, Marc Schütz wrote: On Thursday, 24 September 2015 at 01:01:09 UTC, Nicholas Wilson wrote: On Wednesday, 23 September 2015 at 21:25:15 UTC, tcak wrote: On Wednesday, 23 September 2015 at 21:14:17 UTC, Adam D. Ruppe wrote: [...] Is there any way

Re: I can't get passing an array by reference to work anymore...

2015-09-24 Thread Nicholas Wilson via Digitalmars-d-learn
On Friday, 25 September 2015 at 02:37:22 UTC, TheGag96 wrote: So I'm just doing a small test program here: http://pastebin.com/UYf2n6bP (I'm making sure I know quicksort for my algorithms class, I know functionally this won't work as-is) I'm on Linux, 64-bit, DMD 2.068.1, and when I try to

Re: Can I check if a value is convertible to a valid value of an enum?

2015-09-24 Thread Nicholas Wilson via Digitalmars-d-learn
On Friday, 25 September 2015 at 03:12:20 UTC, French Football wrote: ...without having to loop over the enum? enum SomeType : string { CHEESE = "cheese", POTATO = "potato" } string valid_value = "cheese"; string invalid_value = "pizza"; bool test( string value ){ if(

Re: Why is the constructor of B called?

2015-09-23 Thread Nicholas Wilson via Digitalmars-d-learn
On Wednesday, 23 September 2015 at 21:25:15 UTC, tcak wrote: On Wednesday, 23 September 2015 at 21:14:17 UTC, Adam D. Ruppe wrote: On Wednesday, 23 September 2015 at 21:08:37 UTC, tcak wrote: I wouldn't expect B's constructor to be called at all unless "super" is used there. "If no call to

Re: Massive linker error after upgrade to DMD 2.068.1-1

2015-09-12 Thread Nicholas Wilson via Digitalmars-d-learn
On Saturday, 12 September 2015 at 20:05:28 UTC, rcorre wrote: After upgrading from DMD 2.068.0-1 to DMD 2.068.1-1, my project began producing a large linker error (when built using dub). I was able to trace it down to a single line: target =

Re: Odd stacktrace: Access Violation in object.TypeInfo_Interface.getHash

2015-09-07 Thread Nicholas Wilson via Digitalmars-d-learn
On Monday, 7 September 2015 at 08:55:31 UTC, Fra wrote: I encountered a runtime error in my code and all I can get (even in debug mode) is the following stacktrace: object.Error@(0): Access Violation 0x0051C308 in const(nothrow @trusted uint function(const(void*)))

Re: reading file byLine

2015-09-03 Thread Jordan Wilson via Digitalmars-d-learn
On Thursday, 3 September 2015 at 22:48:01 UTC, Jordan Wilson wrote: On Thursday, 3 September 2015 at 22:21:57 UTC, Namal wrote: ep18.d(10): Error: no property 'split' for type 'char[]' /usr/include/dmd/phobos/std/algorithm.d(427): instantiated from here: MapResult!(__lambda1,

Re: reading file byLine

2015-09-03 Thread Jordan Wilson via Digitalmars-d-learn
Actually, need an extra map I think: auto word = file.byLine() .map!(a => a.split) .map!(a => map!(a => to!int(a))(a)) .array();

Re: reading file byLine

2015-09-03 Thread Jordan Wilson via Digitalmars-d-learn
On Thursday, 3 September 2015 at 22:21:57 UTC, Namal wrote: ep18.d(10): Error: no property 'split' for type 'char[]' /usr/include/dmd/phobos/std/algorithm.d(427): instantiated from here: MapResult!(__lambda1, ByLine!(char, char)) ep18.d(10):instantiated from here:

Re: reading file byLine

2015-09-03 Thread Jordan Wilson via Digitalmars-d-learn
And also: import std.algorithm Sorry, I should have taken the time to answer properly and fully.

Re: reading file byLine

2015-09-03 Thread Jordan Wilson via Digitalmars-d-learn
On Thursday, 3 September 2015 at 23:28:37 UTC, Namal wrote: On Thursday, 3 September 2015 at 23:25:52 UTC, Jordan Wilson wrote: And also: import std.algorithm Sorry, I should have taken the time to answer properly and fully. import std.file, std.stdio, std.string, std.conv, std.algorithm;

Re: reading file byLine

2015-09-03 Thread Jordan Wilson via Digitalmars-d-learn
On Friday, 4 September 2015 at 00:18:15 UTC, Namal wrote: On Thursday, 3 September 2015 at 23:54:44 UTC, H. S. Teoh wrote: [...] Thx Theo, this and the lack of foolproof tutorials were the reason why I gave up on D 2 years ago and went instead to C++. But I am not giving up this time. That

Error Compiling with -debug swtich

2015-08-27 Thread Jordan Wilson via Digitalmars-d-learn
Hello, Just wondering why compiling the following fails with the -debug switch, but appears to compile and execute fine without it: import std.stdio; import std.algorithm; import std.container; int main(string[] args) { Array!string letters = [b,a,c]; sort(letters[]); writeln

Re: New to D - playing with Thread and false Sharing

2015-08-20 Thread Nicholas Wilson via Digitalmars-d-learn
On Thursday, 20 August 2015 at 20:01:58 UTC, tony288 wrote: On Thursday, 20 August 2015 at 15:37:35 UTC, Dejan Lekic wrote: [...] Thanks, I changed the code and the previous one was already using shared. import std.stdio; import core.time; import core.thread; [...] Keep in mind java may

Re: Empty struct, any runtime cost?

2015-08-19 Thread Nicholas Wilson via Digitalmars-d-learn
On Wednesday, 19 August 2015 at 09:54:33 UTC, SimonN wrote: Hi, in a release-like build, I'm using the tharsis profiler, which is a frame-based profiler. Zone is a RAII struct that measures how long its own lifetime is. with (Zone(my_profiler, zone name to appear in output)) {

Re: App Build Error

2015-08-16 Thread Nicholas Wilson via Digitalmars-d-learn
On Sunday, 16 August 2015 at 17:33:52 UTC, Benjamin wrote: I'm having an issue with building my app - even a simple trivial app (shown below). [...] OS X version? Have you configured your dmd.conf? iirc it requires linker path changes or something. Have you looked in /usr/local/lib for

Re: D Classes Passed By Reference or Value?

2015-08-16 Thread Nicholas Wilson via Digitalmars-d-learn
On Sunday, 16 August 2015 at 23:40:41 UTC, Brandon Ragland wrote: On Sunday, 16 August 2015 at 23:31:46 UTC, Ali Çehreli wrote: On 08/16/2015 04:13 PM, Brandon Ragland wrote: That makes more sense. Though it does make the ref method signature unclear, as it only applies to literals at this

Re: Pointers to Dynamic Arrays

2015-08-16 Thread Nicholas Wilson via Digitalmars-d-learn
On Monday, 17 August 2015 at 02:45:22 UTC, Brandon Ragland wrote: Howdy, Since Dynamic Arrays / Slices are a D feature, using pointers to these has me a bit confused... Consider: Now what is especially confusing about this, is that the above seems to works fine, while this does not:

Re: SList container problem

2015-08-13 Thread Nicholas Wilson via Digitalmars-d-learn
On Thursday, 13 August 2015 at 08:40:13 UTC, ted wrote: have upgraded from 2.066.1 to 2.068.0, and have a change in behaviour: import std.container: SList; void main() { SList!int tmp; tmp.insertAfter( tmp[], 3 ); } used to work happily with dmd2.066.1, causes assert

Re: Specify variable type for range of associative arrays.

2015-08-09 Thread Nicholas Wilson via Digitalmars-d-learn
On Sunday, 9 August 2015 at 01:29:16 UTC, Christopher Davies wrote: I'm just learning D. Something I often do in C# is have an IEnumerable (Range) of some type that is then conditionally filtered. It looks like this: IEnumerableDictionarystring, string foo = bar; if (baz) { foo =

Re: Template-Parameterized Variadic isInstaceOf

2015-08-07 Thread Nicholas Wilson via Digitalmars-d-learn
On Friday, 7 August 2015 at 11:45:22 UTC, Nordlöw wrote: To implement a new trait isSortedRange(R, pred) needed for SortedRange specializations I need a variant of enum bool isInstanceOf(alias S, T) = is(T == S!Args, Args...); that takes the `pred` argument aswell. But I have no

Re: std.algorithm each documentation terse

2015-07-20 Thread Nicholas Wilson via Digitalmars-d-learn
On Monday, 20 July 2015 at 14:59:21 UTC, John Colvin wrote: On Monday, 20 July 2015 at 14:40:59 UTC, jmh530 wrote: [...] Everything is exactly as I would expect. Lambdas with = are just shorthand that skips the return expression and std.algorithm.each just calls the lambda for each element

Re: String Metaprogramming

2015-07-18 Thread Nicholas Wilson via Digitalmars-d-learn
On Saturday, 18 July 2015 at 13:48:20 UTC, Clayton wrote: Am new to D programming, am considering it since it supports compile-time function execution . My challenge is how can I re-implement the function below so that it is fully executed in compile-time. The function should result to tabel1

Re: Comparison of struct with Nullable member

2015-07-17 Thread Nicholas Wilson via Digitalmars-d-learn
On Friday, 17 July 2015 at 12:18:56 UTC, TC wrote: Hello, I came around a strange behavior and I'm not sure if it is a bug or feature. import std.typecons : Nullable; struct Foo { string bar; Nullable!int baz; } auto a = Foo(bb); auto b = Foo(bb); assert(a == b); This ends

Re: Array operations with array of structs

2015-07-05 Thread Nicholas Wilson via Digitalmars-d-learn
On Monday, 6 July 2015 at 03:02:59 UTC, Nicholas Wilson wrote: On Monday, 6 July 2015 at 01:16:54 UTC, Peter wrote: Hi, I have a struct with arithmetic operations defined using opBinary but array operations with arrays of it don't work. struct Vector3 { public double[3] _p; ...

Re: Array operations with array of structs

2015-07-05 Thread Nicholas Wilson via Digitalmars-d-learn
On Monday, 6 July 2015 at 01:16:54 UTC, Peter wrote: Hi, I have a struct with arithmetic operations defined using opBinary but array operations with arrays of it don't work. struct Vector3 { public double[3] _p; ... Vector3 opBinary(string op)(in Vector3 rhs) const if (op ==

Re: How to setup GDC with Visual D?

2015-07-03 Thread Nicholas Wilson via Digitalmars-d-learn
On Friday, 3 July 2015 at 23:45:15 UTC, Guy Gervais wrote: On Friday, 3 July 2015 at 19:17:28 UTC, Marko Grdinic wrote: Any advice regarding how I can get this to work? Thanks. I got GDC to work with VS2013 + VisualD by going into Tools-Options (The VS menu, not the one under Visual D) and

linking external libs

2015-07-02 Thread Nicholas Wilson via Digitalmars-d-learn
So test.d depends on libgmp.a Unsurprisingly: $dmd test.d fails to find libgmp.a So tell it to look $dmd -L-lgmp test.d finds the wrong one or doesn't find it. Tell it where to look $dmd -L-L/usr/local/lib -L-lgmp test.d Ok. Now it fails to find Phobos. Ok $dmd -L-L/usr/local/lib

Re: linking external libs

2015-07-02 Thread Nicholas Wilson via Digitalmars-d-learn
On Thursday, 2 July 2015 at 12:19:06 UTC, Steven Schveighoffer wrote: On 7/2/15 8:10 AM, Nicholas Wilson wrote: [...] Try dmd -v, it will tell you the link line. Then you can try it yourself to see how to get it to work. I know dmd has problems with link line parameters, because it always

Re: etc.c.zlib help

2015-07-02 Thread Nicholas Wilson via Digitalmars-d-learn
On Thursday, 2 July 2015 at 03:07:43 UTC, Matthew Gamble wrote: I am trying to make the transition from C++ to D. I've hit a snag with the etc.c.zlib module where any attempt to use this module to open a file yields an error: Error 42: Symbol Undefined __lseeki64. Here is a simple example of

Re: Mutable reference to const objects

2015-07-01 Thread Nicholas Wilson via Digitalmars-d-learn
On Wednesday, 1 July 2015 at 08:33:44 UTC, Yuxuan Shui wrote: On Wednesday, 1 July 2015 at 08:30:23 UTC, Yuxuan Shui wrote: How do I express a mutable reference to a const object in D? What I want to do is to define a variable, which refers a constant object, but I can change which constant

Re: Packing enums

2015-06-30 Thread Nicholas Wilson via Digitalmars-d-learn
On Monday, 29 June 2015 at 22:05:47 UTC, qznc wrote: I stumbled upon this interesting programming challenge [0], which imho should be possible to implement in D. Maybe someone here wants to try. Task: Given two enums with less than 256 states, pack them into one byte and provide convenient

Re: aa.byKeyValue().sort!a.key b.key

2015-06-27 Thread Nicholas Wilson via Digitalmars-d-learn
On Saturday, 27 June 2015 at 12:27:59 UTC, H. S. Teoh wrote: On Sat, Jun 27, 2015 at 12:22:06PM +, Nicholas Wilson via Digitalmars-d-learn wrote: How do I iterate through an AA sorted by key? I am unable to .dup the aa.byKeyValue(). Because it is a range, not an array. To turn

aa.byKeyValue().sort!a.key b.key

2015-06-27 Thread Nicholas Wilson via Digitalmars-d-learn
How do I iterate through an AA sorted by key? I am unable to .dup the aa.byKeyValue(). I have tried both foreach(e; aa.byKeyValue().sort!a.key b.key) { //... use e. key e.value } and foreach(k,v; aa.byKeyValue().sort!a.key b.key) { } i get : template std.algorithm.sorting.sort cannot

Re: compilation issues in a shared library project

2015-06-15 Thread Nicholas Wilson via Digitalmars-d-learn
On Sunday, 7 June 2015 at 00:38:17 UTC, Jonathan Villa wrote: module dt2.DataBlock; class DataBlock { public DataBlock * NextBlock; public DataBlock * PrevBlock; public string value; this() { NextBlock = null; PrevBlock =

Re: Is it possible to add items to the arrays and hashes at compile time?

2015-06-07 Thread Nicholas Wilson via Digitalmars-d-learn
On Sunday, 7 June 2015 at 12:30:12 UTC, Dennis Ritchie wrote: Does D the ability to add items to arrays and hashes at compile time? For example, how do I do it in compile time?: int[][int][int] hash; hash[4][6] ~= [34, 65]; hash[5][7] ~= [4, 78, 21]; try using a pure function + static e.g.

Signs by which to recognize D1

2015-05-06 Thread Daren Scot Wilson via Digitalmars-d-learn
Someone looks at a chunk of D code of murky origin. Possibly, it is old, maybe D1 not D2. Inadequately commented, believe it or not, and not other information. What are some easy to spot details in the syntax by which the onlooker can know it's D1 not D2?

Re: Structs as template parameters: weird error message

2015-04-02 Thread Nicholas Wilson via Digitalmars-d-learn
On Thursday, 2 April 2015 at 23:12:25 UTC, biozic wrote: The code below doesn't compile. Why this error message? --- struct Item { int i; } struct Params { Item* item; this(int i) { item = new Item(i); // line 9 } } struct Foo(Params params) {} enum foo =

Re: DMD Zip for Mac OS X

2015-02-28 Thread Nicholas Wilson via Digitalmars-d-learn
On Saturday, 28 February 2015 at 06:45:58 UTC, Mike Parker wrote: I'm not a Mac user and I'm fairly clueless about it. The DMD zip for OS X contains one executable. I assume it's a 64-bit binary. Is that true? Most likely a disk image (.dmg). (en.wikipedia.org/wiki/Apple_Disk_Image)

Re: How to make Application bundle from Executable? (Mac)

2015-02-20 Thread Nicholas Wilson via Digitalmars-d-learn
On Friday, 20 February 2015 at 06:19:29 UTC, Gan wrote: On Friday, 20 February 2015 at 06:10:51 UTC, Nicholas Wilson wrote: On Friday, 20 February 2015 at 03:26:47 UTC, Gan wrote: Also I can't get my application to load images that I place in the Resources folder(or any folder in the bundle

Re: How to make Application bundle from Executable? (Mac)

2015-02-19 Thread Nicholas Wilson via Digitalmars-d-learn
On Friday, 20 February 2015 at 03:26:47 UTC, Gan wrote: Also I can't get my application to load images that I place in the Resources folder(or any folder in the bundle for that matter). I suggest to have a look at the projects generated by SFML regarding locating the resources in C++/ObjC and

Re: Binding C++ value types

2015-02-09 Thread Nicholas Wilson via Digitalmars-d-learn
On Monday, 9 February 2015 at 19:30:32 UTC, Benjamin Thaut wrote: When binding C++ value types you might want to use them by placing them on the D-Stack. This however seems to be not supported as the mangling for the constructor is completely wrong. Is this supposed to work? Kind Regards

Re: Issue with template function

2015-02-07 Thread Nicholas Wilson via Digitalmars-d-learn
On Friday, 6 February 2015 at 17:09:29 UTC, Charles wrote: I'm trying to create a template function that can take in any type of array and convert it to a ubyte array. I'm not concerned with endianness at the moment, but I ran into a roadblock when trying to do this with strings. It already

Re: Issue with template function

2015-02-07 Thread Nicholas Wilson via Digitalmars-d-learn
The original code I was using was written in Java, and only had a method for strings. This is closer to what I wanted. My unit tests were just going back and forth with readString function, so I was completely missing this for other types. Nice catch! There were a couple issues with your

Re: Syntax for checking if an element exists in a list

2015-02-05 Thread Nicholas Wilson via Digitalmars-d-learn
On Thursday, 5 February 2015 at 13:31:21 UTC, Nicholas Wilson wrote: On Thursday, 5 February 2015 at 12:31:31 UTC, Stéphane wrote: Syntax for checking if an element exists in a list Hello, I would like to know if there is a better (easier to wite, easier to read, easier to understand) way

Re: Syntax for checking if an element exists in a list

2015-02-05 Thread Nicholas Wilson via Digitalmars-d-learn
On Thursday, 5 February 2015 at 12:31:31 UTC, Stéphane wrote: Syntax for checking if an element exists in a list Hello, I would like to know if there is a better (easier to wite, easier to read, easier to understand) way to check if an element (string) is in a list of strings. Here are

Re: Error when profiling

2015-02-01 Thread Nicholas Wilson via Digitalmars-d-learn
On Saturday, 31 January 2015 at 14:12:59 UTC, Phil wrote: When trying to run my program with profiling enabled it dies before the first line of my main function runs. Everything works fine without profiling. I get the following stack trace: thread #1: tid = 0x38de4, 0x00010008d985

Re: BitArray crash

2015-01-30 Thread Nicholas Wilson via Digitalmars-d-learn
I think I have to set length first. Yes. Declaring BitArray b; is like declaring int[] a; // ={.length = 0, . ptr = null} you get the segfault for invalid dereference.

Re: Threads and stdio and HANDLE

2015-01-29 Thread Nicholas Wilson via Digitalmars-d-learn
On Wednesday, 28 January 2015 at 11:50:46 UTC, Danny wrote: Hello, I'm trying to write some toy examples using threads in D. Is the std.stdio.File thread-local or shared? Is flockfile used when I synchronize on it? I tried checking phobos myself and found some things I don't get (in

Re: Why can't functions and struct types have the same name?

2015-01-26 Thread Nicholas Wilson via Digitalmars-d-learn
On Monday, 26 January 2015 at 11:15:26 UTC, Joakim wrote: Right now, any attempt to have symbols with the same name errors out, regardless of how they're used. This caused a problem for me because I'm trying to use a third-party C library that defines a struct type called socket and my code

Audio file read/write?

2014-11-06 Thread Daren Scot Wilson via Digitalmars-d-learn
What's the current recommended way to read and write audio files? I don't need to play it on the speakers or deal with anything real time - just read a file's data into an array, fiddle with it, and write it out to a file. I found some other threads about audio files, but none recent,

Re: Using D static library from C

2014-06-05 Thread Dave Wilson via Digitalmars-d-learn
You can create a static library from one or more .o files using ar, if that helps (unless I've failed to understand the question). ar r libtest.a test.o should do the job.

<    2   3   4   5   6   7