Re: A couple of questions about arrays and slices

2023-06-20 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, June 20, 2023 8:09:26 PM MDT Cecil Ward via Digitalmars-d-learn wrote: > First is an easy one: > > 1.) I have a large array and a sub-slice which I want to set up > to be pointing into a sub-range of it. What do I write if I know > the start and end indices ? Concerned about an

Re: How does D’s ‘import’ work?

2023-06-18 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, June 18, 2023 2:24:10 PM MDT Cecil Ward via Digitalmars-d-learn wrote: > I wasn’t intending to use DMD, rather ldc if possible or GDC > because of their excellent optimisation, in which DMD seems > lacking, is that fair? (Have only briefly looked at dmd+x86 and > haven’t given DMD’s

Re: C++'s this() equivalent?

2023-06-15 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, June 15, 2023 7:54:22 PM MDT Jonathan M Davis via Digitalmars-d- learn wrote: > On Thursday, June 15, 2023 7:18:25 PM MDT zjh via Digitalmars-d-learn wrote: > > On Friday, 16 June 2023 at 01:00:05 UTC, Steven Schveighoffer > > > > wrote: > > > B b = B.ma

Re: C++'s this() equivalent?

2023-06-15 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, June 15, 2023 7:18:25 PM MDT zjh via Digitalmars-d-learn wrote: > On Friday, 16 June 2023 at 01:00:05 UTC, Steven Schveighoffer > > wrote: > > B b = B.make(); // call factory function > > > > -Steve > > Thank you for your tip. > If could simplify it a bit more, it would be even

Re: Calling C functions that modify a string

2023-06-15 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, June 15, 2023 7:18:06 AM MDT Steven Schveighoffer via Digitalmars-d-learn wrote: > But in general, if you want a mutable character array that's zero > terminated, you need to make a copy with a zero terminator, but type it > as mutable. I'm surprised there isn't a way to do this

Re: how to assign to shared obj.systime?

2020-07-10 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, July 10, 2020 12:30:16 PM MDT mw via Digitalmars-d-learn wrote: > On Friday, 10 July 2020 at 17:35:56 UTC, Steven Schveighoffer > > wrote: > > Mark your setTime as shared, then cast away shared (as you > > don't need atomics once it's locked), and assign: > > > > synchronized

Re: how to assign to shared obj.systime?

2020-07-10 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, July 9, 2020 9:01:20 PM MDT mw via Digitalmars-d-learn wrote: > On Friday, 10 July 2020 at 02:59:56 UTC, mw wrote: > > Error: template std.datetime.systime.SysTime.opAssign cannot > > deduce function from argument types !()(SysTime) shared, > > candidates are: > >

Re: What's the point of static arrays ?

2020-07-09 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, July 9, 2020 10:21:41 AM MDT H. S. Teoh via Digitalmars-d-learn wrote: > > - Assignment copies the whole array, as in int[5] a; auto b = a; > > Sometimes this is desirable. Consider the 3D game example. Suppose > you're given a vector and need to perform some computation on it. If

Re: called copy constructor in foreach with ref on Range

2020-06-22 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, June 22, 2020 9:25:55 PM MDT Stanislav Blinov via Digitalmars-d- learn wrote: > On Tuesday, 23 June 2020 at 02:41:55 UTC, Jonathan M Davis wrote: > > As things stand, uncopyable ranges aren't really a thing, and > > common range idiomns rely on ranges being copyable. > > Which idioms

Re: called copy constructor in foreach with ref on Range

2020-06-22 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, June 22, 2020 3:33:08 PM MDT H. S. Teoh via Digitalmars-d-learn wrote: > On Mon, Jun 22, 2020 at 09:11:07PM +, Stanislav Blinov via Digitalmars- d-learn wrote: > > That is not true. Copying of forward ranges is absolutely fine. It's > > what the current `save()` primitive is

Re: called copy constructor in foreach with ref on Range

2020-06-22 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, June 22, 2020 3:11:07 PM MDT Stanislav Blinov via Digitalmars-d- learn wrote: > On Monday, 22 June 2020 at 20:51:37 UTC, Jonathan M Davis wrote: > > You're unlikely to find much range-based code that does that > > and there really isn't much point in doing that. Again, copying > > isn't

Re: called copy constructor in foreach with ref on Range

2020-06-22 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, June 22, 2020 3:38:02 PM MDT Paul Backus via Digitalmars-d-learn wrote: > On Monday, 22 June 2020 at 21:33:08 UTC, H. S. Teoh wrote: > > Jonathan is coming from the POV of generic code. The problem > > with move leaving the original range in its .init state isn't > > so much that it

Re: Temporary File Creation

2020-06-22 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, June 22, 2020 3:46:57 PM MDT Per Nordlöw via Digitalmars-d-learn wrote: > Has anybody written a procedure for creating a temporary file in > a race-free manner? > > And why has such a procedure not already been added to std.file > when std.file.tempDir has? > > See:

Re: called copy constructor in foreach with ref on Range

2020-06-22 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, June 22, 2020 3:10:28 PM MDT kinke via Digitalmars-d-learn wrote: > On Monday, 22 June 2020 at 20:51:37 UTC, Jonathan M Davis wrote: > > [...] > > That's why I put the struct in parantheses. Moving a class ref > makes hardly any sense, but I've also never written a *class* to >

Re: called copy constructor in foreach with ref on Range

2020-06-22 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, June 22, 2020 1:41:34 PM MDT kinke via Digitalmars-d-learn wrote: > On Monday, 22 June 2020 at 19:03:44 UTC, Jonathan M Davis wrote: > > in practice, that means that generic code cannot use a range > > once it's been copied > > Translating to a simple rule-of-thumb: never copy a

Re: called copy constructor in foreach with ref on Range

2020-06-22 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, June 22, 2020 10:59:45 AM MDT kinke via Digitalmars-d-learn wrote: > If copying a range is considered to be generally unsafe and a > common pitfall (vs. the save() abomination), maybe range-foreach > shouldn't allow any lvalue ranges in the 1st place, thus not > making any copies and

Re: called copy constructor in foreach with ref on Range

2020-06-22 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, June 21, 2020 2:25:37 PM MDT kinke via Digitalmars-d-learn wrote: > A foreach over a custom range makes an initial copy, so that the > original range is still usable after the foreach (not empty). No, it's not so that the range will be useable afterwards. In fact, for generic code, you

Re: final switch problem

2020-06-13 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, June 13, 2020 10:22:39 AM MDT John Chapman via Digitalmars-d- learn wrote: > On Saturday, 13 June 2020 at 15:33:55 UTC, Boris Carvajal wrote: > > On Saturday, 13 June 2020 at 09:02:21 UTC, John Chapman wrote: > >> Is this a bug or have I made a mistake? This worked a few days > >> ago

Re: Should opIndex take precedence over pointer indexing?

2020-06-12 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, June 12, 2020 5:12:35 PM MDT claptrap via Digitalmars-d-learn wrote: > struct Foo > { > float* what; > float opIndex(size_t idx) { return what[idx]; } > } > > Foo* foo; > float x = foo[idx]; // *** > > > *** (68): Error: cannot implicitly convert expression >

Re: What is the current stage of @property ?

2020-06-10 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, June 10, 2020 3:41:54 PM MDT H. S. Teoh via Digitalmars-d-learn wrote: > On Wed, Jun 10, 2020 at 08:24:19PM +, Vinod K Chandran via Digitalmars- d-learn wrote: > > Hi all, > > I read in an old thread that authors of D wants to eliminate > > @property. I just roughly read the big

Re: Distinguish between a null array and an empty array

2020-05-24 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, May 24, 2020 6:12:31 AM MDT bauss via Digitalmars-d-learn wrote: > Is there a way to do that? > > Since the following are both true: > > int[] a = null; > int[] b = []; > > assert(a is null); > assert(!a.length); > > assert(b is null); > assert(!b.length); > > What I would like is to

Re: opEquals @safe is ignored

2020-05-24 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, May 24, 2020 2:57:28 AM MDT Luis via Digitalmars-d-learn wrote: > Lets take this example code (https://run.dlang.io/is/Vkpx9j) : > > ´´´D > import std; > > void main() > { > } > > class ExampleC > { >int x; >this (int x) @safe >{ > this.x = x; >} > >override

Re: Asserting that a base constructor is always called

2020-05-24 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, May 24, 2020 12:38:46 AM MDT Tim via Digitalmars-d-learn wrote: > Oh right. I mean it makes sense but I got confused when super() > is valid syntax. Why would you need to call the super constructor > when it's called automatically? 1. If you wanted to run any code before calling the

Re: Asserting that a base constructor is always called

2020-05-23 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, May 23, 2020 4:43:04 PM MDT Tim via Digitalmars-d-learn wrote: > It is but I want to make sure for other cases in the future where > I create a new class that inherits from GameObject. This was I > can avoid future bugs by ensure that all classes in the future > that inherit from

Re: any chance to get it working on windows xp?

2020-05-18 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, May 17, 2020 11:36:01 PM MDT Mike Parker via Digitalmars-d-learn wrote: > Unfortunately, the minimum Windows version "officially" supported > is Windows 7: > > https://forum.dlang.org/post/ktfgps$2ghh$1...@digitalmars.com > > With no testing on XP, you are bound to run into

Re: Retrieve the return type of the current function

2020-05-05 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, May 5, 2020 11:11:53 AM MDT learner via Digitalmars-d-learn wrote: > On Tuesday, 5 May 2020 at 16:41:06 UTC, Adam D. Ruppe wrote: > > typeof(return) > > Thank you, that was indeed easy! > > Is it possible to retrieve also the caller return type? Something > like: > > ``` > int foo() {

Re: How can I check if an element is iterable?

2020-05-03 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, May 3, 2020 2:54:17 PM MDT Marcone via Digitalmars-d-learn wrote: > On Sunday, 3 May 2020 at 20:46:30 UTC, Adam D. Ruppe wrote: > > On Sunday, 3 May 2020 at 20:21:24 UTC, Marcone wrote: > >> How can I check if a variable is iterable? > > > > Every variable has a type. You can get it

Re: Help, what is the code mean?

2020-04-28 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, April 27, 2020 9:52:32 AM MDT drug via Digitalmars-d-learn wrote: > 27.04.2020 18:28, data pulverizer пишет: > > I'm probably not the first person to say this but. Isn't @trusted an odd > > label to give unsafe functions and open to abuse by unscrupulous > > programmers? It almost says

Re: make dub use my version of dmd

2020-04-16 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, April 16, 2020 12:41:14 PM MDT Steven Schveighoffer via Digitalmars-d-learn wrote: > On 4/16/20 2:28 PM, Steven Schveighoffer wrote: > > OK, I thought, just put it in ~/bin, and run it from there. Doesn't > > work, now it looks in ~/bin (where there is no compiler), and fails. > > I

Re: No implicit opOpAssign for structs with basic types?

2020-04-04 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, April 4, 2020 4:22:29 AM MDT Robert M. Münch via Digitalmars-d- learn wrote: > D doesn't have implicit operators for structs? > > struct S {float a, float b}; > S a = {1, 5}; > S b = {2, 5); > > a += b; > Error: a is not a scalar, it is a S > > So I really have to write an overloaded

Re: OR in version conditional compilation

2020-03-20 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, March 20, 2020 4:33:58 PM MDT jxel via Digitalmars-d-learn wrote: > On Friday, 20 March 2020 at 21:03:55 UTC, Jonathan M Davis wrote: > > On Wednesday, March 18, 2020 10:23:26 AM MDT IGotD- via > > > > Digitalmars-d-learn wrote: > >> I have not seen any example where version has several

Re: OR in version conditional compilation

2020-03-20 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, March 18, 2020 10:23:26 AM MDT IGotD- via Digitalmars-d-learn wrote: > I have not seen any example where version has several OR matches. > > Example idiom: > > version(X86_64 || X86) > { > > } > else version(ARM || Thumb) > { > > }... > > you get the idea. So is this possible at all

Re: std.datetime & timzone specifier: 2018-11-06T16:52:03+01:00

2020-03-09 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, March 8, 2020 11:19:33 PM MDT tchaloupka via Digitalmars-d-learn wrote: > On Sunday, 8 March 2020 at 17:28:33 UTC, Robert M. Münch wrote: > > On 2020-03-07 12:10:27 +, Jonathan M Davis said: > > > > DateTime dt = > > DateTime.fromISOExtString(split("2018-11-06T16:52:03+01:00", > >

Re: std.datetime & timzone specifier: 2018-11-06T16:52:03+01:00

2020-03-07 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, March 7, 2020 2:43:47 AM MST Robert M. Münch via Digitalmars-d- learn wrote: > It looks like std.datetime is not anticipating the +1:00 part of a date > like: "2018-11-06T16:52:03+01:00" > > Those dates are used all over on the internet and I'mm wondering why > it's not supported. Any

Re: Difference between range `save` and copy constructor

2020-02-16 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, February 16, 2020 12:22:01 PM MST Paul Backus via Digitalmars-d- learn wrote: > On Sunday, 16 February 2020 at 18:11:11 UTC, Jonathan M Davis > > wrote: > > Either way, generic code should never be using a range after > > it's been copied, and copying is a key part of how idiomatic, > >

Re: Difference between range `save` and copy constructor

2020-02-16 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, February 16, 2020 10:53:36 AM MST Paul Backus via Digitalmars-d- learn wrote: > On Sunday, 16 February 2020 at 17:10:24 UTC, Jonathan M Davis > > wrote: > > On Sunday, February 16, 2020 7:29:11 AM MST uranuz via > > > >> This is working fine with disabled postblit... > >> import std; >

Re: Difference between range `save` and copy constructor

2020-02-16 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, February 16, 2020 6:52:17 AM MST uranuz via Digitalmars-d-learn wrote: > It's very bad. Because there seem that when I use range based > algorithm I need to take two things into account. The first is > how algrorithm is implemented. If it creates copies of range > inside or pass it by

Re: Difference between range `save` and copy constructor

2020-02-16 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, February 16, 2020 7:29:11 AM MST uranuz via Digitalmars-d-learn wrote: > On Sunday, 16 February 2020 at 12:38:51 UTC, Jonathan M Davis > > wrote: > > On Sunday, February 16, 2020 3:41:31 AM MST uranuz via > > > > Digitalmars-d-learn wrote: > >> I have reread presentation: > >>

Re: Difference between range `save` and copy constructor

2020-02-16 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, February 16, 2020 3:41:31 AM MST uranuz via Digitalmars-d-learn wrote: > I have reread presentation: > http://dconf.org/2015/talks/davis.pdf > We declare that `pure` input range cannot be `unpoped` and we > can't return to the previous position of it later at the time. So > logically

Re: Difference between range `save` and copy constructor

2020-02-15 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, February 15, 2020 7:34:42 AM MST Steven Schveighoffer via Digitalmars-d-learn wrote: > On 2/15/20 5:53 AM, uranuz wrote: > > I am interested in current circumstances when we have new copy > > constructor feature what is the purpose of having range `save` > > primitive? For me they

Re: Assoc array init

2020-02-04 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, February 4, 2020 12:52:05 AM MST JN via Digitalmars-d-learn wrote: > int[int] a = [5: 7]; > > void main() > { > } > > > This fails because apparently [5: 7] is a "non-const expression". > How? Why? > > Yes, I know I can just init in a static this() section, but that > feels like a bad

Re: Empty string vs null

2020-02-04 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, February 4, 2020 12:33:42 AM MST mark via Digitalmars-d-learn wrote: > I have just discovered that D seems to treat empty and null > strings as the same thing: > > // test.d > import std.stdio; > import std.string; > void main() > { > string x = null; > writeln("x = \"",

Re: Cannot implicitly convert expression [[0, -1, 2], [4, 11, 2]] of type int[][] to const(int[2])[]

2020-01-31 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, January 31, 2020 5:43:44 AM MST MoonlightSentinel via Digitalmars-d-learn wrote: > On Friday, 31 January 2020 at 12:37:43 UTC, Adnan wrote: > > What's causing this? > > You mixed up the array lengths: > > const int[3][2] matA = [[0, -1, 2], [4, 11, 2]]; > const int[2][3] matB = [[3,

Re: auto keyword

2020-01-30 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, January 30, 2020 2:37:40 AM MST Michael via Digitalmars-d-learn wrote: > auto is surely a nice feature. Nonetheless I'd prefer to use > explicit types. So when reading a code and I see the auto keyword > I also have to find out what kind of type is meant. > > I have a line of code

Re: How to convert "string" to const(wchar)* ?

2020-01-29 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, January 29, 2020 12:16:29 AM MST Ferhat Kurtulmuş via Digitalmars-d-learn wrote: > On Wednesday, 29 January 2020 at 06:53:15 UTC, Jonathan M Davis > > wrote: > > On Tuesday, January 28, 2020 10:17:03 PM MST Marcone via > > > > Digitalmars-d-learn wrote: > >> [...] > > > > Of course

Re: How to convert "string" to const(wchar)* ?

2020-01-28 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, January 28, 2020 10:17:03 PM MST Marcone via Digitalmars-d-learn wrote: > How to convert "string" to const(wchar)* ? > The code bellow is making confuse strange characters. > > cast(wchar*) str Of course it is. string is immutable(char)[], and the characters are in UTF-8.

Re: Lexicographic comparison of arrays (of chars)

2020-01-22 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, January 22, 2020 7:50:01 AM MST Per Nordlöw via Digitalmars-d- learn wrote: > On Wednesday, 22 January 2020 at 10:19:38 UTC, Jacob Carlborg > > wrote: > > That looks like it's for internal use. There is a `compare` > > method in the `TypeInfo` of each type. > > Will that incur an

Re: range algorithms on container class

2020-01-18 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, January 15, 2020 9:13:05 AM MST Paul Backus via Digitalmars-d- learn wrote: > On Thursday, 9 January 2020 at 10:26:07 UTC, Jonathan M Davis > > wrote: > > On Wednesday, January 8, 2020 10:56:20 PM MST rikki cattermole > > > > via Digitalmars-d-learn wrote: > >> Slicing via the

Re: range algorithms on container class

2020-01-09 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, January 8, 2020 10:56:20 PM MST rikki cattermole via Digitalmars-d-learn wrote: > Slicing via the opSlice operator overload is a convention, not a > requirement. It's not a requirement, but it's more than a convention. If you use the container with foreach, the compiler will call

Re: range algorithms on container class

2020-01-09 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, January 8, 2020 10:28:23 PM MST Alex Burton via Digitalmars-d- learn wrote: > I am writing a specialised container class, and want to make it > work like a normal array with range functions. > After some struggle, I look at the code for std.container.array > and see this comment : >

Re: @disable("reason")

2020-01-09 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, January 8, 2020 2:58:59 PM MST Marcel via Digitalmars-d-learn wrote: > On Wednesday, 8 January 2020 at 07:03:26 UTC, Jonathan M Davis > > wrote: > > On Tuesday, January 7, 2020 5:23:48 PM MST Marcel via > > > > Digitalmars-d-learn wrote: > >> [...] > > > > In terms of an error

Re: @disable("reason")

2020-01-08 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, January 8, 2020 4:54:06 AM MST Simen Kjærås via Digitalmars-d- learn wrote: > On Wednesday, 8 January 2020 at 07:03:26 UTC, Jonathan M Davis > > wrote: > > you could just document that no one should ever use its init > > value explicitly, and that they will have bugs if they do > >

Re: @disable("reason")

2020-01-07 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, January 7, 2020 5:23:48 PM MST Marcel via Digitalmars-d-learn wrote: > Hello! > I'm writing a library where under certain conditions i need all > the default constructors to be disabled. I would like to tell the > user why they can't instantiate the struct. > Is there a way to do

Re: @safe std.file.read

2020-01-06 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, January 6, 2020 8:52:01 AM MST Steven Schveighoffer via Digitalmars-d-learn wrote: > On 1/6/20 5:07 AM, WebFreak001 wrote: > > I was wondering, how are you supposed to use std.file : read in @safe > > code when it returns a void[] but you want to get all bytes in the file? > > > > Is

Re: Thin UTF8 string wrapper

2019-12-07 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, December 7, 2019 5:23:30 AM MST Joseph Rushton Wakeling via Digitalmars-d-learn wrote: > On Saturday, 7 December 2019 at 03:23:00 UTC, Jonathan M Davis > > wrote: > > The module to look at here is std.utf, not std.encoding. > > Hmmm, docs may need updating then -- several functions

Re: Thin UTF8 string wrapper

2019-12-06 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, December 6, 2019 9:48:21 AM MST Joseph Rushton Wakeling via Digitalmars-d-learn wrote: > Hello folks, > > I have a use-case that involves wanting to create a thin struct > wrapper of underlying string data (the idea is to have a type > that guarantees that the string has certain

Re: opCmp with and without const

2019-12-06 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, December 6, 2019 12:03:45 AM MST berni44 via Digitalmars-d-learn wrote: > In std.typecons, in Tuple there are two opCmp functions, that are > almost identical; they only differ by one being const and the > other not: > > int opCmp(R)(R rhs) > if

Re: Unexpectedly nice case of auto return type

2019-12-03 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, December 3, 2019 3:23:20 AM MST Basile B. via Digitalmars-d- learn wrote: > On Tuesday, 3 December 2019 at 10:19:02 UTC, Jonathan M Davis > > wrote: > > On Tuesday, December 3, 2019 3:03:22 AM MST Basile B. via > > > > Digitalmars-d- learn wrote: > >> [...] > > > > There isn't much

Re: Unexpectedly nice case of auto return type

2019-12-03 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, December 3, 2019 3:03:22 AM MST Basile B. via Digitalmars-d- learn wrote: > On Tuesday, 3 December 2019 at 09:58:36 UTC, Jonathan M Davis > > wrote: > > On Tuesday, December 3, 2019 12:12:18 AM MST Basile B. via > > > > Digitalmars-d- learn wrote: > >> I wish something like this was

Re: Unexpectedly nice case of auto return type

2019-12-03 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, December 3, 2019 12:12:18 AM MST Basile B. via Digitalmars-d- learn wrote: > I wish something like this was possible, until I change the > return type of `alwaysReturnNull` from `void*` to `auto`. > > > --- > class A {} > class B {} > > auto alwaysReturnNull() // void*, don't compile >

Re: Building and running DMD tests

2019-12-01 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, December 1, 2019 8:20:42 AM MST Per Nordlöw via Digitalmars-d- learn wrote: > Is it possible to compile and run unittest of dmd without > druntime and phobos? > > If so, how? > > I'm trying the following under dmd root: > > make -C src -f posix.mak unittest >

Re: How to create DDoc for string mixin generated functions?

2019-11-26 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, November 25, 2019 9:25:08 AM MST ParticlePeter via Digitalmars-d- learn wrote: > I am producing a bunch of functions/methods through string > mixins. I also generated DDoc comments for those functions, in > the hope that they would produce proper documentation, but they > don't. So how

Re: static assert(version(x)) ?

2019-11-26 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, November 26, 2019 4:29:18 AM MST S.G via Digitalmars-d-learn wrote: > On Tuesday, 26 November 2019 at 10:24:00 UTC, Robert M. Münch > > wrote: > > How can I write something like this to check if any of a set of > > specific versions is used? > > > > static assert(!(version(a) |

Re: What is the point of a synchronized lock on a single return statement?

2019-11-25 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, November 25, 2019 1:22:17 AM MST Andrej Mitrovic via Digitalmars- d-learn wrote: > From: > https://github.com/dlang/phobos/blob/10b9174ddcadac52f6a1ea532deab3310d3a8 > c03/std/concurrency.d#L1913-L1916: > > - > /// > final @property bool isClosed() @safe @nogc pure > { >

Re: why local variables cannot be ref?

2019-11-25 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, November 25, 2019 1:32:53 AM MST H. S. Teoh via Digitalmars-d- learn wrote: > On Mon, Nov 25, 2019 at 08:07:50AM +, Fanda Vacek via > Digitalmars-d-learn wrote: [...] > > > But anyway, pointers are not allowed in @safe code, so this is not > > always solution. > > [...] > > This is

Re: Parsing with dxml

2019-11-18 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, November 17, 2019 11:44:43 PM MST Joel via Digitalmars-d-learn wrote: > I can only parse one row successfully. I tried increasing the > popFronts, till it said I'd gone off the end. > > Running ./app > core.exception.AssertError@../../../../.dub/packages/dxml-0.4.1/dxml/sourc >

Re: Should I stop being interested in D language if I don't like to see template instantiation in my code?

2019-11-13 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, November 13, 2019 7:01:13 AM MST BoQsc via Digitalmars-d-learn wrote: > I don't like to see exclamation marks in my code in as weird > > syntax as these ones: > > to!ushort(args[1]) > > s.formattedRead!"%s!%s:%s"(a, b, c); > > I'm not sure why, but template instantiation syntax is

Re: Alias sleep(int) for Thread.sleep(dur!("seconds")( int ));

2019-11-12 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, November 12, 2019 2:24:54 PM MST Marcone via Digitalmars-d-learn wrote: > I am using this function to sleep, but I want a simple Alias. How > can I alias this? > > // Function sleep(int) > void sleep(int seconds){ > Thread.sleep(dur!("seconds")( seconds )); > } > > sleep(1); //

Re: Unexpected aliasing

2019-11-11 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, November 11, 2019 12:17:37 PM MST Bastiaan Veelo via Digitalmars- d-learn wrote: > Recently I got my first surprise with our use of D. The symptom > was that two local variables in two different functions appeared > to be sharing data. > > A simplified example is shown below (the

Re: A question about postblit constructor

2019-11-06 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, November 5, 2019 5:09:15 AM MST Ferhat Kurtulmuş via Digitalmars-d-learn wrote: > On Tuesday, 5 November 2019 at 12:06:44 UTC, Ferhat Kurtulmuş > > wrote: > > On Tuesday, 5 November 2019 at 11:20:47 UTC, Mike Parker wrote: > >> On Tuesday, 5 November 2019 at 10:32:03 UTC, Ferhat

Re: No UFCS with nested functions?

2019-11-05 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, November 5, 2019 9:16:27 AM MST ixid via Digitalmars-d-learn wrote: > On Monday, 4 November 2019 at 20:46:41 UTC, H. S. Teoh wrote: > > On Mon, Nov 04, 2019 at 07:51:26PM +, Tobias Pankrath via > > > > Digitalmars-d-learn wrote: > >> Why does the following not work? It works, if I

Re: Is there any writeln like functions without GC?

2019-11-02 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, October 31, 2019 9:11:42 AM MDT Ferhat Kurtulmuş via Digitalmars-d-learn wrote: > On Thursday, 31 October 2019 at 13:46:07 UTC, Adam D. Ruppe wrote: > > On Thursday, 31 October 2019 at 03:56:56 UTC, lili wrote: > >> Hi: > >>why writeln need GC? > > > > It almost never does, it

Re: Documentation: is it intentional that template constraints are displayed after the signature?

2019-11-01 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, November 1, 2019 11:23:42 AM MDT Ali Çehreli via Digitalmars-d- learn wrote: > On 11/01/2019 09:33 AM, Paul Backus wrote: > > On Friday, 1 November 2019 at 15:29:24 UTC, Ali Çehreli wrote: > >> Apparently, it's the version for static arrays. However, I don't think > >> the template

Re: Using a char value >= 128

2019-10-27 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, October 27, 2019 6:44:05 AM MDT Per Nordlöw via Digitalmars-d- learn wrote: > In which circumstances can a `char` be initialized a non-7-bit > value (>= 128)? Is it possible only in non-@safe code? > > And, if so, what will be the result of casting such a value to > `dchar`? Will that

Re: About the in expression, Why can't use with array.

2019-10-24 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, October 24, 2019 8:40:59 PM MDT lili via Digitalmars-d-learn wrote: > On Thursday, 24 October 2019 at 22:40:31 UTC, Jonathan M Davis > > wrote: > > On Thursday, October 24, 2019 7:04:56 AM MDT Paul Backus via > > > > Digitalmars-d- learn wrote: > >> On Thursday, 24 October 2019 at

Re: About the in expression, Why can't use with array.

2019-10-24 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, October 24, 2019 7:04:56 AM MDT Paul Backus via Digitalmars-d- learn wrote: > On Thursday, 24 October 2019 at 12:58:11 UTC, lili wrote: > > Hi: > >In Dlang where is strange design. The in expression can only > > > > use to associative array, why array can not use in expression. >

Re: Why isn't skipOver(string, string) nothrow?

2019-10-22 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, October 22, 2019 4:27:59 PM MDT Per Nordlöw via Digitalmars-d- learn wrote: > On Tuesday, 22 October 2019 at 15:39:17 UTC, Adam D. Ruppe wrote: > > On Tuesday, 22 October 2019 at 15:33:05 UTC, Per Nordlöw wrote: > >> Why isn't a call to > >> > >> skipOver(string, string) > >> > >>

Re: Why isn't skipOver(string, string) nothrow?

2019-10-22 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, October 22, 2019 9:33:05 AM MDT Per Nordlöw via Digitalmars-d- learn wrote: > Why isn't a call to > > skipOver(string, string) > > nothrow? > > I see no reason why it shouldn't be. > > Further, this test should be qualifyable as nothrow: > > @safe pure /* TODO nothrow @nogc */

Re: Some questions about GC

2019-10-18 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, October 18, 2019 10:54:55 AM MDT Roland Hadinger via Digitalmars- d-learn wrote: > These questions probably need some context: I'm working on an > interpreter that will manage memory via reference counted struct > types. To deal with the problem of strong reference cycles > retaining

Re: How Different Are Templates from Generics

2019-10-12 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, October 12, 2019 9:48:02 PM MDT jmh530 via Digitalmars-d-learn wrote: > On Saturday, 12 October 2019 at 21:44:57 UTC, Jonathan M Davis > > wrote: > > [snip] > > Thanks for the reply. > > As with most people, I don't write a lot of D code that uses > classes that much. > > The use

Re: How Different Are Templates from Generics

2019-10-12 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, October 12, 2019 2:11:28 PM MDT jmh530 via Digitalmars-d-learn wrote: > On Friday, 11 October 2019 at 17:50:42 UTC, Jonathan M Davis > > wrote: > > [snip] > > A very thorough explanation! > > One follow-up question: would it be possible to mimic the > behavior of Java generics in D?

Re: selective tests

2019-10-12 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, October 12, 2019 2:18:02 AM MDT Martin Brezeln via Digitalmars- d-learn wrote: > Is it possible to execute only certain modules or tests which are > defined in certain directories? > > For example, in go one can run "go test ./XYZ" to execute ony > tests in ./XYZ or "go test ./..." to

Re: _getmaxstdio / _setmaxstdio

2019-10-11 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, October 10, 2019 5:03:29 PM MDT Damian via Digitalmars-d-learn wrote: > Missing _getmaxstdio / _setmaxstdio? > I'd like to try and increase the limit of open files without > resorting to Windows API, is it possible or will I have to resort > to the WinAPI to achieve this? Phobos

Re: How Different Are Templates from Generics

2019-10-11 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, October 11, 2019 12:09:20 PM MDT Just Dave via Digitalmars-d- learn wrote: > Thanks for the thorough explanation. Most of that is how I was > thinking it worked. However, that leaves me perplexed. If > templates just generate code then how come: > > Wouldnt.. > > class SomeClass(T)

Re: How Different Are Templates from Generics

2019-10-11 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, October 11, 2019 8:43:49 AM MDT Just Dave via Digitalmars-d-learn wrote: > I come from both a C++ and C# background. Those have been the > primary languages I have used. In C# you can do something like > this: > > public interface ISomeInterface > { > T Value { get;

Re: C#'s 'is' equivalent in D

2019-10-10 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, October 10, 2019 9:47:58 AM MDT Just Dave via Digitalmars-d- learn wrote: > In C# you can do something like: > > > if (obj is Person) > { > var person = obj as Person; > // do stuff with person... > } > > where you can check the type of an object prior

Re: Dynamic Arrays as Stack and/or Queue

2019-10-08 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, October 8, 2019 2:42:22 PM MDT mipri via Digitalmars-d-learn wrote: > On Tuesday, 8 October 2019 at 10:48:45 UTC, Jonathan M Davis > > wrote: > > The result of this is that code like > > > > stack.popBack(); > > stack ~= foo; > > stack ~= bar; > > stack.popBack(); > > stack ~= baz; >

Re: Ranges to deal with corner cases and "random access"

2019-10-08 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, October 8, 2019 9:40:33 AM MDT Paul Backus via Digitalmars-d- learn wrote: > On Sunday, 6 October 2019 at 20:34:55 UTC, Brett wrote: > > If it can be done and make to work well with ranges it would > > allow many algorithms to be very easily expressed and make > > ranges more powerful.

Re: Dynamic Arrays as Stack and/or Queue

2019-10-08 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, October 7, 2019 1:16:31 PM MDT IGotD- via Digitalmars-d-learn wrote: > On Monday, 7 October 2019 at 17:36:09 UTC, Ferhat Kurtulmuş wrote: > >> I'm not talking about memory deletion. I'm talking about push, > >> pop, enqueue, and dequeue behavior. I'd assume in a garbage > >> collected

Re: How does D distnguish managed pointers from raw pointers?

2019-10-04 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, October 4, 2019 1:22:26 PM MDT Dennis via Digitalmars-d-learn wrote: > On Friday, 4 October 2019 at 19:08:04 UTC, Adam D. Ruppe wrote: > > (personally though I like to explicitly slice it all the time > > though, it is more clear and the habit is nice) > > Turns out I have this habit

Re: Using enforce or assert to check for fullness when appending to fixed length array container

2019-10-04 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, October 4, 2019 4:00:08 AM MDT Per Nordlöw via Digitalmars-d- learn wrote: > I have a wrapper container FixedArray at > > https://github.com/nordlow/phobos-next/blob/25f4a4ee7347427cebd5cd375c9990 > b44108d2ef/src/fixed_array.d > > on top of a static array store that provides the member

Re: Struct initialization has no effect or error?

2019-10-03 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, October 2, 2019 11:48:46 PM MDT Mike Parker via Digitalmars-d- learn wrote: > On Thursday, 3 October 2019 at 04:57:44 UTC, mipri wrote: > > On Thursday, 3 October 2019 at 04:33:26 UTC, Brett wrote: > >> I was trying to avoid such things since X is quite long in > >> name. Not a huge

Re: C++ base constructor call vs. D's

2019-10-02 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, October 2, 2019 11:22:40 AM MDT Just Dave via Digitalmars-d- learn wrote: > I was reading the C++ to D page, and came across this little bit > about when to call the base class constructor: > > "It's superior to C++ in that the base constructor call can be > flexibly placed anywhere

Re: Why dynamic array is InputRange but static array not.

2019-09-24 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, September 24, 2019 1:35:24 AM MDT lili via Digitalmars-d-learn wrote: > Hi: >in phobos/std/range/primitives.d has this code > ``` > static assert( isInputRange!(int[])); > static assert( isInputRange!(char[])); > static assert(!isInputRange!(char[4])); > static

Re: wstring comparison is failing

2019-09-23 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, September 23, 2019 5:22:14 PM MDT Brett via Digitalmars-d-learn wrote: > On Monday, 23 September 2019 at 20:45:00 UTC, destructionator > > wrote: > > On Mon, Sep 23, 2019 at 08:38:03PM +, Brett via > > > > Digitalmars-d-learn wrote: > >> The only thing is that szExeFile is a static

Re: what is the mean that call function start with a dot.

2019-09-22 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, September 21, 2019 10:32:08 PM MDT Paul Backus via Digitalmars- d-learn wrote: > On Sunday, 22 September 2019 at 04:15:53 UTC, lili wrote: > > Hi: > > > >yesterday I saw some d code, where is an .fn() call syntax, > > > > what is it mean. > > It means that `fn` is looked up in the

Re: Looking for a Simple Doubly Linked List Implementation

2019-09-21 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, September 21, 2019 12:52:23 PM MDT Dennis via Digitalmars-d- learn wrote: > Since I marked the method as const, `auto a = head` got the type > const(Node!T) and `a = a.next` no longer compiled. With structs > you can declare a const(Node!T)* (mutable pointer to const node), > but I

Re: Why must a bidirectional range also be a forward range?

2019-09-21 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, September 20, 2019 7:08:03 AM MDT Joseph Rushton Wakeling via Digitalmars-d-learn wrote: > On Thursday, 19 September 2019 at 22:55:55 UTC, Jonathan M Davis > > wrote: > > For better or worse, ranges were more or less set up as a > > linear hierarchy, and it's unlikely that use cases

Re: Avoid gratuitous closure allocations

2019-09-20 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, September 20, 2019 5:21:22 AM MDT Ali Çehreli via Digitalmars-d- learn wrote: > tl;dr Instead of returning an object that uses local state, return an > object that uses member variables. The other issue this helps with is problems related to having multiple contexts. IIRC, without it,

Re: Why must a bidirectional range also be a forward range?

2019-09-19 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, September 19, 2019 3:31:32 AM MDT Joseph Rushton Wakeling via Digitalmars-d-learn wrote: > Hello folks, > > A question that occurred to me while implementing a new data > structure recently, which I'm not sure I've ever seen a reason > for. > > Why must bidirectional ranges also be

<    1   2   3   4   5   6   7   8   9   10   >