Re: How to use ranges?

2015-08-23 Thread anonymous via Digitalmars-d-learn
On Sunday 23 August 2015 19:58, Doolan wrote: >> You can use typeof to get the type of a range expression when >> typing it out is impractical/impossible. > What if I want to save a range in a struct? Or is a range more of > a verb than a noun..? Can still use typeof then: struct S { imp

Re: How to use ranges?

2015-08-23 Thread anonymous via Digitalmars-d-learn
On Sunday 23 August 2015 12:17, Doolan wrote: > And the use of auto everywhere makes it really hard to tell what > types I should be using for anything. My compiler talks about > RangeT!(whatever) but you try to use RangeT!(whatever) and you > find out RangeT is private... You can use typeof to g

Re: Trying to compile weather program

2015-08-23 Thread anonymous via Digitalmars-d-learn
On Sunday 23 August 2015 11:54, Tony wrote: > weather_report.d(32): Error: undefined identifier centerJustifier `centerJustifier` is new in 2.068. You're probably using an older version of D. You can replace `centerJustifier` with `center` here.

Re: Why does not my program is not running?

2015-08-20 Thread anonymous via Digitalmars-d-learn
On Thursday 20 August 2015 23:11, anonymous wrote: > 2) *integer++ doesn't do what you think it does. The increment is done > before the dereference. You could fix this, but: I got that one wrong. Steven Schveighoffer has it right. The pointer is incremented after the currently pointed-to value

Re: Why does not my program is not running?

2015-08-20 Thread anonymous via Digitalmars-d-learn
On Thursday 20 August 2015 22:31, Unknow wrote: > I'm writed a program for calculating the e number. I can compile > the source code but when i try run the program, system gives > 'program stopped working' error. > > Source code; > """ > // main.d > > module main; > > import std.file; > import

Re: How to provide this arg or functor for algorithm?

2015-08-17 Thread anonymous via Digitalmars-d-learn
On Monday, 17 August 2015 at 16:21:16 UTC, thedeemon wrote: On Monday, 17 August 2015 at 16:18:50 UTC, thedeemon wrote: I've just checked with my runtime GC hook. Here the call to func() allocates 12 bytes via gc_malloc, and it's the same for a 4-elements array, so it's not for the array itself

Re: std.net.curl

2015-08-17 Thread anonymous via Digitalmars-d-learn
On Monday, 17 August 2015 at 13:13:48 UTC, anonymous wrote: and figured out that the linker is invoked (on my machine) with gcc a.o -o a -m64 -lcurl -L/usr/lib/x86_64-linux-gnu -Xlinker correct (I named the example programm a.d instead of app.d): gcc app.o -o app -m64 -lcurl -L/usr/lib/x86_64

Re: std.net.curl

2015-08-17 Thread anonymous via Digitalmars-d-learn
On Monday, 17 August 2015 at 12:58:54 UTC, Adam D. Ruppe wrote: On Monday, 17 August 2015 at 12:52:37 UTC, tired_eyes wrote: Hovewer, "dmd app.d" spits a whole bunch of strange error messages: try "dmd -lcurl app.d" and see if that helps. DMD does not accept -lcurl. From dmd --help: -Llinke

Re: How to provide this arg or functor for algorithm?

2015-08-17 Thread anonymous via Digitalmars-d-learn
On Monday, 17 August 2015 at 10:28:33 UTC, thedeemon wrote: Nope, it "works" only because "r" is unreferenced and gets thrown out. Just try using r.front there, for example, and the error returns. You're right, it falls short. But I think r not being referenced is not exactly it. Using front

Re: How to provide this arg or functor for algorithm?

2015-08-17 Thread anonymous via Digitalmars-d-learn
On Sunday, 16 August 2015 at 23:05:42 UTC, Ali Çehreli wrote: // Now the type of d is a template parameter @nogc auto func(Func)(uint[] arr, Func d) { return arr.map!(d); } Huh. I think func being a template is the key here. When the original code is put in a template, it works too (with 2

Re: 2.068 Regression in EnumMembers?

2015-08-16 Thread anonymous via Digitalmars-d-learn
On Sunday, 16 August 2015 at 11:25:48 UTC, Nordlöw wrote: I tried rebuilding my knowledge graph project at https://github.com/nordlow/justd/tree/master/knet with DMD 2.068 and it seems like we have a regression in std.traits: EnumMembers: [...] It builds without errors nor warnings on 2.067

Re: using memset withing a pure function

2015-08-15 Thread anonymous via Digitalmars-d-learn
On Saturday, 15 August 2015 at 19:50:56 UTC, Temtaime wrote: There's a problem with « dst[0 .. n] = val; ». It should be « dst[0 .. n][] = val; » No, you don't need the `[]`.

Re: using memset withing a pure function

