Re: How to create a mutable array of strings?

2015-05-17 Thread anonymous via Digitalmars-d-learn
On Sunday, 17 May 2015 at 09:26:15 UTC, Dennis Ritchie wrote: And no crashes on Windows :) Yeah, on windows it's even worse. void main() { auto s = cast(char[][])["foo", "bar"]; s[1][1] = 't'; import std.stdio; writeln("bar"); }

Re: ICE?

2015-05-17 Thread anonymous via Digitalmars-d-learn
On Sunday, 17 May 2015 at 10:09:11 UTC, Daniel Kozak wrote: On Sunday, 17 May 2015 at 09:25:33 UTC, Namespace wrote: [...] Error: e2ir: cannot cast malloc(length * 8u) of type void* to type char[] I would say this is not an ICE just normal error message. "e2ir: " shouldn't be there, though.

Re: Const is already there. It cannot deduce it

2015-05-18 Thread anonymous via Digitalmars-d-learn
On Sunday, 17 May 2015 at 21:34:21 UTC, tcak wrote: [code] void test(D)( const D data ) if( is(D: shared(char[]) ) ) { } void main() { char[] text = new char[4]; text[0] = 'a'; text[1] = 'b'; text[2] = 'c'; text[3] = 'd'; auto t = cast( shared(const(char[])) )tex

Re: Capturing Caller UDAs as CT Template Function Parameters

2015-05-18 Thread anonymous via Digitalmars-d-learn
On Monday, 18 May 2015 at 21:35:44 UTC, Per Nordlöw wrote: void yield(T)(ref T value) { mixin("alias caller = " ~ caller ~ ";"); } doesn't work across module boundaries not even for `__PRETTY_FUNCTION__`. Do we need need to fix the compiler, Walter?! ;) You have to impor

Re: -vgc Info ok?

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

Re: Python's features, which requires D

2015-05-23 Thread anonymous via Digitalmars-d-learn
On Saturday, 23 May 2015 at 20:25:18 UTC, Dennis Ritchie wrote: This does not work! enum n1 = 5; writeln(stdin.byLine .map!(line => line.split(" ").map!(x => to!int(x))) ); - http://rextester.com/VGHZF81178 The code itself is ok. That site has broken newlines. You can see here tha

Re: Python's features, which requires D

2015-05-23 Thread anonymous via Digitalmars-d-learn
On Saturday, 23 May 2015 at 21:08:19 UTC, Dennis Ritchie wrote: Perhaps that's not the site, and in Windows. That's what gives me in CMD: 456 4 4 8 99 456 [[456, 4, 4, 8, 99, 456]13 546 std.conv.ConvException@C:\D\dmd2\windows\bin\..\..\src\phobos\std\conv.d(2013): Unexpected end of input when

Re: ctfe and static arrays

2015-05-24 Thread anonymous via Digitalmars-d-learn
On Sunday, 24 May 2015 at 17:35:39 UTC, Jay Norwood wrote: I'm a bit confused by the documentation of the ctfe limitations wrt static arrays due to these seemingly conflicting statements, and the examples didn't seem to clear anything up. I was wondering if anyone has examples of clever things

Re: ctfe and static arrays

2015-05-24 Thread anonymous via Digitalmars-d-learn
On Sunday, 24 May 2015 at 18:14:19 UTC, anonymous wrote: "Static array" has a special meaning. It does not mean "static variable with an array type". Static arrays are those of the form Type[size]. That is, the size is known statically. PS: You may also see the term "fixed-size array" which me

Re: ctfe and static arrays

2015-05-24 Thread anonymous via Digitalmars-d-learn
On Sunday, 24 May 2015 at 20:53:03 UTC, Jay Norwood wrote: On Sunday, 24 May 2015 at 18:14:19 UTC, anonymous wrote: [...] 1) static int[5] x; -- x is a static variable with a static array type 2) static int[] x; -- static variable, dynamic array 3) int[5] x; -- non-static variable, static arra

Re: Replacing nested loops foreach using map/each/etc

