Re: Simulating computed goto

2020-11-25 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Nov 25, 2020 at 06:44:52PM +, NonNull via Digitalmars-d-learn wrote: > For automatically generated code of some low level kinds it is > convenient to have "computed goto" like this: > > https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html > > and D does not have this. > > A

Re: lambdas with types

2020-11-20 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Nov 20, 2020 at 02:52:41PM +, Adam D. Ruppe via Digitalmars-d-learn wrote: > On Friday, 20 November 2020 at 14:47:52 UTC, Paul Backus wrote: > > There is no way to create an anonymous template in D. > > I wish there was, maybe some day we can think of a way to add it to > the

Re: lambdas with types

2020-11-20 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Nov 20, 2020 at 02:47:52PM +, Paul Backus via Digitalmars-d-learn wrote: [...] > In this specific case, you could also make `foo` a type-safe variadic > function [1], which would eliminate the need for `allSatisfy`: > > void foo(double[] args...) > { > // ... > }

Re: why is "hello".writeln considered bad?

2020-11-20 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Nov 20, 2020 at 11:03:18AM +0100, Daniel Kozak via Digitalmars-d-learn wrote: [...] >I remember days when I liked UFCS too . Unfortunately  it is not so >awesome when you use it with IDE. So I am now avoiding UFCS as much >as possible and it is a much better experience for me.

Re: magically a static member on init?

2020-11-16 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Nov 15, 2020 at 10:06:55AM +, Martin via Digitalmars-d-learn wrote: > On Sunday, 15 November 2020 at 00:29:41 UTC, H. S. Teoh wrote: > > if you don't like the semantics, don't use it; always allocate the > > field in the class ctor instead. > > Hi, i neither like it nor dislike it -

Re: magically a static member on init?

2020-11-14 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Nov 14, 2020 at 11:20:55PM +, Martin via Digitalmars-d-learn wrote: > Hi, i do no know if this is intended - but imo this is weird: > https://run.dlang.io/is/eBje3A > > I expected that `c.a.str == ""` (just like `c.str` is). But instead > `c.a.str` keeps the value of `b.a.str`. > >

Re: .d files without a module statement? Required to be absent?

2020-11-14 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Nov 14, 2020 at 05:55:13PM +, WhatMeWorry via Digitalmars-d-learn wrote: > > I was poking around the dmd code just to "learn from the best" IMNSHO, Phobos is more representative of typical D code than dmd; dmd code was automatically translated from C++, so a lot of it may still have

Re: Unclear error message

2020-11-10 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Nov 11, 2020 at 01:05:21AM +, SealabJaster via Digitalmars-d-learn wrote: > Please see the code at https://run.dlang.io/is/Yjidek [Quoting code in full here for future reference] > struct PreValidate > { > alias FuncT = bool delegate(string arg); > > FuncT func; > >

Re: C++ or D?

2020-11-09 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Nov 10, 2020 at 01:00:50AM +, Mark via Digitalmars-d-learn wrote: [...] > my question would be about using D or not using D. Is the newest C++ > iteration any good compared to D? [...] > I haven't looked into the newest C++. In theory, they might have added > something helpful in the

Re: Unicode Regular Expressions

2020-11-09 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Nov 09, 2020 at 03:39:05PM +, Per Nordlöw via Digitalmars-d-learn wrote: > Is there any library that can deal with decoding and generating > character matchers for Unicode regular expression described at > > https://www.regular-expressions.info/unicode.html I'm pretty sure std.regex

Re: Switch between two structs with csvreader

2020-11-06 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Nov 06, 2020 at 07:17:53PM +, Selim Ozel via Digitalmars-d-learn wrote: > On Thursday, 5 November 2020 at 22:36:36 UTC, Anonymouse wrote: > > If I'm not mistaken the `csvReader` function returns a range struct, > > and the full type is something long and unwieldy like > >

Re: Implicit conversion to templatized type

2020-11-06 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Nov 06, 2020 at 03:36:46PM +, Paul Backus via Digitalmars-d-learn wrote: [...] > User-defined implicit conversions are one of the most error-prone > features of C++, and have been deliberately excluded from D, with the > exception of `alias this`. And Walter is already expressing

Re: How add class or struct member after construction?

2020-11-05 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Nov 05, 2020 at 10:48:38PM +, Marcone via Digitalmars-d-learn wrote: > How add class or struct member after construction? Is it possible in > D? How? You can't, because D is statically-typed. However, you *can* implement something equivalent manually by other means, depending on your

Re: Does dmd's -i "include imported modules in the compilation" switch generate object files?

2020-11-03 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Nov 03, 2020 at 10:42:55AM -0800, Ali Çehreli via Digitalmars-d-learn wrote: > -i is a useful feature: > > https://dlang.org/dmd-linux.html > > Does dmd compile auto-included files separately? Does it generate > temporary object files? If so, where does it write the files? Would -i >

Re: What is the difference between enum and shared immutable?

2020-10-29 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Oct 29, 2020 at 04:56:46PM +, IGotD- via Digitalmars-d-learn wrote: > On Thursday, 29 October 2020 at 16:45:51 UTC, Ali Çehreli wrote: > > > > import std; > > > > immutable string p; > > > > shared static this() { > > p = environment["PATH"]; // <-- Run time > > } > > > > Just

Re: What is the difference between enum and shared immutable?

2020-10-29 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Oct 29, 2020 at 11:00:42AM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: > On 10/29/20 10:39 AM, H. S. Teoh wrote: > > On Thu, Oct 29, 2020 at 09:50:28AM -0400, Steven Schveighoffer via > > Digitalmars-d-learn wrote: > > [...] > > > D frequently allows no-op attributes. > >

Re: What is the difference between enum and shared immutable?

2020-10-29 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Oct 29, 2020 at 09:50:28AM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: [...] > D frequently allows no-op attributes. [...] I find that to be a bad smell in terms of language design, actually. Either something should be allowed and have a definite effect, or it should not

Re: What is the difference between enum and shared immutable?

2020-10-29 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Oct 29, 2020 at 08:13:42AM +, Jan Hönig via Digitalmars-d-learn wrote: [...] > Is there some rule of thumb when to use what? > > I judge that using enum will slow down the compilation process, but > might increase performance. Nah. The slowdown is practically indiscernible. You

Re: Empty functions

2020-10-29 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Oct 29, 2020 at 09:06:21AM +, Jan Hönig via Digitalmars-d-learn wrote: > On Thursday, 29 October 2020 at 09:01:12 UTC, Jan Hönig wrote: > > This would mean, that this one should work as well. > > It does not work as I intended, as `() => {}` has not the return type > of `void`. > >

Re: nested module problem

2020-10-28 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Oct 28, 2020 at 10:52:33PM +, Adam D. Ruppe via Digitalmars-d-learn wrote: > On Wednesday, 28 October 2020 at 22:43:12 UTC, mw wrote: > > I wonder what's the best way to resolve this conflict, i.e my local > > file name with 3rd party library dir name. > > Don't write any module with

Re: What is the difference between enum and shared immutable?

2020-10-28 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Oct 28, 2020 at 09:54:19PM +, Jan Hönig via Digitalmars-d-learn wrote: > Maybe this is a silly question, but I don't understand completely the > difference between an `enum` and a `shared immutable`. > > I could have: > > enum x = 1; > > or > > shared immutable x = 1; > > What is

Re: Associative array using std.container.array

2020-10-28 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Oct 28, 2020 at 06:54:01PM +, Vino via Digitalmars-d-learn wrote: > Hi All, > >Is it possible to create an associative array using > std.container.array, if possible can you please provide me an example > nor send me some link which has this information.

Re: Print int[string] sorted by Value

2020-10-28 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Oct 28, 2020 at 03:15:40PM +, Paul via Digitalmars-d-learn wrote: > per the D sample wc2.d > size_t[string] dictionary; <-is printed by... > . > foreach (word1; dictionary.keys.sort) writef etc > > I want to print the dictionary sorted by value not key. I can write > an

Re: String Template Package

2020-10-26 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Oct 26, 2020 at 11:36:12PM +, Per Nordlöw via Digitalmars-d-learn wrote: > I need a string template system for generation of parsers in D code to > compiled in separate phase (not Pegged). > > What packages is there for this? Adela Vais is working on D support for GNU bison, a

Re: Recommended way to use __FILE__/__LINE__ etc.

2020-10-22 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Oct 22, 2020 at 03:32:57PM +, Andrey Zherikov via Digitalmars-d-learn wrote: > There are two ways how __FILE__, __LINE__ etc. can se used in function > parameters: as regular parameters and as template parameters: [...] > What is recommended way? > What are pros/cons of each case? I

Re: Forward referencing functions in D

2020-10-16 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Oct 16, 2020 at 08:04:07PM +, Imperatorn via Digitalmars-d-learn wrote: [...] > I think it might be just because you havent defined the function yet > at that point. That's not correct; the following works: module mymodule; void func() {

Re: Forward referencing functions in D

2020-10-16 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Oct 16, 2020 at 07:55:53PM +, wilcro via Digitalmars-d-learn wrote: > The web page "Programming in D for C Programmers" > (https://dlang.org/articles/ctod.html#forwardfunc) states that forward > declarations are neither required nor permitted, [...] > However, the following code will

Re: why do i need an extern(C): here?

2020-10-15 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Oct 15, 2020 at 09:47:16PM +, IGotD- via Digitalmars-d-learn wrote: > On Thursday, 15 October 2020 at 21:29:59 UTC, WhatMeWorry wrote: > > > > I've go a small DLL and a test module both written in D. Why do I > > need to use the extern(C)? Shouldn't both sides be using D name > >

Re: Error on dub build - Trying Vibe-d for the first time

2020-10-14 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Oct 14, 2020 at 05:30:37PM +, Andre Pany via Digitalmars-d-learn wrote: > On Wednesday, 14 October 2020 at 16:39:39 UTC, Imperatorn wrote: > > On Wednesday, 14 October 2020 at 15:27:46 UTC, Andre Pany wrote: [...] > > > Please add this to your dub.json file: > > > "versions": [

Re: Range format specifiers in other languages?

2020-10-12 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Oct 12, 2020 at 05:51:21AM +, Imperatorn via Digitalmars-d-learn wrote: > On Monday, 12 October 2020 at 00:59:33 UTC, Adam D. Ruppe wrote: > > On Monday, 12 October 2020 at 00:46:37 UTC, Imperatorn wrote: > > > To people trying to learn, why is that % before ( needed in the > > >

Re: Why does sum not work in static arrays?

2020-10-11 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Oct 11, 2020 at 01:26:13PM +, Alaindevos via Digitalmars-d-learn wrote: > Sidenote, sort also not works with static arrays. Just slice it with []. T -- I think the conspiracy theorists are out to get us...

Re: question on dub and postgresql

2020-10-07 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Oct 07, 2020 at 07:15:42PM +, aberba via Digitalmars-d-learn wrote: [...] > It seems the D ecosystem is not immediately obvious to some people. > Dub, compilers, and IDEs are recurring issues. This is stuff that needs to be documented up-front and in-your-face. For example, if we're

Re: Efficient sort function allowing own test and swap function as parameter

2020-10-06 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Oct 06, 2020 at 10:18:39PM +, Alaindevos via Digitalmars-d-learn wrote: > I have a large table consisting of two columns.One with words.Another > with frequencies. I want to sort them efficiently according to the > names or frequency. > For this I need an efficient sort function where

Re: Accessing non-binary Unicode properties with std.uni

2020-09-29 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Sep 29, 2020 at 06:14:45PM +, Chloé Kekoa via Digitalmars-d-learn wrote: > On Tuesday, 29 September 2020 at 17:04:51 UTC, H. S. Teoh wrote: > > OTOH, the relevant Unicode data file that contains East_Asian_Width > > data (EastAsianWidth.txt) is relatively straightforward to parse. > >

Re: Safe to remove AA elements while iterating over it via .byKeyValue?

2020-09-29 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Sep 29, 2020 at 09:56:41AM +, ikod via Digitalmars-d-learn wrote: > Hello, > > Sorry if I unintentionally hurt anybody in this thread. > I'll try to implement sane and correct iteration behavior for AA > without noticeable performance loss, and propose it if I succeed. No feelings

Re: Accessing non-binary Unicode properties with std.uni

2020-09-29 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Sep 29, 2020 at 04:22:18PM +, Dukc via Digitalmars-d-learn wrote: > On Monday, 28 September 2020 at 18:23:43 UTC, Chloé Kekoa wrote: > > The documentation of std.uni [1] says that the unicode struct > > provides sets for several binary properties. I am looking for a way > > to query

Re: Safe to remove AA elements while iterating over it via .byKeyValue?

2020-09-28 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Sep 28, 2020 at 08:04:49PM +, ikod via Digitalmars-d-learn wrote: > On Monday, 28 September 2020 at 19:18:20 UTC, H. S. Teoh wrote: [...] > > The problem with arbitrary, unrestricted modification of a container > > while iterating over it, is that it inevitably leads to > >

Re: Safe to remove AA elements while iterating over it via .byKeyValue?

2020-09-28 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Sep 28, 2020 at 05:18:41PM +, ikod via Digitalmars-d-learn wrote: > On Monday, 28 September 2020 at 14:58:15 UTC, Steven Schveighoffer wrote: [...] > > One could write a specific function to iterate and remove. I > > This looks like dead end to me, as you may not only remove items

Re: Array Slicing

2020-09-27 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Sep 27, 2020 at 01:59:07PM +, DMon via Digitalmars-d-learn wrote: > Are these in the Specification or Phobos? See: https://dlang.org/articles/d-array-article.html T -- Государство делает вид, что платит нам зарплату, а мы делаем вид, что работаем.

Re: Safe to remove AA elements while iterating over it via .byKeyValue?

2020-09-27 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Sep 27, 2020 at 01:02:04PM +, Per Nordlöw via Digitalmars-d-learn wrote: > Is it safe to remove AA-elements from an `aa` I'm iterating over via > aa.byKeyValue? No. Modifying a container while iterating over it is, in general, a bad idea (unless the container is designed to be used

Re: Is it possible to "overload" based on visibility?

2020-09-25 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Sep 25, 2020 at 05:58:08PM +, 60rntogo via Digitalmars-d-learn wrote: > On Friday, 25 September 2020 at 15:21:22 UTC, Steven Schveighoffer wrote: > > If the input is not ref, you should not return by ref, because then > > you would be returning a reference to local stack data that is

Re: what's the best way to convert a sysTime to local machine's time (zone)?

2020-09-24 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Sep 24, 2020 at 08:36:38PM -0400, James Blachly via Digitalmars-d-learn wrote: > On 9/24/20 6:22 PM, mw wrote: [...] > > I'm just wondering what's the best way to convert sysTime to local > > machine's time (zone)? [...] > It is definitely not easy to find. > >

Re: How can I test at compile time whether T is an instance of an interface ?

2020-09-23 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Sep 23, 2020 at 07:08:47PM +, data pulverizer via Digitalmars-d-learn wrote: > On Wednesday, 23 September 2020 at 18:56:33 UTC, wjoe wrote: > > > > It doesn't occur to me that the compiler doesn't know at compile > > time that > > > > interface IFoo{} > > class Foo: IFoo {} > > > >

Re: How can I test at compile time whether T is an instance of an interface ?

2020-09-23 Thread H. S. Teoh via Digitalmars-d-learn
Try this: interface I {} class C : I {} class D {} struct S {} pragma(msg, is(C : I)); // true pragma(msg, is(D : I)); // false pragma(msg, is(S : I)); // false So probably what you want is something like this: void register(C,

Re: Why private methods cant be virtual?

2020-09-21 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Sep 21, 2020 at 07:43:30PM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: [...] > No, it's not a bug. It's intentional. > > private and package functions are final, and we aren't going to change > that now, even if it makes sense to make them virtual. [...] Whoa. But why??

Re: Why private methods cant be virtual?

2020-09-21 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Sep 21, 2020 at 11:17:13PM +, claptrap via Digitalmars-d-learn wrote: > Seems like a completely pointless restriction to me. [...] It looks like a bug to me. Please file one if there isn't already one: https://issues.dlang.org/ T -- Computerese Irregular Verb

Re: Good repos to learn D

2020-09-19 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Sep 19, 2020 at 08:26:36AM +, Imperatorn via Digitalmars-d-learn wrote: > What are some good examples of pretty large/medium size, good > structured repos in D? I'm looking for examples to learn from [...] Phobos itself. I have to say, it's the most readable programming language

Re: How to convert member function to free function?

2020-09-18 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Sep 18, 2020 at 06:20:41PM +, Andrey Zherikov via Digitalmars-d-learn wrote: > How can I rewrite foo() function as a free-function that won't cause > struct copying? My simplified code is: > > struct S > { > ref S foo() return > { > return this; > } > } >

Re: Proper way to exit with specific exit code?

2020-09-18 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Sep 18, 2020 at 08:20:59AM +, IGotD- via Digitalmars-d-learn wrote: > On Friday, 18 September 2020 at 05:02:21 UTC, H. S. Teoh wrote: > > > > That's the obvious solution, except that actually implementing it is not > > so simple. When you have multiple threads listening for each

Re: Proper way to exit with specific exit code?

2020-09-17 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Sep 17, 2020 at 09:53:07PM -0400, James Blachly via Digitalmars-d-learn wrote: [...] > I never considered this -- so when I call core.stdc.stdlib : exit, > none of my destructors get called? Yes. > Presumably also not scope(exit) blocks? Yes. > If this is the case, could we simply

Re: enum and const or immutable ‘variable’ whose value is known at compile time

2020-09-17 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Sep 17, 2020 at 06:06:56PM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: > On 9/17/20 9:13 AM, Simen Kjærås wrote: > > > To be clear: I don't mind 'enum' being used this way, but if I were > > to do things over again, I would have used 'alias'. > > fun fact: for a (very)

Re: Building LDC runtime for a microcontroller

2020-09-17 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Sep 17, 2020 at 08:40:06PM +, wjoe via Digitalmars-d-learn wrote: > On Thursday, 17 September 2020 at 19:27:41 UTC, Adam D. Ruppe wrote: > > fyi my baby was just born i'll come back to this but it might be a > > day or two [...] "A day or two"??! More likely a month for starters. :-D

Re: Proper way to exit with specific exit code?

2020-09-17 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Sep 17, 2020 at 02:58:48PM +, drathier via Digitalmars-d-learn wrote: > What's the proper way to exit with a specific exit code? > > I found a bunch of old threads discussing this, making sure > destructors run and the runtime terminates properly, all of which > seemingly concluding

Re: Why is BOM required to use unicode in tokens?

2020-09-14 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Sep 14, 2020 at 09:49:13PM -0400, James Blachly via Digitalmars-d-learn wrote: > I wish to write a function including ∂x and ∂y (these are trivial to > type with appropriate keyboard shortcuts - alt+d on Mac), but without > a unicode byte order mark at the beginning of the file, the lexer

Re: how to do this meta-programming? print the address of random element's address of a variable length of arrays?

2020-09-12 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Sep 12, 2020 at 07:31:57PM +, mw via Digitalmars-d-learn wrote: [...] > I've tried something like this: the AliasSeq specify the logical > divide > >printRandomElemAddr(AliasSeq!(extraA, extraB, extraC, extraD), a, b, c); > > but cannot make it work. Yes, because AliasSeq

Re: tupleof seems to break encapsulation

2020-09-04 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Sep 04, 2020 at 07:36:00PM +0200, Jacob Carlborg via Digitalmars-d-learn wrote: [...] > It's useful for serialization and, as you can see in your example, for > debugging as well. `writeln` will print the values of the fields in a > struct, even for private fields. It's certainly useful,

Re: BetterC + WASM Update

2020-09-03 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Sep 03, 2020 at 06:18:00PM +, Mike Brown via Digitalmars-d-learn wrote: [...] > I did however, get taken in by how small and precise the D code was > compared to my C++ equivalent. The templating is beautiful, I’m now > considering writing in D rather than C++ as the smaller and

Re: How to create compile-time container?

2020-08-31 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Aug 31, 2020 at 08:39:10PM +, Andrey Zherikov via Digitalmars-d-learn wrote: > On a low level, I want something like this code to work: > string[] arr; // this can be any suitable type > > arr ~= "a";// data is compile-time constant > > enum f = arr[0]; //

Re: How to get the element type of an array?

2020-08-25 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Aug 25, 2020 at 03:02:14PM +, FreeSlave via Digitalmars-d-learn wrote: > On Tuesday, 25 August 2020 at 03:41:06 UTC, Jon Degenhardt wrote: > > What's the best way to get the element type of an array at compile > > time? > > > > Something like std.range.ElementType except that works

Re: How to get the element type of an array?

2020-08-24 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Aug 25, 2020 at 03:41:06AM +, Jon Degenhardt via Digitalmars-d-learn wrote: > What's the best way to get the element type of an array at compile > time? > > Something like std.range.ElementType except that works on any array > type. There is std.traits.ForeachType, but it wasn't

Re: Which version of DMD does GDC 10 target

2020-08-19 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Aug 20, 2020 at 04:28:41AM +, Arun via Digitalmars-d-learn wrote: > Which version of DMD is GDC 10 based on? Compile the following D program to find out: - static assert(0, "Compiler language version: " ~ __VERSION__.stringof); - I have this line in a file called langver.d,

Re: Location of core.internal.traits : CoreUnqual in Dlang GitHub repo

2020-08-19 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Aug 19, 2020 at 10:47:19PM +, data pulverizer via Digitalmars-d-learn wrote: > Hi all, > > I've been looking for where `CoreUnqual` is defined in the Dlang > repos. I've tried searching in dmd and phobos but only found the > reference usage in std.traits: > > import

Re: Creating a pointer array

2020-08-19 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Aug 19, 2020 at 08:09:31PM +, bachmeier via Digitalmars-d-learn wrote: [...] > Maybe I'm the only one, but I think double*[] is hideous, and I'd sure > hate for someone not used to D to see it. IMO, double*[] is absolutely logical. It's a natural consequence of type syntax. > Alias

Re: Subtyping with alias this

2020-08-17 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Aug 18, 2020 at 05:34:58AM +, novice3 via Digitalmars-d-learn wrote: [...] > The problem is: > if i use fmt.spec in overloaded toString(), > when i get error "phobos/std/format.d(2243): Error: no property ip for > type onlineapp.IpV4Address" Here's a working example:

Re: Subtyping with alias this

2020-08-17 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Aug 17, 2020 at 02:29:47PM +, novice3 via Digitalmars-d-learn wrote: [...] > ``` > struct IpV4Address > { > private uint ip; > alias ip this; > > string toString() > { > import std.conv: to; > return to!string((ip >>> 24) & 0xFF) ~ "." ~ >to!string((ip >>>

Re: Types of lambda args

2020-08-16 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Aug 17, 2020 at 12:20:24AM +, Cecil Ward via Digitalmars-d-learn wrote: > In a lambda, how do we know what types the arguments are? In something > like > (x) => x * x It's implemented as a template, whose argument types are inferred based on usage context. > - there I just

Re: DMD: how to restore old unittest+main

2020-08-13 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Aug 13, 2020 at 08:30:44AM +, Jonathan via Digitalmars-d-learn wrote: [...] > Is there a reason you need to run all unittests every time you want to > run the program? During development, this is a valuable time-saver: instead of compiling twice, once with -unittest and once without,

Re: How does D's templated functions implementation differ from generics in C#/Java?

2020-08-08 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Aug 08, 2020 at 01:47:27AM +, jmh530 via Digitalmars-d-learn wrote: > On Friday, 7 August 2020 at 21:39:44 UTC, H. S. Teoh wrote: > > [snip] > > "Furthermore, it can dispatch to a type-erased implementation ala Java > -- at your choice;" > > This is interesting. Would you just cast

Re: How does D's templated functions implementation differ from generics in C#/Java?

2020-08-07 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Aug 07, 2020 at 09:03:47PM +, aberba via Digitalmars-d-learn wrote: > Syntactically they look the same (although D's can do more things) so > I'm trying to understand how why in D it's called template but in > languages like C#/Java they're generics. > > I guess I have fair

Re: I just discovered an alternative use of the `in`-operator

2020-08-07 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Aug 07, 2020 at 09:02:03PM +, Per Nordlöw via Digitalmars-d-learn wrote: > On Thursday, 6 August 2020 at 22:24:43 UTC, Paul Backus wrote: > > [1] https://dlang.org/spec/expression.html#is_expression > > I bet there a several places in Phobos where this feature isn't but > could be

Re: Non-recursive maxSizeOf

2020-08-06 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Aug 06, 2020 at 01:07:14PM +, Per Nordlöw via Digitalmars-d-learn wrote: [...] > However, your solution > > template maxSize(T...) > { > align(1) union Impl { T t; } > enum maxSize = Impl.sizeof; > } > > fails as > > variable `std.variant.maxSize!(void,

Re: Non-recursive maxSizeOf

2020-08-06 Thread H. S. Teoh via Digitalmars-d-learn
On Thursday, 6 August 2020 at 00:58:39 UTC, Per Nordlöw wrote: Is it possible to implement template maxSizeOf(T...) { static if (T.length == 1) enum size_t maxSizeOf = T[0].sizeof; else { enum size_t firstSize = T[0].sizeof; enum size_t maxSizeRest =

Re: Invoking the compiler during runtime

2020-08-05 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Aug 05, 2020 at 06:02:58AM +, cy via Digitalmars-d-learn wrote: > D's compile-time-execution is fantastic, but there are some times when > I'd like to examine the generated code, or produce code that needs to > pass through earlier phases before CTFE, or do AST stuff. Sometimes I >

Re: Question about UDAs

2020-08-03 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Aug 03, 2020 at 08:16:57PM -0700, Ali Çehreli via Digitalmars-d-learn wrote: [...] > UDAs were added to D by a request from Manu Evans and that's when I > learned them. In one of Manu's use cases they would put a @Tweakable > attribute to certain struct members. The effect of that

Re: Question about UDAs

2020-08-03 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Aug 03, 2020 at 03:00:08AM +, Cecil Ward via Digitalmars-d-learn wrote: > When practically speaking would you use UDAs? A real-world use-case? There are probably more use cases than this, but for me, their primary usefulness is in declarative programming and compile-time

Re: Gotcha with const std.range.chunks

2020-07-30 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jul 30, 2020 at 06:52:42PM +, sportsracer via Digitalmars-d-learn wrote: [...] > int[] xs = new int[100]; > const chunked = xs.chunks(10); > writeln(chunked[0][0]); > } > > Error: mutable method std.range.Chunks!(int[]).Chunks.opIndex is not > callable using a const

Re: Overload comparison operators for "nullable" types

2020-07-30 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jul 30, 2020 at 01:41:05PM +, Oleg B via Digitalmars-d-learn wrote: [...] > Logically we can compare versions, but what must return `opCmp` if one of > versions has 'not comparible' state? [...] opCmp is allowed to return float; so you could return float.nan in this case. T --

Re: Contributing to D wiki

2020-07-27 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jul 27, 2020 at 11:39:32AM +, John Burton via Digitalmars-d-learn wrote: [...] > I tried looking there for information and examples of getting glfw3 > statically linked into my program using LDC and didn't really find > anything. > > I wonder if adding a page for static linking tips

Re: Help with Ranges

2020-07-27 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Jul 26, 2020 at 07:10:41AM +, Charles via Digitalmars-d-learn wrote: > Suppose I have the following line of code where arr is an array, > doSomething is some predicate that does a lot of processing on each > element, sort must come after the mapping, and there are more > operations

Re: std.process - avoid interaction with parent shell

2020-07-20 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jul 20, 2020 at 04:55:52PM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: > I am doing some scripting via D, and using std.process.execute to git > clone things. > > I don't want any user interaction. Occasionally, I get a repository > that no longer exists (404). Then git

Re: Good way to send/receive UDP packets?

2020-07-18 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Jul 18, 2020 at 04:00:09PM +, Dukc via Digitalmars-d-learn wrote: > I have a project where I need to take and send UDP packets over the > Internet. Only raw UDP - my application uses packets directly, with > their starting `[0x5a, packet.length.to!ubyte]` included. And only >

Re: Contributing to D wiki

2020-07-15 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jul 15, 2020 at 09:27:22PM +, tastyminerals via Digitalmars-d-learn wrote: [...] > D wiki is badly outdated. This is not a fact but a gut feeling after > reading through some of its pages. I was wondering who's owning it > myself but never actually dared to just go and update. Why

Re: Contributing to D wiki

2020-07-15 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jul 15, 2020 at 04:04:56PM +, aberba via Digitalmars-d-learn wrote: > So I'm looking to make changes to the D wiki but I'm not sure who to > talk to about such changes. > > Currently: Move all other IDEs low-quality down (maybe to Others) and > focus on just the few that really works

Re: GDC and DMD incompatability, can both be used?

2020-07-10 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Jul 11, 2020 at 04:28:32AM +, cy via Digitalmars-d-learn wrote: > hunt/source/hunt/serialization/JsonSerializer.d:125:20: error: basic > type expected, not foreach > 125 | static foreach (string member; FieldNameTuple!T) { > > I'm having a little trouble using the hunt

Re: What's the point of static arrays ?

2020-07-09 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jul 09, 2020 at 06:02:02PM +, IGotD- via Digitalmars-d-learn wrote: [...] > Is this the reason that ubyte[arraySize] doesn't create a dynamic > array with size arraySize? > > Now you need to do. > > ubyte[] arr; > arr.length = arraySize; Nah, just do this: arr = new

Re: Working with pointers/adresses

2020-07-09 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jul 09, 2020 at 05:24:33PM +, matheus via Digitalmars-d-learn wrote: [...] > I wonder if the question was more like intended to display the value > using pointers, ie: > > import std.stdio; > > void main(){ > int i; > readf("%d\n", i); > int *p = > writeln(*p); > } >

Re: Working with pointers/adresses

2020-07-09 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jul 09, 2020 at 04:16:53PM +, Quantium via Digitalmars-d-learn wrote: > I have one more question. I tested the programm, as you said, it > worked rarely because of OS restrictions. If I compile that code to > dll, and run it through dll launcher, should it work? No, it's subject to

Re: What's the point of static arrays ?

2020-07-09 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jul 09, 2020 at 12:12:06PM +, wjoe via Digitalmars-d-learn wrote: > + The size is known at compile time. > > vs. > > - Can neither grow nor shrink them > - Can't append elements > - Can't remove elements Consider a 3D game in which you represent vectors as static arrays of 4

Re: How to ensure template function can be processed during compile time

2020-07-08 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jul 08, 2020 at 08:11:05PM +, IGotD- via Digitalmars-d-learn wrote: [...] > Doing the same in D, would with my lack of knowledge look like this. > > > size_t mySize(T)() > { > return T.sizeof + 42; > } What you want is: enum mySize(T) = T.sizeof + 42; And there is no

Re: Program exited with code -11 when calling

2020-06-30 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jul 01, 2020 at 05:04:28AM +, Anthony via Digitalmars-d-learn wrote: [...] > auto str_utf8 = str.toUTF8(); > bson_error_t error > > auto bson = bson_new_from_json(cast(const uint8_t*)str_utf8.ptr, -1, > ); > > > I get a "Program exited with code -11" message. > Does anyone know what

Re: Why is this allowed

2020-06-30 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jun 30, 2020 at 02:06:13PM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: > On 6/30/20 12:37 PM, Steven Schveighoffer wrote: [...] > I take it back, I didn't realize this wasn't something that happened > with dynamic arrays: > > int[] dyn = [1, 2, 3]; > > dyn = 5; // error >

Re: Why is this allowed

2020-06-30 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jun 30, 2020 at 04:50:07PM +, Adam D. Ruppe via Digitalmars-d-learn wrote: > On Tuesday, 30 June 2020 at 16:41:50 UTC, JN wrote: > > I like my code to be explicit, even at a cost of some extra typing, > > rather than get bitten by some unexpected implicit behavior. > > I agree, I

Re: Why is this allowed

2020-06-30 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jun 30, 2020 at 04:22:57PM +, JN via Digitalmars-d-learn wrote: > Spent some time debugging because I didn't notice it at first, > essentially something like this: > > int[3] foo = [1, 2, 3]; > foo = 5; > writeln(foo); // 5, 5, 5 > > Why does such code compile? I don't think this

Re: Recursive delegate inside template?

2020-06-26 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jun 26, 2020 at 02:12:00PM +, drathier via Digitalmars-d-learn wrote: > I'm trying to get this to compile, without much luck: > > ``` > bool foo() > { > template fn(A) > { > A delegate(A) fn; > fn = delegate A(A a) > { > return fn(a); >

Re: Unused template arguments; what type to use?

2020-06-26 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jun 26, 2020 at 01:40:57PM +, Simen Kjærås via Digitalmars-d-learn wrote: > On Friday, 26 June 2020 at 13:21:25 UTC, drathier wrote: > > How can I tell the compiler that I will never create a value of type > > X, while still being able to write code that uses it? Using void as > > a

Re: figure out where a particular template function is located

2020-06-24 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jun 24, 2020 at 04:28:24PM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: > I have code that instantiates a template: > > templ!int("abc"); > > When I read the source of where I *think* this template should be, I > can't find one that would match (I think). I feel like it's

Re: opBinary : Static ifs or specialization?

2020-06-23 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jun 23, 2020 at 11:53:36PM +, claptrap via Digitalmars-d-learn wrote: > So you have opBinary and half a dozen operators to implement. Do you > use a separate method for each operator or do you have one method and > a big static if else if to select code path? [...] If your

Re: called copy constructor in foreach with ref on Range

2020-06-22 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jun 23, 2020 at 03:25:55AM +, 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

Re: called copy constructor in foreach with ref on Range

2020-06-22 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jun 22, 2020 at 08:53:22PM -0600, Jonathan M Davis via Digitalmars-d-learn wrote: [...] > Exactly. It's because of issues like this that generic, range-based > functions need to be tested with a variety of range types - including > reference types. Without that, bugs are routinely missed.

Re: called copy constructor in foreach with ref on Range

2020-06-22 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jun 22, 2020 at 09:11:07PM +, Stanislav Blinov via Digitalmars-d-learn wrote: > On Monday, 22 June 2020 at 20:51:37 UTC, Jonathan M Davis wrote: [...] > > And moving doesn't fix anything, since the original variable is > > still there (just in its init state, which would still be

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