2015-08-15 Thread anonymous via Digitalmars-d-learn
On Saturday, 15 August 2015 at 18:04:30 UTC, D_Learner wrote: memcpy(&skip[0], &skip[0]+shift, (m-shift)*(int.sizeof)); memset(&skip[0]+(m-shift),0, shift*(int.sizeof)) I was thinking conversion would be :- skip[0 .. size-1] = skip[shift .. size-1 ]; //For the memcpy(); Those

Re: using memset withing a pure function

2015-08-14 Thread anonymous via Digitalmars-d-learn
On Saturday, 15 August 2015 at 02:21:46 UTC, D_Learner wrote: Well, the actual error I got is : Error: memset cannot be interpreted at compile time, because it has no available source code . I seems to suggest I miss the actual code. I guess I gave you a wrong impression of how pure relates t

Re: using memset withing a pure function

2015-08-14 Thread anonymous via Digitalmars-d-learn
On Saturday, 15 August 2015 at 02:21:46 UTC, D_Learner wrote: On Saturday, 15 August 2015 at 01:13:02 UTC, Adam D. Ruppe wrote: On Saturday, 15 August 2015 at 01:09:15 UTC, D_Learner wrote: When writting a pure fucntion involving C non pure functions like memcpy() and memset() Those funct

Re: Associative array literal. Why doesn't it compile?

2015-08-14 Thread anonymous via Digitalmars-d-learn
On Friday, 14 August 2015 at 07:04:53 UTC, BBasile wrote: It's because of the key type (string is a library type). This is not true. It's not because of the key type. And string is not a library type.

Re: SList container problem

2015-08-14 Thread anonymous via Digitalmars-d-learn
https://issues.dlang.org/show_bug.cgi?id=14920

Re: complete win headers for 32/64 bit

2015-08-13 Thread anonymous via Digitalmars-d-learn
On Thursday, 13 August 2015 at 16:28:15 UTC, learn wrote: unfortunately i can't find a complete set of windows header files. maybe one should add a link for those headers if they exist - life is not linux or osx only. https://github.com/etcimon/windows-headers

Re: Compiletime Table

2015-08-13 Thread anonymous via Digitalmars-d-learn
On Thursday, 13 August 2015 at 19:13:55 UTC, D_Learner wrote: I was wondering how I could change the code below such the `bmBc` is computed at compile time . The one below works for runtime but it is not ideal since I need to know the `bmBc` table at compile-time . I could appreciate advice on

Should these aliases kind be illegal ?

2015-08-12 Thread anonymous via Digitalmars-d-learn
The following alias declaration is totally legal but actually it's not usable --- class Foo { void something(size_t param){} } class Bar { private Foo foo; this(){foo = new Foo;} alias somethingelse = foo.something; } void main(string[] args) { auto bar = new Bar; //bar

Re: Infinity loop with dates comparison

2015-08-11 Thread anonymous via Digitalmars-d-learn
On Tuesday, 11 August 2015 at 19:56:02 UTC, Suliman wrote: Date startDate = Date.fromISOExtString("2014-08-01"); [...] Date nextday; while (nextday < currentDate) { nextday = startDate + 1.days; writeln(nextday); } startDate doe

Re: Concurrency Confusion

2015-08-09 Thread anonymous via Digitalmars-d-learn
On Sunday, 9 August 2015 at 17:43:59 UTC, 岩倉 澪 wrote: Afaict it is the best way to do what I'm trying to do, and since the data is mutable and cast to immutable with assumeUnique, casting it back to mutable shouldn't be a problem. Technically casting away immutable might be undefined behaviour

Re: Removing elements from dynamic array

