Re: Why are immutable array literals heap allocated?

2019-07-06 Thread Nick Treleaven via Digitalmars-d-learn
On Friday, 5 July 2019 at 23:05:32 UTC, Jonathan M Davis wrote: Yes, I was wondering why the compiler doesn't statically allocate it automatically as an optimization. It would have to be set up to store the literal somewhere else. I was thinking the read-only data segment. Certainly, it

Re: Why are immutable array literals heap allocated?

2019-07-05 Thread Nick Treleaven via Digitalmars-d-learn
On Thursday, 4 July 2019 at 11:06:36 UTC, Eugene Wissner wrote: static immutable arr = [1, 2]; You have to spell it out that the data is static. Yes, I was wondering why the compiler doesn't statically allocate it automatically as an optimization.

Why are immutable array literals heap allocated?

2019-07-04 Thread Nick Treleaven via Digitalmars-d-learn
immutable(int[]) f() @nogc { return [1,2]; } onlineapp.d(2): Error: array literal in `@nogc` function `onlineapp.f` may cause a GC allocation This makes dynamic array literals unusable with @nogc, and adds to GC pressure for no reason. What code would break if dmd used only static data

Re: [TWiD] static foreach loop variable

2019-05-28 Thread Nick Treleaven via Digitalmars-d-learn
Ok, thanks for explaining. Nice idea.

Re: Create object from a library's Class returns Null

2019-05-28 Thread Nick Treleaven via Digitalmars-d-learn
On Tuesday, 28 May 2019 at 09:25:51 UTC, dangbinghoo wrote: class NSconf { String name; ... } Does this class have a non-default constructor?

Re: Create object from a library's Class returns Null

2019-05-28 Thread Nick Treleaven via Digitalmars-d-learn
On Tuesday, 28 May 2019 at 09:25:51 UTC, dangbinghoo wrote: writeln(Object.factory("gwlib.entity.nsconf.NSConf")); Typo, should be NSconf.

[TWiD] static foreach loop variable

2019-05-28 Thread Nick Treleaven via Digitalmars-d-learn
Hi, Last week's TWiD had a tip that didn't make sense: http://dpldocs.info/this-week-in-d/Blog.Posted_2019_05_20.html#tip-of-the-week template Locals(int i) { alias Whatever = int; } static foreach(i; [1, 2, 3]) { Locals!i.Whatever; } The body is just `int;`. Not sure how to reach Adam.

Re: Escaping address of

2018-04-12 Thread Nick Treleaven via Digitalmars-d-learn
On Thursday, 12 April 2018 at 00:32:49 UTC, Uknown wrote: Adding a destructor makes the compiler return an error about lifetimes, with or without -dip1000 Thanks. Filed, mentioning this: https://issues.dlang.org/show_bug.cgi?id=18756

Escaping address of

2018-04-11 Thread Nick Treleaven via Digitalmars-d-learn
Is this a known bug? With v2.079.0, with or without -dip1000: @safe unittest { struct S { int i; } auto p = ().i; } The address of field `i` should not escape, right? It's also incorrectly allowed when using an lvalue of S (when -dip1000 is not present).

Re: how to make private class member private