2015-05-25 Thread anonymous via Digitalmars-d-learn
On Monday, 25 May 2015 at 17:52:09 UTC, Dennis Ritchie wrote: But why is the solution breaks down when `s = 1` ? :) import std.stdio, std.algorithm, std.range; int c; const x = 12, y = 65, z = 50, s = 10; Which is it, now? 4 or 5 zeros? void solve(Range)(Range r) { cartesianProduct

Re: data-oriented struct abstraction ?

2015-05-30 Thread Anonymous via Digitalmars-d-learn
This may be somewhat related. http://forum.dlang.org/thread/ckeqxhkqjyvmqodrf...@forum.dlang.org#post-m9rj0d:242m9e:243:40digitalmars.com https://github.com/economicmodeling/soa On Saturday, 30 May 2015 at 14:17:51 UTC, short2cave wrote: On Saturday, 30 May 2015 at 13:57:28 UTC, Rikki Cattermo

Re: Woldemort Type can't even call "take" or "array"

2015-05-31 Thread anonymous via Digitalmars-d-learn
On Sunday, 31 May 2015 at 08:02:10 UTC, Ali Çehreli wrote: auto maxElement(R)(R range) { return reduce!((current, a) => current >= a ? current : a) (ElementType!R.min, range); } [...] auto result = numArr.maxElement; Can be shortened to `auto result = numArr.reduce!m

Re: Woldemort Type can't even call "take" or "array"

2015-05-31 Thread anonymous via Digitalmars-d-learn
On Sunday, 31 May 2015 at 07:45:02 UTC, kerdemdemir wrote: Unfortunately not this time :) import std.stdio; import std.algorithm; import std.string; import std.conv; import std.array; ---> I added this line thanks to you. `take` is in `std.range`. Try importing that.

Re: template instance template 'appender' is not defined

2015-05-31 Thread anonymous via Digitalmars-d-learn
On Sunday, 31 May 2015 at 21:33:53 UTC, Assembly wrote: why that page I've linked use std.format? You mean that first example? Simple oversight. It's already fixed in the prerelease version where it imports std.array now: http://dlang.org/phobos-prerelease/std_format.html

Re: TypeTuple!(T...) vs Tuple!(T...)

2015-06-02 Thread anonymous via Digitalmars-d-learn
On Tuesday, 2 June 2015 at 08:10:27 UTC, rsw0x wrote: The tuple page is even confusing me http://dlang.org/tuple.html A variable declared with a TypeTuple becomes an ExpressionTuple: alias TL = Tuple!(int, long); is it using Tuple!(T...) and TypeTuple!(T...) interchangeably? Almost. `Tuple

Re: TypeTuple!(T...) vs Tuple!(T...)

2015-06-02 Thread anonymous via Digitalmars-d-learn
On Tuesday, 2 June 2015 at 09:34:28 UTC, Ali Çehreli wrote: On 06/02/2015 01:10 AM, rsw0x wrote: [...] The tuple page is even confusing me http://dlang.org/tuple.html [...] Tuple can hold only values, TypeTuple can hold types as well. Tuple can be created at run time, TypeTuple is a compile

Re: InvalidMemoryOperationError from File.byLine()?

2015-06-02 Thread anonymous via Digitalmars-d-learn
On Tuesday, 2 June 2015 at 19:18:15 UTC, Stiff wrote: Hi, I'm reading in a rather large text file (~25Mb) line by line, where I don't need to hang on to a line for more than one iteration through my loop. I'm consistently getting an InvalidMemoryOperationError on my 2,547th iteration, and bas

Re: The Kernighan-Ritchie allocator is back with a vengeance

2015-06-02 Thread anonymous via Digitalmars-d-learn
On Tuesday, 2 June 2015 at 19:47:09 UTC, Andrei Alexandrescu wrote: I just updated the Kernighan-Ritchie allocator, including documentation: Wrong board?

Re: InvalidMemoryOperationError from File.byLine()?

2015-06-02 Thread anonymous via Digitalmars-d-learn
On Tuesday, 2 June 2015 at 20:56:41 UTC, Steven Schveighoffer wrote: Hm... I think the issue might possibly be solved. What version of the compiler are you using? I think 14005 (and 14578) are fixed in git head, because there's no assumeSafeAppend in byLine anymore. But the underlying issue

Re: InvalidMemoryOperationError from File.byLine()?

2015-06-02 Thread anonymous via Digitalmars-d-learn
On Tuesday, 2 June 2015 at 21:43:45 UTC, Stiff wrote: So...in the meantime, I'll just pad my input I guess? It's a mess and I'm not sure what works and what doesn't, but here are some options: byLineCopy: Could be fine as it doesn't reuse any buffers. readln without passing a buffer: as abo

Re: Template elegance?

2015-06-03 Thread anonymous via Digitalmars-d-learn
On Wednesday, 3 June 2015 at 09:10:22 UTC, David Monagle wrote: What I was looking for is a more elegant way of defining those secondary functions. Originally I was hoping I could do something like: enum shouldEqual(E, V) = shouldValue((e, v) => e == v, "equal", E, V); Here you go: tem

Re: string to char array?

2015-06-03 Thread anonymous via Digitalmars-d-learn
On Wednesday, 3 June 2015 at 10:21:20 UTC, Kyoji Klyden wrote: On Wednesday, 3 June 2015 at 08:11:16 UTC, Kagamin wrote: On Tuesday, 2 June 2015 at 16:41:38 UTC, Kyoji Klyden wrote: [...] string source = readText("test.glvert"); const char* sources = source.ptr; [...]

Re: string to char array?

2015-06-03 Thread anonymous via Digitalmars-d-learn
On Wednesday, 3 June 2015 at 10:56:21 UTC, Kyoji Klyden wrote: So in "const char* sources = source.ptr;" sources is just turning the property ptr of source into a variable, yes and then in glShaderSource you're passing the memory address of sources yes (which is technically source.ptr)

Re: string to char array?

2015-06-03 Thread anonymous via Digitalmars-d-learn
On Wednesday, 3 June 2015 at 11:23:09 UTC, Kyoji Klyden wrote: Ooooh okay, I'm starting to get it. I think this last question should clear it up for me: When a string is made, how is the struct Slice handled? What does ptr get assigned? ptr is a pointer to the first char, in other words the ad

Re: Array declaration warning

2015-06-03 Thread anonymous via Digitalmars-d-learn
On Wednesday, 3 June 2015 at 20:28:57 UTC, Paul wrote: Ooops, this is what I meant to post: struct CoOrd { int x, y; } CoOrd[][NumPaths]pathList; I append values like so... pathList[][n] ~= CoOrd(cX, cY); The "[]" does nothing here. You can leave it (or add more) out without chang

Re: Error: field r must be initialized in constructor, because it is nested struct

2015-06-03 Thread anonymous via Digitalmars-d-learn
On Wednesday, 3 June 2015 at 23:27:31 UTC, Ali Çehreli wrote: Pretty standard thing doesn't work and I can't find it on bugzilla: import std.algorithm; struct Foo(R) { R r; this(R r)// <-- Compilation error {} } auto foo(R)(R r) { return Foo!R(r); } void main() { aut

Re: Does using "const" keyword for scalar parameters mean anything?

2015-06-04 Thread anonymous via Digitalmars-d-learn
On Thursday, 4 June 2015 at 11:28:51 UTC, tcak wrote: [code] void test( const int a ){} [/code] Does that "const" make any difference at all? At the end, it is a scalar, and passed as value. All it does is it makes the variable "a" const: void test( const int a ) { a = 42; /* Error:

Re: string to char array?

2015-06-04 Thread anonymous via Digitalmars-d-learn
On Thursday, 4 June 2015 at 21:35:40 UTC, Kyoji Klyden wrote: On Thursday, 4 June 2015 at 03:25:24 UTC, ketmar wrote: On Wed, 03 Jun 2015 11:59:56 +, Kyoji Klyden wrote: [...] what exactly is char**? Is it pointing to the first char of the first string in an array? it's a pointer to a

Re: Emulation macros and pattern matching on D

2015-06-05 Thread anonymous via Digitalmars-d-learn
On Friday, 5 June 2015 at 14:15:09 UTC, Dennis Ritchie wrote: For example, why here I can simply write: void main() { int b = 5; mixin(`int a = b;`); assert(a == 5); } This becomes: int b = 5; int a = b; assert(a == 5); Why should not I write like this: void main()

Re: string to char array?

2015-06-05 Thread anonymous via Digitalmars-d-learn
On Friday, 5 June 2015 at 17:27:18 UTC, Kyoji Klyden wrote: On Thursday, 4 June 2015 at 22:28:50 UTC, anonymous wrote: [...] By the way, there are subtly different meanings of "array" and "string" which I hope you're aware of, but just to be sure: "array" can refer to D array types, i.e. a poin

Re: string to char array?

2015-06-05 Thread anonymous via Digitalmars-d-learn
On Friday, 5 June 2015 at 19:30:58 UTC, Kyoji Klyden wrote: Okay, so it's primarily an interfacing with C problem that started all this? (My brain is just completely scrambled at this point xP ) Yeah, you wanted to call glShaderSource, which is a C function and as such it's not aware of D sli

Re: Initialising global associative array

2015-06-06 Thread anonymous via Digitalmars-d-learn
On Saturday, 6 June 2015 at 20:30:50 UTC, Paul wrote: However, I now get an 'undefined identifier' error when compiling and trying to access the AA from a function within the same module. static this() { string[string] tagWords = [ "DIST" : "Distance", . } ... if(tag in tagWords)

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

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: 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: 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: 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: 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: 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: 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: 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: 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 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: 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: 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: __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: __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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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 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: 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: 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: 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: 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: 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: 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-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: 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: 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: 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 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: 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-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

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: 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

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: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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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-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: 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

<    1   2   3   4   5   6   >