2015-08-09 Thread anonymous via Digitalmars-d-learn
On Sunday, 9 August 2015 at 20:23:00 UTC, Reflexive wrote: I see that remove() removes the value of the element but keeps the same size of the array, and replace the value by a new one at the end. The method : class sabot{ card[] sabotarray ; (...) card getCard(){

Re: std.array: array, ulong and Win32

2015-08-09 Thread anonymous via Digitalmars-d-learn
On Sunday, 9 August 2015 at 20:13:38 UTC, ixid wrote: This seems like a reasonable use but errors, obviously I can do it in many other ways: ulong[] result = iota(1UL, 10UL).array; Error: static assert "Argument types in (ulong) are not all convertible to size_t: (ulong)" C:\D\dmd2\src

Re: std.stream.MemoryStream deprecated, range is the alternative?

2015-08-07 Thread anonymous via Digitalmars-d-learn
On Thursday, 6 August 2015 at 17:01:32 UTC, chris wrote: since memorystream is deprecated how do i do something like this with Input and Output ranges? How can i fill up an array with ranges like you can do with streams? Thanks. The InputRange primitives already exist for arrays, they are lo

Re: trouble compiling Fiber example code from docs dmd linux v2.067.1

2015-08-06 Thread anonymous via Digitalmars-d-learn
On Thursday, 6 August 2015 at 20:21:38 UTC, Carl Sturtivant wrote: I took the example code from here, http://dlang.org/phobos/core_thread.html#.Fiber and wrapped the statements at the bottom inside main() and put import core.thread and std.stdio at the top, and the compiler gave me the followin

Re: D Wiki: Windows programming examples are missing

2015-08-05 Thread anonymous via Digitalmars-d-learn
On Wednesday, 5 August 2015 at 21:02:49 UTC, Andre Polykanine wrote: Hi everyone, I'm fairly new to D and am really excited about it. I would like to see more examples of Windows programming in D, but the repository indicated on the D wiki seems to be moved or deleted. More info is here: http:/

Re: What is the order of resolution for super() calls?

2015-08-05 Thread anonymous via Digitalmars-d-learn
On Wednesday, 5 August 2015 at 12:32:48 UTC, cym13 wrote: For reference, as the diagram was unreadable, I'll describe it here: class Adam ; class Eve ; class Abel:Adam,Eve ; class Cain:Adam,Eve ; class David:Abel,Cain ; This is illegal D. You must use interfaces to simulate multiple inherita

Re: Trouble with template parameter matching

2015-08-02 Thread anonymous via Digitalmars-d-learn
On Sunday, 2 August 2015 at 08:08:05 UTC, tcak wrote: [code] void func1(N)( const N name ) if( is(N: string) || is(N: char[]) ) { func2( name ); } void func2(N)( const N name ) if( is(N: string) || is(N: char[]) ) {} void main(){ char[] blah = ['b', 'l', 'a', 'h'

Re: alias overloading strange error

2015-08-01 Thread anonymous via Digitalmars-d-learn
On Friday, 31 July 2015 at 11:09:39 UTC, anonymous wrote: Definitely a bug. Please file an issue at . https://issues.dlang.org/show_bug.cgi?id=14858

Re: alias overloading strange error

2015-07-31 Thread anonymous via Digitalmars-d-learn
On Friday, 31 July 2015 at 10:56:33 UTC, vitus wrote: //Why expression 'foobar(1);' doesn't work? void foo()(){} void bar(int){} alias foobar = foo; alias foobar = bar; void main(){ .foobar(1); //OK foobar(1); //Error: overload alias 'foo' is not a var

Re: Error: 'this' is only defined in non-static member functions, not main

2015-07-29 Thread anonymous via Digitalmars-d-learn
On Wednesday, 29 July 2015 at 21:33:16 UTC, remi thebault wrote: Hello I have this weird error trying to achieve something simple: That's far from simple. Here's a reduction: template wl_container_of(alias member) { size_t get() {return member.offsetof;} } struct item { int link; }

Re: Type inference of a function parameter

2015-07-29 Thread anonymous via Digitalmars-d-learn
On Wednesday, 29 July 2015 at 20:20:47 UTC, Adel Mamin wrote: void my_func(auto arr) { writeln(arr); } There are no `auto` parameters in D. You have to make it a template explicitly: void my_func(A)(A arr) { writeln(arr); }

Re: extern(C) with function returning user type

2015-07-29 Thread anonymous via Digitalmars-d-learn
On Wednesday, 29 July 2015 at 17:59:26 UTC, Kyoji Klyden wrote: How would I use a C function that's returning a struct? auto doesn't work here, and from what I can tell D can't import C headers. (If it really can't then, that would be a very welcome feature) I do have the required libs but I

Re: Dynamic memory

2015-07-29 Thread anonymous via Digitalmars-d-learn
On Tuesday, 28 July 2015 at 22:52:31 UTC, Binarydepth wrote: I'm reading the reference : http://dlang.org/arrays.html And I'm declaring two dynamic arrays as I understand. What I had in mind was declaring a dynamic array of two elements each. int[2][] is exactly an dynamic array of (arrays wi

Re: Select value from list, indexed by a type

2015-07-28 Thread anonymous via Digitalmars-d-learn
On Tuesday, 28 July 2015 at 21:12:13 UTC, Johan Engelen wrote: Hi all, I am wondering if there is any Phobos functionality for indexing into a list using a type. What I mean is something like: assert( somethingie!(float, float, double, real)(1, 22, 333) == 1 ); assert( somethingie!(dou

Re: Dynamic memory

2015-07-28 Thread anonymous via Digitalmars-d-learn
On Tuesday, 28 July 2015 at 16:41:40 UTC, Binarydepth wrote: It works with 2 as input but shows error when number is 3 :( I can't reproduce that or I misunderstood something: $ cat a.d import std.stdio : readf, writef; void main(){ int[2][] nam; int num; readf(" %

Re: Dynamic memory

2015-07-28 Thread anonymous via Digitalmars-d-learn
On Tuesday, 28 July 2015 at 16:09:46 UTC, Binarydepth wrote: Here is what I'm trying to do : import std.stdio : readf, writef; void main() { int[2][] nam; int num; readf(" %d", &num); nam.length = num; foreach(nim; 0..num){ readf("

Re: Yes or No Options

2015-07-27 Thread Anonymous via Digitalmars-d-learn
On Monday, 27 July 2015 at 16:48:00 UTC, Alex wrote: Okay. By pure trying I found out what I did wrong: Apparently by typing Y I entered the shift key. Could that have been the problem? I changed it to a small y and it at least jumped back to the commandline instead of just being stuck. And

Re: Problem with casting instance reference to void* and back.

2015-07-27 Thread anonymous via Digitalmars-d-learn
On Monday, 27 July 2015 at 13:11:33 UTC, anonymous wrote: In the first example, you pass a pointer to a class instance. You cannot get the vtbl entry for the interface like this. Instead try to do this in 2 steps: actually i meant you pass an untyped pointer, so when you cast as interface it'

Re: Problem with casting instance reference to void* and back.

2015-07-27 Thread anonymous via Digitalmars-d-learn
On Monday, 27 July 2015 at 12:03:06 UTC, Vlad Leberstein wrote: Hi! My use case requires interaction with C API which in turn implies storing object instance reference as void *. I'm using gdc 4.9.2 and everything worked fine with "object -> void * -> object" conversion, but "object -> void * -

Re: Why hide a trusted function as safe?

2015-07-26 Thread anonymous via Digitalmars-d-learn
On Sunday, 26 July 2015 at 11:38:31 UTC, simendsjo wrote: Is there a reason why you would hide the fact that a function is trusted rather than safe? Technically it doesn't matter, right? To me, it seems like this would give wrong assumptions to the caller. The reason I ask is because I found

Re: Sending an immutable object to a thread

2015-07-24 Thread anonymous via Digitalmars-d-learn
On Friday, 24 July 2015 at 21:51:44 UTC, Frank Pagliughi wrote: So then: is there a pointer notation to which you can cast the "B" reference, which thus points to the heap, but retains type identity of the heap object? There's no straight forward way to do that. D has no types for the actual

Re: Sending an immutable object to a thread

2015-07-24 Thread anonymous via Digitalmars-d-learn
On Friday, 24 July 2015 at 18:55:26 UTC, Frank Pagliughi wrote: So then, of course, I hope/wonder/assume that the pointer to the heap is sufficient to keep the heap memory alive, and that this would be OK from the GC perspective to do something like this: B* make_b_thing(int i) { cast(B*) n

Re: monitoring variable evaluation time

2015-07-20 Thread anonymous via Digitalmars-d-learn
On Monday, 20 July 2015 at 08:53:52 UTC, Clayton wrote: What could be the best-tool for monitoring the evaluation time of a variable . What I usually do is run the command :- - dmd -J. program.d Then I inspect the program.o file using vi for presence of compile-time constants and enums. I am

Re: String Metaprogramming

2015-07-18 Thread anonymous via Digitalmars-d-learn
On Saturday, 18 July 2015 at 16:18:30 UTC, Clayton wrote: Thanks , you were right . It seems there are some key words though which one has to use so that the code gets executed on compile-time .For example I had to change the second forloop to a foreach loop, `for` loops work just fine in CTF

Re: Comparison of struct with Nullable member

2015-07-17 Thread anonymous 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 end

Re: Environment variable for application storage under OSX ?

2015-07-17 Thread anonymous via Digitalmars-d-learn
On Friday, 17 July 2015 at 07:54:43 UTC, FreeSlave wrote: On Friday, 17 July 2015 at 07:33:43 UTC, Anonymous wrote: On Friday, 17 July 2015 at 07:14:24 UTC, FreeSlave wrote: On Thursday, 16 July 2015 at 21:12:05 UTC, anonymous wrote: I have the following code, working under Win and Linux: ---

Re: Infinite range of nullable elements

2015-07-17 Thread anonymous via Digitalmars-d-learn
On Friday, 17 July 2015 at 07:42:09 UTC, Roland Hadinger wrote: Here's how I would implement the basic behaviour (could be extended to also forward bidirectional and random access functions): --- auto cushion(R)(R r) if (isInputRange!R) { static if (isInfinite!R) { retu

Re: Environment variable for application storage under OSX ?

2015-07-17 Thread Anonymous via Digitalmars-d-learn
On Friday, 17 July 2015 at 07:14:24 UTC, FreeSlave wrote: On Thursday, 16 July 2015 at 21:12:05 UTC, anonymous wrote: I have the following code, working under Win and Linux: --- import std.process: environment; immutable string p; static this() { version(Win32) p = environment.get("APPDAT

Environment variable for application storage under OSX ?

2015-07-16 Thread anonymous via Digitalmars-d-learn
I have the following code, working under Win and Linux: --- import std.process: environment; immutable string p; static this() { version(Win32) p = environment.get("APPDATA"); version(linux) p = "/home/" ~ environment.get("USER"); version(OSX) p = "?"; } --- what would be the OSX e

Re: Understanding Safety of Function Pointers vs. Addresses of Functions

2015-07-14 Thread anonymous via Digitalmars-d-learn
On Tuesday, 14 July 2015 at 14:02:46 UTC, jmh530 wrote: Thanks for posting that. I figured out the issue. Before you had recommended that I use alias cos = std.math.cos; I had kept that text in. When I removed it, everything worked just fine. I'm still not sure I grasp the subtleties of alias

Re: Understanding Safety of Function Pointers vs. Addresses of Functions

2015-07-14 Thread anonymous via Digitalmars-d-learn
On Tuesday, 14 July 2015 at 01:05:21 UTC, jmh530 wrote: Note: some of the above seemed to only work when I kept the std.math.cos, std.math.sin text in there. When I take it out, I get warnings about recursive aliases. Yeah, you can't do `alias cos = givemeabettername!cos;`. That would define

Re: Understanding Safety of Function Pointers vs. Addresses of Functions

2015-07-12 Thread anonymous via Digitalmars-d-learn
On Sunday, 12 July 2015 at 21:07:34 UTC, jmh530 wrote: private template givemeabettername(alias fun) { T givemeabettername(T : U[], U)(T x) if (isArray!(T)) { return x.map!(a => fun(a)).array; You don't need the lambda, do you? -> return x.map!fun.array; } } Very

Re: opApply compilation woes

2015-07-12 Thread anonymous via Digitalmars-d-learn
On Sunday, 12 July 2015 at 17:25:17 UTC, Gary Willoughby wrote: Why does the following code fail to compile if the `writeln(value);` line is present? The error message (formatted to be a little more readable): Error: function test2.__unittestL6_1.Foo.opApply (int delegate(ref string) not

Re: Understanding Safety of Function Pointers vs. Addresses of Functions

2015-07-12 Thread anonymous via Digitalmars-d-learn
On Sunday, 12 July 2015 at 16:34:17 UTC, jmh530 wrote: I've been playing around with this a little more. I wrote this function to encapsulate a simple operation on arrays. U array_fun(T, U)(T fp, U x) if (isFunctionPointer!(T) && isArray!(U)) { return x.map!(a => fp(a)).array; }

Re: Array operations with array of structs

2015-07-11 Thread anonymous via Digitalmars-d-learn
On Saturday, 11 July 2015 at 13:31:12 UTC, Peter wrote: The postblit can only not take @nogc due to the array duplication which is understandable. I think the postblit might be redundant anyway since the struct is built on a static array so there is no possibility of two different Vect3s "point

Re: Import module

2015-07-10 Thread anonymous via Digitalmars-d-learn
On Friday, 10 July 2015 at 00:53:38 UTC, codenstuff wrote: On Friday, 10 July 2015 at 00:24:44 UTC, anonymous wrote: On Thursday, 9 July 2015 at 22:05:23 UTC, codenstuff wrote: I am trying to import module and compile. The compiler produces message map/map.d(9): Error: module game_object is i

Re: Import module

2015-07-10 Thread anonymous via Digitalmars-d-learn
On Friday, 10 July 2015 at 03:11:25 UTC, Mike Parker wrote: On Friday, 10 July 2015 at 00:53:38 UTC, codenstuff wrote: The path is ${HOME}/d_apps/steering/steering/game_object.d [...] First, because you are importing sterring.game_object, then you can't pass -I/home/real/d_apps/steering to

Re: Import module

2015-07-09 Thread anonymous via Digitalmars-d-learn
On Thursday, 9 July 2015 at 22:05:23 UTC, codenstuff wrote: I am trying to import module and compile. The compiler produces message map/map.d(9): Error: module game_object is in file 'steering/game_object.d' which cannot be read import path[0] = /usr/include/dmd/phobos import path[1] = /usr/i

Re: Understanding Safety of Function Pointers vs. Addresses of Functions

2015-07-07 Thread anonymous via Digitalmars-d-learn
On Tuesday, 7 July 2015 at 20:32:49 UTC, jmh530 wrote: Thanks for the detailed answer. All I meant here is that if I have some T foo(T)(T x), then to take the address, sometimes I've needed to &foo!int or &foo!real, etc. Ah, sure. Templates don't have addresses. Function templates are not exe

Re: Understanding Safety of Function Pointers vs. Addresses of Functions

2015-07-07 Thread anonymous via Digitalmars-d-learn
On Tuesday, 7 July 2015 at 19:54:19 UTC, jmh530 wrote: I'm not sure I understand the safety of function pointers vs. the addresses of functions. The code below illustrates the issue. I was under the impression that pointers are not allowed in safe code. No, pointers are fine. It's pointer a

Re: Correctly implementing a bidirectional range on a linked list?

2015-07-06 Thread anonymous via Digitalmars-d-learn
On Monday, 6 July 2015 at 21:58:31 UTC, anonymous wrote: To make your removal methods stable, it may be enough to not free the removed node. That is, don't do this: https://github.com/nomad-software/etcetera/blob/master/source/etcetera/collection Looks like I messed up the URL. Here's the righ

Re: Correctly implementing a bidirectional range on a linked list?

2015-07-06 Thread anonymous via Digitalmars-d-learn
On Monday, 6 July 2015 at 20:50:19 UTC, Gary Willoughby wrote: How do you correctly implement a bidirectional range on a linked list? I have a linked list implementation and I've added a range interface to it but after a while I've realized it not quite right. The problem is when I call the s

Re: Array operations with array of structs

2015-07-06 Thread anonymous via Digitalmars-d-learn
On Monday, 6 July 2015 at 12:15:22 UTC, Peter wrote: dmd 2.066.1, windows 7 64bit Tested it on Windows 7, using dmd 2.066.1: works for me. The exact code I tested (just commented those "..." out): struct Vector3 { public double[3] _p; //... Vector3 opBinary(string op)(in Vecto

Re: Array operations with array of structs

2015-07-06 Thread anonymous 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: [...] unittest{ auto a = Vector3([2.0, 2.0, 0.0]); auto b = Vector3([1.0, 2.0, 1.0]); Vector3[] c = [a]; Vector3[] d = [b]; Vector3 e = a + b; // works Vec

Re: Array operations with array of structs

2015-07-06 Thread anonymous 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: incorrect data when returning static array in place of dynamic

2015-07-06 Thread anonymous via Digitalmars-d-learn
On Monday, 6 July 2015 at 07:48:17 UTC, sigod wrote: Aren't compiler smart enough to prevent it? ``` ubyte[] test1() { auto b = sha1Of(""); return b; // Error: escaping reference to local b } ubyte[] test2() { return sha1Of(""); // works, but returns incorrect data } ``

Re: time difference - beautify my code

2015-07-02 Thread anonymous via Digitalmars-d-learn
On Thursday, 2 July 2015 at 19:03:49 UTC, dd0s wrote: i got a date t described in seconds from 1.1.1970, I.e., you have a unix timestamp. and i want to check if the current time is further than 12 hours from the given time t. the following code works but it's super ugly =S please give me s

Re: lovely compiler error message - incompatible types

2015-07-02 Thread anonymous via Digitalmars-d-learn
On Thursday, 2 July 2015 at 17:33:29 UTC, Laeeth Isharc wrote: Any thoughts on what could be leading to the following: ./../../marketdata/source/pricebar.d(397): Error: incompatible types for ((bar.high) + (bar.low)): 'FixedDecimal!(int, 8)' and 'FixedDecimal!(int, 8)' ../../../marketdata/sourc

Re: wrong struct alignment

2015-07-01 Thread anonymous via Digitalmars-d-learn
On Wednesday, 1 July 2015 at 20:01:08 UTC, dd0s wrote: i have the following struct, and i expect it to have 30 bytes but sizeof tells me it has 32 bytes. dmd seems to still use 4byte alignment altough i specified to align 2bytes. struct netadr_t { align(2): inttype; // 0 in

Re: Same process to different results?

2015-07-01 Thread anonymous via Digitalmars-d-learn
On Wednesday, 1 July 2015 at 17:13:03 UTC, Taylor Hillegeist wrote: string q = cast(string) (A.cycle.take(seg1len).array ~B.cycle.take(seg2len).array ~C.cycle.take(seg3len).array); q.writeln; I was wondering if it might be the cast? Yes, the cast is wrong. You're reinterpreting (not

Re: Template Declarations - Why not Template definitions?

2015-06-30 Thread anonymous via Digitalmars-d-learn
On Tuesday, 30 June 2015 at 21:06:58 UTC, WhatMeWorry wrote: All the stuff I've read about templates always refers to them as template declarations. So with the following code segment: template codeBlockTemplate(T, U) { T a = 7; U b = 'z'; } codeBlockTemplate!(int, char); // error he

Re: goroutines vs vibe.d tasks

2015-06-30 Thread anonymous via Digitalmars-d-learn
On Tuesday, 30 June 2015 at 15:18:36 UTC, Jack Applegame wrote: Just creating a bunch (10k) of sleeping (for 100 msecs) goroutines/tasks. Compilers go: go version go1.4.2 linux/amd64 vibe.d: DMD64 D Compiler v2.067.1 linux/amd64, vibe.d 0.7.23 Code go: http://pastebin.com/2zBnGBpt vibe

Re: Why D doesn't have an equivalent to C#'s readonly?

2015-06-30 Thread anonymous via Digitalmars-d-learn
On Monday, 29 June 2015 at 22:11:16 UTC, sigod wrote: `new immutable(MyClass)()` is invalid code. It's perfectly fine, actually.

Re: Bug or feature?

2015-06-30 Thread anonymous via Digitalmars-d-learn
On Monday, 29 June 2015 at 12:04:46 UTC, Jonathan M Davis wrote: You haven't declared an immutable constructor, so you can't construct an immutable Foo. That's not what's happening. Constructing an immutable Foo works just fine.

Re: Map Purity

2015-06-30 Thread anonymous via Digitalmars-d-learn
On Sunday, 28 June 2015 at 16:28:20 UTC, jmh530 wrote: Thanks for the reply. Two follow ups: 1) Does labeling a template as pure matter if the compiler infers it anyway? 2) Does the compiler also infer anything for @safe/nothrow in templates? 1) It means you can't instantiate the template fun

Re: Pure delegate not quite pure?

2015-06-28 Thread anonymous via Digitalmars-d-learn
On Sunday, 28 June 2015 at 09:19:16 UTC, Tofu Ninja wrote: module main; import std.stdio; void main(string[] args) { auto d = foo(); writeln(d()); // prints 25 } auto foo() { int x = 4; pure int delegate() d = delegate() { return x*x;

Re: how to string → uint* ?

2015-06-28 Thread anonymous via Digitalmars-d-learn
On Sunday, 28 June 2015 at 01:57:46 UTC, xky wrote: hello. :-) when i was using DerelictSFML2( http://code.dlang.org/packages/derelict-sfml2 ), i got this problem. CSFML doc had 'setUnicodeString': CSFML_GRAPHICS

Re: Program exited with code -11

2015-06-23 Thread anonymous via Digitalmars-d-learn
On Tuesday, 23 June 2015 at 07:57:26 UTC, Charles Hawkins wrote: Sigh. I'm probably doing something stupid. I tried full paths: dmd -I+/home/charles/projects/d/mylib/source/mylib/ myprog.d What's that plus sign doing there? Looks wrong. /home/charles/projects/d/mylib/build/libmylib.a Same

Re: core.exception.InvalidMemoryOperationError@(0) on File Reading.

2015-06-22 Thread anonymous via Digitalmars-d-learn
On Monday, 22 June 2015 at 20:30:40 UTC, David DeWitt wrote: I am getting an core.exception.InvalidMemoryOperationError@(0) auto recs = f // Open for reading .byLineCopy(); .array; //Here is where is appears to be happening. I have

Re: How do I make my class iterable?

2015-06-22 Thread anonymous via Digitalmars-d-learn
On Monday, 22 June 2015 at 18:44:22 UTC, Assembly wrote: I'm using this, thanks for all. Can someone clarify how does opApply() works? I assume it's called every iteration and as opApply() has a loop does it means the number of iteration ran actually is the ones from foreach() is 2*n where n is

Re: Defining constant values in struct

2015-06-16 Thread anonymous via Digitalmars-d-learn
On Tuesday, 16 June 2015 at 21:17:37 UTC, 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, using enum with string doesn't seem like a

Re: Casting MapResult

2015-06-15 Thread anonymous via Digitalmars-d-learn
On Monday, 15 June 2015 at 15:10:24 UTC, jmh530 wrote: float[] exp(float[] x) { auto y = x.map!(a => exp(a)); cast(float[]) y; return y; } But I get an error that I can't convert MapResult!(__lambda2, float[]) to float[]. So I suppose I have two questions: 1) am I scre

Re: __traits getMember is context sensetive?

2015-06-14 Thread anonymous via Digitalmars-d-learn
On Sunday, 14 June 2015 at 10:41:24 UTC, JDemler wrote: So if i want to use parameters in a static context at compile time i have to pass them as template parameters? Yes, template parameters are fine.

Re: __traits getMember is context sensetive?

2015-06-14 Thread anonymous via Digitalmars-d-learn
On Sunday, 14 June 2015 at 10:10:51 UTC, ketmar wrote: i.e. when it need a value in compile time. the interpreter is invoked, it evaluates (interprets) the given code (function or template instantiation), and then it returns result (or raises an error). One important thing I didn't see stated

Re: Qualified destructors / immutable objects

2015-06-14 Thread anonymous via Digitalmars-d-learn
To come back to destructors and immutable objects: Even without the default initialized variables issue it is possible to modify immutable data: struct S { int[] bar; ~this() { bar[0] = 123; } } void foo(immutable(int[]) i) { immutable(S) s = immutable S(i); } void main() { im

Re: Qualified destructors / immutable objects

2015-06-13 Thread anonymous via Digitalmars-d-learn
Is there an existing issue on issue.dlang.org? If not can you report it https://issues.dlang.org/show_bug.cgi?id=10376

Re: char[][] to std::vector - DIP or dmd-issue?

2015-06-13 Thread anonymous via Digitalmars-d-learn
On Saturday, 13 June 2015 at 17:02:06 UTC, Dennis Ritchie wrote: On Saturday, 13 June 2015 at 16:20:46 UTC, anonymous wrote: [...] Yeah, that would be neat. But typing out ".dup" isn't that bad, and converting a `string[]` to a `char[][]` is simple: import std.conv: to; auto a = ["foo"].to

Re: char[][] to std::vector - DIP or dmd-issue?

2015-06-13 Thread anonymous via Digitalmars-d-learn
On Saturday, 13 June 2015 at 15:58:44 UTC, Dennis Ritchie wrote: On Saturday, 13 June 2015 at 15:45:34 UTC, anonymous wrote: Before jumping to a solution, please elaborate on the perceived problem. I have a feeling that there is none. Do you like to write? char[][] strArray = ["foo".dup, "bar"

Re: char[][] to std::vector - DIP or dmd-issue?

2015-06-13 Thread anonymous via Digitalmars-d-learn
On Saturday, 13 June 2015 at 16:09:58 UTC, Dennis Ritchie wrote: On Saturday, 13 June 2015 at 15:45:34 UTC, anonymous wrote: [...] Are you saying that `string[]` is simpler than `char[][]`? That's not true: `string` is an alias for `immutable(char)[]`, so `string[]` is the same as `immutable(c

Re: char[][] to std::vector - DIP or dmd-issue?

2015-06-13 Thread anonymous via Digitalmars-d-learn
On Saturday, 13 June 2015 at 15:21:19 UTC, Dennis Ritchie wrote: Hello, everyone! I like to work with arrays of strings like `string[] strArray`, but unfortunately, they are immutable. I do not like to work with arrays of strings such as `char[][] strArray`, because it is necessary to apply

Re: Conditional Compilation Multiple Versions

2015-06-13 Thread anonymous via Digitalmars-d-learn
On Saturday, 13 June 2015 at 00:47:37 UTC, Mike Parker wrote: // config.d version(One) enum One = true; else enum One = false; version(Two) enum Two = true; else enum Two = false; // other.d import config; static if(One || Two) { ... } Taking it one step further: template Version(string

Re: Qualified destructors / immutable objects

2015-06-12 Thread anonymous via Digitalmars-d-learn
no need for ~this() to modify immutable data: class C { int a; this(int a) { this.a = a; } } struct S { C elem = new C(42); } void main() { import std.stdio; immutable(S) s1; // Error: cannot modify immutable expression s1.e

Re: Qualified destructors / immutable objects

2015-06-12 Thread anonymous via Digitalmars-d-learn
I cannot find a way to actually modify immutable memory with it... a.d: class C { int a; this(int a) { this.a = a; } } struct S { int x; C elem = new C(42); ~this() { import std.stdio; writeln("mutable ~this()"); x = 1; elem.a = 123;

Re: Reading array of integers readln performance issues

2015-06-11 Thread anonymous via Digitalmars-d-learn
On Thursday, 11 June 2015 at 19:56:00 UTC, kerdemdemir wrote: Can I achieve something faster than code below? auto peopleMoney = stdin.readln().split().map!(a => to!int(a)).array(); if (peopleMoney.length == 20) writeln(":("); `std.array.split` is eager. It may be faster if you

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

2015-06-10 Thread anonymous via Digitalmars-d-learn
On Wednesday, 10 June 2015 at 17:00:34 UTC, Dennis Ritchie wrote: Isnt it possible to come up with the interpreter compile-time, which will determine the operating time of the program at runtime at compile time. Sounds like the halting problem. So, no, generally this is not possible.

Re: simple template constraint - compile error.

2015-06-07 Thread anonymous via Digitalmars-d-learn
On Sunday, 7 June 2015 at 23:08:02 UTC, WhatMeWorry wrote: However, when I try to add a simple constraint to the function like so: int arrayByteSize(T)(T[] someArray) if (isDynamicArray(T)) You forgot an exclamation mark here. Make that: isDynamicArray!(T)

Re: How to remove the key from the `redBlackTree` with comparator" a <= b "?

2015-06-07 Thread anonymous via Digitalmars-d-learn
On Sunday, 7 June 2015 at 19:04:08 UTC, Dennis Ritchie wrote: OK. But I want to return a `upperBound` segment with the included `key`. It does not suit me: auto rbt = redBlackTree!("a < b", int)(1, 2, 3, 4, 5); writeln(rbt.upperBound(3)); // prints [4, 5] I want it to be so: auto rbt = redBla

Re: How to remove the key from the `redBlackTree` with comparator" a <= b "?

2015-06-07 Thread anonymous via Digitalmars-d-learn
On Sunday, 7 June 2015 at 18:42:58 UTC, Dennis Ritchie wrote: How do I remove the key from the `redBlackTree` with comparator "a <= b" ? Do not use '<=' as a comparison function with RedBlackTree. It doesn't meet the requirements. Quoting the documentation [1]: Note that less should produce

<    1   2   3   4   5   6   >