2018-03-29 Thread Nick Treleaven via Digitalmars-d-learn
On Sunday, 18 March 2018 at 18:45:23 UTC, Steven Schveighoffer wrote: unittest { auto foo = new Foo; assert(foo.internalbuffer.empty); // note, this is a private symbol. } I don't understand why you would want a private symbol in a *documented* unittest, the reader of the

Re: how to make private class member private

2018-03-17 Thread Nick Treleaven via Digitalmars-d-learn
On Tuesday, 13 March 2018 at 13:59:00 UTC, Steven Schveighoffer wrote: If you limit to class members, then you have to do something like C++ friends, which are unnecessarily verbose. Not if you also have a module-level visibility modifier, which could have been `module`. IMO, the

Re: how to make private class member private

2018-03-17 Thread Nick Treleaven via Digitalmars-d-learn
On Tuesday, 13 March 2018 at 05:11:48 UTC, psychoticRabbit wrote: If you have access to the module source, you have access to the source of types inside it. Making the module the lowest level of encapsulation makes sense from that perspective. There are two problems I see: 1st - D has broken

Re: building git druntime - range violation in extendedPathThen

2017-12-07 Thread Nick Treleaven via Digitalmars-d-learn
On Wednesday, 6 December 2017 at 17:11:49 UTC, Nick Treleaven wrote: 0x005482C2 in nothrow void* ddmd.root.filename.extendedPathThen!(ddmd.root.file.File.read().__lambda1).extendedPathThen(const(char*)) at C:\git\dmd\src\ddmd\root\filename.d(834) 0x005480E8 in File at

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

2017-12-06 Thread Nick Treleaven via Digitalmars-d-learn
On Wednesday, 6 December 2017 at 17:04:06 UTC, A Guy With a Question wrote: abstract class Test(T) Here you have a class template. It does produce there error when I do this: class Test2 : Test!int You instantiated the template, so the compiler can now type check the instantiated

building git druntime - range violation in extendedPathThen

2017-12-06 Thread Nick Treleaven via Digitalmars-d-learn
Hi, I checked out dmd and druntime this morning. dmd seems to build fine, but when I try druntime I get this error: $ make -f win32.mak ..\dmd\generated\windows\release\32\dmd -conf= -c -o- -Isrc -Iimport -Hfimport\core\sync\barrier.di src\core\sync\barrier.d DMD v2.077.1 DEBUG

Re: Andrei's "The D Programming Language" book. Up to date?

2017-11-29 Thread Nick Treleaven via Digitalmars-d-learn
On Wednesday, 29 November 2017 at 17:50:59 UTC, Arun Chandrasekaran wrote: Multiple alias this You can only have one subtyping member currently. Shared Not all of shared's guarantees are implemented yet. SafeD @safe (and therefore SafeD) isn't fully implemented. So, it doesn't necessarily

Re: Andrei's "The D Programming Language" book. Up to date?

2017-11-29 Thread Nick Treleaven via Digitalmars-d-learn
On Wednesday, 4 October 2017 at 20:49:26 UTC, John Gabriele wrote: What's changed in the language, library, and community since then that I should be aware of if following along with and learning from that book? Here's a list of significant things - maybe incomplete:

Re: Compile time foreach with switch

2017-04-24 Thread Nick Treleaven via Digitalmars-d-learn
On Saturday, 22 April 2017 at 11:56:31 UTC, Nick Treleaven wrote: If I compile the above I get: Deprecation: switch case fallthrough - use 'goto default;' if intended IMO the compiler should issue this warning with the OP's code. https://issues.dlang.org/show_bug.cgi?id=7390#c4

Re: Compile time foreach with switch

2017-04-22 Thread Nick Treleaven via Digitalmars-d-learn
On Friday, 21 April 2017 at 19:17:32 UTC, Adam D. Ruppe wrote: Then realize that it does exactly the same thing when it is inside a switch... it always breaks the innermost thing, which happens to be this loop. (note that cases are not `breaked`, the switch is.) By coincidence I ran into

Re: Can we disallow appending integer to string?

2017-04-21 Thread Nick Treleaven via Digitalmars-d-learn
On Friday, 21 April 2017 at 08:36:12 UTC, Nick Treleaven wrote: Converting from char types -> integers, whilst (arguably) bug prone, at least is numerically sound. So perhaps we could disallow uint -> dchar, which is unsound. That is in the general case - when VRP can prove an integer fits

Re: Can we disallow appending integer to string?

2017-04-21 Thread Nick Treleaven via Digitalmars-d-learn
On Thursday, 20 April 2017 at 11:05:00 UTC, Nick Treleaven wrote: On Wednesday, 19 April 2017 at 14:50:38 UTC, Stanislav Blinov wrote: Because integrals implicitly convert to characters of same width (byte -> char, short -> wchar, int -> dchar). Despite char.min > byte.min, char.max <

Re: Can we disallow appending integer to string?

2017-04-20 Thread Nick Treleaven via Digitalmars-d-learn
On Wednesday, 19 April 2017 at 14:50:38 UTC, Stanislav Blinov wrote: Because integrals implicitly convert to characters of same width (byte -> char, short -> wchar, int -> dchar). Despite char.min > byte.min, char.max < byte.max. Anyway, appending an integer is inconsistent because

Can we disallow appending integer to string?

2017-04-19 Thread Nick Treleaven via Digitalmars-d-learn
This bug is fixed as the code no longer segfaults but throws instead: https://issues.dlang.org/show_bug.cgi?id=5995 void main(){ string ret; int i = -1; ret ~= i; } Why is it legal to append an integer?

Re: A simplification of the RvalueRef idiom

2016-11-27 Thread Nick Treleaven via Digitalmars-d-learn
On Friday, 25 November 2016 at 17:21:52 UTC, Nick Treleaven wrote: I've started documenting it now, will post a PR soon. https://github.com/dlang/dlang.org/pull/1519

Re: A simplification of the RvalueRef idiom

2016-11-25 Thread Nick Treleaven via Digitalmars-d-learn
On Thursday, 24 November 2016 at 00:35:39 UTC, TheGag96 wrote: The thing that gets me more is "return" as a function attribute. I see it under "MemberFunctionAttribute" in the grammar but I can't find an explanation for its use anywhere... I've started documenting it now, will post a PR soon.

Re: arr.ptr, @safe and void*

2016-06-16 Thread Nick Treleaven via Digitalmars-d-learn
On Wednesday, 15 June 2016 at 20:33:54 UTC, Steven Schveighoffer wrote: It could probably do this. Dereferencing a void * isn't valid, so it kind of has the same effect. However, there are many functions which take void * and do write to/read from the data pointing at it (e.g. memcpy). These

Re: arr.ptr, @safe and void*

2016-06-15 Thread Nick Treleaven via Digitalmars-d-learn
On Wednesday, 15 June 2016 at 17:35:49 UTC, Steven Schveighoffer wrote: On 6/15/16 6:32 AM, Nick Treleaven wrote: My question is: would returning void* instead really be unsafe, i.e. is there a way of dereferencing it in safe code? (I'm not thinking about holes in @safe, but ways by

arr.ptr, @safe and void*

2016-06-15 Thread Nick Treleaven via Digitalmars-d-learn
Hi, Walter's made a fix for arr[$..$].ptr being unsafe to dereference - .ptr will be @system: https://github.com/dlang/dmd/pull/5860 A referenced druntime pull mentioned having a safe wrapper for .ptr that allows comparison of the pointer value, but does not allow dereference. The wrapper

Re: Instantiate!(Template, args) in Phobos?

2016-04-25 Thread Nick Treleaven via Digitalmars-d-learn
On 25/04/2016 11:16, Nick Treleaven wrote: On Friday, 22 April 2016 at 19:09:40 UTC, David Nadlinger wrote: alias Instantiate(alias Template, Params...) = Template!Params; Ah, maybe I'd even seen this in passing and forgot. Good point about aliasSeq template elements, let's make this public.

Re: Instantiate!(Template, args) in Phobos?

2016-04-25 Thread Nick Treleaven via Digitalmars-d-learn
On Friday, 22 April 2016 at 19:09:40 UTC, David Nadlinger wrote: From std.meta: --- /* * Instantiates the given template with the given list of parameters. * * Used to work around syntactic limitations of D with regard to instantiating * a template from an alias sequence (e.g. T[0]!(...)

Re: Instantiate!(Template, args) in Phobos?

2016-04-22 Thread Nick Treleaven via Digitalmars-d-learn
On 22/04/2016 14:40, Steven Schveighoffer wrote: OK, I get it. I think this used to work, but I think D has long since disallowed direct access to eponymous members. So what you really want to do is: staticEx!(Exception, msg)!(file, line), but of course this doesn't follow proper grammar. I

Re: Instantiate!(Template, args) in Phobos?

2016-04-22 Thread Nick Treleaven via Digitalmars-d-learn
On 21/04/2016 18:03, Steven Schveighoffer wrote: This doesn't work? alias staticEx(string msg, string file = __FILE__, size_t line = __LINE__) = staticEx!(Exception, msg).staticEx!(file, line); No, nor using the module dot prefix `= .staticEx!(...).staticEx` either: staticex.d(3): Error:

Instantiate!(Template, args) in Phobos?

2016-04-21 Thread Nick Treleaven via Digitalmars-d-learn
Hi, There doesn't seem to be something like this in Phobos: alias Instantiate(alias Template, T...) = Template!T; Here's an example of why I need it: alias staticEx(string msg, string file = __FILE__, size_t line = __LINE__) = Instantiate!(.staticEx!(Exception, msg), file, line);

Re: @nogc inconsistent for array comparison depending on mutability of elements

2016-04-08 Thread Nick Treleaven via Digitalmars-d-learn
On Friday, 8 April 2016 at 10:11:43 UTC, Rene Zwanenburg wrote: On Friday, 8 April 2016 at 09:56:41 UTC, Nick Treleaven wrote: If the comparison with b shouldn't be allowed, I suggest we add opEquals to std.range.only. This removes a need to import std.algorithm.equal and reduces bracket

Re: @nogc inconsistent for array comparison depending on mutability of elements

2016-04-08 Thread Nick Treleaven via Digitalmars-d-learn
On Friday, 8 April 2016 at 03:14:40 UTC, Xinok wrote: On Friday, 8 April 2016 at 01:36:18 UTC, rcorre wrote: @nogc unittest { int[2] a = [1, 2]; assert(a == [1, 2]); // OK immutable(int)[2] b = [1, 2]; assert(b == [1, 2]); // fail: array literal may cause allocation } Is

Disallow destroy(structPtr)?

2015-02-20 Thread Nick Treleaven via Digitalmars-d-learn
Hi, The following code is supposed to destroy the struct instance: import std.stdio; struct S{ ~this(){destruct.writeln;} } auto p = new S; destroy(p); end.writeln; It works correctly if I use destroy(*p), but the above code could perhaps be statically

Problem building dmd d_do_test tool - missing link operand

2014-09-27 Thread Nick Treleaven via Digitalmars-d-learn
Hi, I used to run the ddoc tests with no problem, but for the last month or so I ran into problems building the d_do_test tool from latest Git dmd. (As I didn't need the latest dmd at the time, I just used an older one for a while). Maybe I'm doing something wrong with my build setup for

Re: Problem building dmd d_do_test tool - missing link operand

2014-09-27 Thread Nick Treleaven via Digitalmars-d-learn
On 27/09/2014 12:59, Nick Treleaven wrote: # in dmd/test $ make DMD=../src/dmd.exe QUIET='' Building d_do_test tool OS: win32 ../src/dmd.exe -m32 -unittest -run d_do_test.d -unittest /usr/bin/link: missing operand after `d_do_test,,nul,user32+kernel32/noi;' Try `/usr/bin/link --help' for more

Re: ddoc and CODE_HIGHLIGHT macro

2014-07-27 Thread Nick Treleaven via Digitalmars-d-learn
On 27/07/2014 09:44, Alix Pexton wrote: On 26/07/2014 4:31 PM, Nick Treleaven wrote: Hi, Ddoc doesn't seem to expand a macro near top of http://dlang.org/hash-map.html: // The $(CODE_HIGHLIGHT KeyType) is string Which is weird because it expands it for 'remove' on this line not far below it:

ddoc and CODE_HIGHLIGHT macro

2014-07-26 Thread Nick Treleaven via Digitalmars-d-learn
Hi, Ddoc doesn't seem to expand a macro near top of http://dlang.org/hash-map.html: // The $(CODE_HIGHLIGHT KeyType) is string Which is weird because it expands it for 'remove' on this line not far below it: b.remove(hello); Maybe a bug in dmd? Also, I build some dlang.org docs