Re: Can std.variant be used with std.container.rbtree?

2022-04-02 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 2 April 2022 at 14:49:15 UTC, Vijay Nayar wrote: On Saturday, 2 April 2022 at 14:35:10 UTC, Vijay Nayar wrote: The `tryMatch` method fails to compile, and instead I get the following error: ```d /dlang/dmd/linux/bin64/../../src/phobos/std/sumtype.d(2004): Error: static assert:

Re: Good to the last drop.

2022-03-31 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 31 March 2022 at 19:44:23 UTC, WhatMeWorry wrote: Is there a way to programmatically determine the exact maximum memory size available to the DRuntime’s array implementation? Closest you can get is probably [`GC.stats`][1], which will give you the total amount of free memory

Re: How to unit-test behavior under "version"?

2022-03-29 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 29 March 2022 at 19:55:52 UTC, Andrey Zherikov wrote: I have a function below (just an example). What's the recommended way to unit-test it for all `version` cases? ```d void f() { import std.stdio: writeln; version(foo) writeln("foo"); else

Re: Detecting manifest contants

2022-03-12 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 12 March 2022 at 19:00:23 UTC, Paul Backus wrote: On Saturday, 12 March 2022 at 18:49:32 UTC, Anonymouse wrote: Currently I'm testing if a function that takes the address of the member compiles, and I think it works, but like with everything `__traits(compiles)` it strikes me as

Re: Detecting manifest contants

2022-03-12 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 12 March 2022 at 18:49:32 UTC, Anonymouse wrote: Currently I'm testing if a function that takes the address of the member compiles, and I think it works, but like with everything `__traits(compiles)` it strikes me as it might not be the right way to go about things. It sounds

Re: How to exclude function from being imported in D language?

2022-03-08 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 8 March 2022 at 17:47:47 UTC, BoQsc wrote: Premise: In D language, only one main(){} function can exist in a program. Having two `main()` functions throws an error. Let's say I want to use some functionality of another program, but it has a `main(){}` function. How can I import

Re: What does dual-context mean?

2022-03-01 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 1 March 2022 at 14:51:47 UTC, wjoe wrote: Hello, what's a dual context as in the deprecation message? It means you have a struct or class member function that accesses its calling context via a template alias parameter. See this bug report for more information:

Re: opCast in class prevents destroy

2022-03-01 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 1 March 2022 at 16:40:50 UTC, Paul Backus wrote: It's a bug in druntime. `destroy` needs to reinterpret the class reference as a `void*` to pass it to `rt_finalize`: https://github.com/dlang/druntime/blob/v2.098.1/src/object.d#L4209 However, `cast(void*)` is not the correct way

Re: opCast in class prevents destroy

2022-03-01 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 1 March 2022 at 04:59:49 UTC, Mike Parker wrote: On Tuesday, 1 March 2022 at 04:29:56 UTC, cc wrote: ```d struct A {} class B { A opCast(T : A)() { return A(); } } void main() { auto b = new B(); destroy(b); } ``` fails with ```

Re: template instance does not match template declaration

2022-02-25 Thread Paul Backus via Digitalmars-d-learn
On Friday, 25 February 2022 at 23:34:59 UTC, kdevel wrote: What about this: ```d module model; // model.d import std.file : read; // this line provokes the error private int read (string filename) // now it's private { import std.file; auto data = std.file.read (filename); return 0;

Re: template instance does not match template declaration

2022-02-25 Thread Paul Backus via Digitalmars-d-learn
On Friday, 25 February 2022 at 23:05:00 UTC, kdevel wrote: It seems the template parameter f becomes not aliased to model.read in the presence of the selective import. Bug or feature? I'd call this a bug. Currently, selective imports are implemented using `alias`es under the hood, which

Re: How to check that a member function is generated by compiler?

2022-02-25 Thread Paul Backus via Digitalmars-d-learn
On Friday, 25 February 2022 at 19:06:25 UTC, Ali Çehreli wrote: On 2/25/22 08:24, Paul Backus wrote: > I've seen `.stringof` give inconsistent results. (E.g., > https://issues.dlang.org/show_bug.cgi?id=18269) That must be a part of the reasons why Adam D Ruppe repeats that .stringof should

Re: How to check that a member function is generated by compiler?

2022-02-25 Thread Paul Backus via Digitalmars-d-learn
On Friday, 25 February 2022 at 14:25:22 UTC, Andrey Zherikov wrote: Another interesting observation - is there any explanation why `typeof` returns different results for generated `opAssign`? [...] If I move `foreach` loop into a function (e.g. `main`) then the first pragma prints the same

Re: Odd behaviour of std.range

2022-02-22 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 22 February 2022 at 12:48:21 UTC, frame wrote: What am I missing here? Is this some UTF conversion issue? ```d string a; char[] b; pragma(msg, typeof(a.take(1).front)); // dchar pragma(msg, typeof(b.take(1).front)); // dchar ``` This is a feature of the D standard library known

Re: SumType alias can't be deduced?

2022-02-21 Thread Paul Backus via Digitalmars-d-learn
On Monday, 21 February 2022 at 18:43:18 UTC, Emmanuelle wrote: If you run this, the compiler should emit this error: ```d onlineapp.d(14): Error: template `onlineapp.foobar` cannot deduce function from argument types `!()(SumType!(int, Unit))` onlineapp.d(8):Candidate is:

Re: How to use sets in D?

2022-02-08 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 8 February 2022 at 21:58:49 UTC, H. S. Teoh wrote: On Tue, Feb 08, 2022 at 09:47:13PM +, Paul Backus via Digitalmars-d-learn wrote: [...] The `alias` and the `enum` just make the code a little nicer to read by letting you write `Unit` instead of `void[0]` and `unit` instead

Re: How to use sets in D?

2022-02-08 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 8 February 2022 at 21:08:47 UTC, tastyminerals wrote: https://forum.dlang.org/post/mailman.1072.1581112984.31109.digitalmars-d-le...@puremagic.com On Friday, 7 February 2020 at 22:03:00 UTC, H. S. Teoh wrote: On Fri, Feb 07, 2020 at 07:37:08PM +, mark via Digitalmars-d-learn

Re: Linkage question

2022-01-24 Thread Paul Backus via Digitalmars-d-learn
On Monday, 24 January 2022 at 19:41:30 UTC, frame wrote: It claims that the D calling convention matches C. But it seems that the arguments are pushed in order whereas C does it in reverse order and the -218697648 value is indeed my 3rd string pointer. Windows has two calling conventions for

Re: Meaning of in, out and inout

2022-01-20 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 20 January 2022 at 13:19:06 UTC, Sergey wrote: https://forum.dlang.org/post/17nwtnp4are5q$.1ddtvmj4e23iy@40tude.net On Tuesday, 10 May 2005 at 01:06:14 UTC, Derek Parnell wrote: [...] Thanks a lot for your explanation. I started to learn D language recently and I have

Re: alias and __VERSION__ condition doesn't play well

2022-01-18 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 18 January 2022 at 04:42:45 UTC, frame wrote: At the very top of my module I have this declaration: ```d static if (__VERSION__ >= 2098) { alias Foo = TypeA; } else { alias Foo = TypeB; } ``` No problem inside the module itself but this doesn't work when imported from

Re: number ranges

2022-01-17 Thread Paul Backus via Digitalmars-d-learn
On Monday, 17 January 2022 at 10:24:06 UTC, forkit wrote: so I'm wondering why the code below prints: 1 2 3 4 and not 1 2 3 4 5 as I would expect. foreach (value; 1..5) writef("%s ", value); This kind of half-open interval, which includes the lower bound but excludes the upper bound, is

Re: Throw stack trace from program kill

2022-01-16 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 16 January 2022 at 18:22:04 UTC, Steven Schveighoffer wrote: Does this work normally? The memory error handler for Linux jumps through a lot of hoops to be able to throw an error from a signal handler. See https://github.com/dlang/druntime/blob/master/src/etc/linux/memoryerror.d

Re: Throw stack trace from program kill

2022-01-16 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 16 January 2022 at 15:15:07 UTC, Hipreme wrote: Is there some way to throw a stack trace when killing the program from the CTRL+C from the terminal? It would help a lot into debugging occasional infinity loops On POSIX, you can use the `sigaction` function to install a signal

Re: How to convert a chunks result to a two-dimensional array

2022-01-14 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 15 January 2022 at 01:49:14 UTC, forkit wrote: I want int[][] like this -> [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15]] Any help will be appreciated. note: to2Darray is not a valid statement ;-) // --- module test; import std; void main() { int[][]

Re: @safe question

2022-01-11 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 12 January 2022 at 00:45:23 UTC, H. S. Teoh wrote: IMNSHO, that @trusted lambda thing is an anti-pattern that should be avoided, needless to say already promoted. It's papering over a problem that ought to be fixed instead of being pushed under the rug. There's nothing wrong

Re: @safe question

2022-01-11 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 11 January 2022 at 21:38:58 UTC, forkit wrote: On Tuesday, 11 January 2022 at 14:54:51 UTC, Paul Backus wrote: .. If you compile with -preview=dip1000, the compiler will actually keep track of which pointers point to stack memory, and will allow your original code. But

Re: @safe question

2022-01-11 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 11 January 2022 at 10:57:28 UTC, forkit wrote: On Monday, 10 January 2022 at 03:21:46 UTC, Paul Backus wrote: Taking the address of a local variable is forbidden in @safe code. Even though str is a ref variable that points to a heap-allocated string, it is still considered a

Re: @safe question

2022-01-09 Thread Paul Backus via Digitalmars-d-learn
On Monday, 10 January 2022 at 01:16:31 UTC, forkit wrote: On Sunday, 9 January 2022 at 21:56:05 UTC, Salih Dincer wrote: Try the @trusted and in/out: ... .. . thanks for introducing me to the in/out feature of D :-) I'll certainly look into that feature more. But my question still remains:

Re: Safe code doesnt seem to complain when it should

2022-01-06 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 6 January 2022 at 16:12:10 UTC, HuskyNator wrote: I can't figure out why this code works: ```d union A { int* b; float c; } int fun(A a) @safe { return *(()=>a.b)(); // return *a.b; //Complains about pointer type overlap } ``` I tried to find out

Re: Returning value by ref does not create a ref. Is this intentional?

2022-01-04 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 5 January 2022 at 04:35:12 UTC, Tejas wrote: ```d import std.stdio:writeln; ref int func(return ref int a){ a = 6; // modifies a as expected return a; } void main(){ int a = 5; auto c = func(a); // I expected c to alias a here c = 10; // Expected to modify a as

Re: Is there a File-like object for unit tests?

2022-01-04 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 4 January 2022 at 17:01:41 UTC, Amit wrote: Hi! I wrote a text parser that takes a File argument and parses that file's contents. Now I would like to write a unit-test for that parser. I need a File (or a general IO interface) that reads from an in-memory buffer, similar to

Re: print ubyte[] as (ascii) string

2022-01-02 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 2 January 2022 at 09:15:32 UTC, eugene wrote: ``` p1.d(9): Error: cannot cast expression `until(b[], '\x0a', Flag.yes)` of type `Until!("a == b", ubyte[], char)` to `char[]` ``` Here's a working version: ```d import std.stdio; import std.string; import std.algorithm : until,

Re: How are extra copy constructor parameters used?

2021-12-29 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 30 December 2021 at 02:04:30 UTC, Ali Çehreli wrote: On 12/29/21 5:14 PM, Paul Backus wrote: Therefore, when you write your own copy constructors, you should always use `inout` if possible, so that compiler-generated copy constructors will be able to copy instances of your

Re: How are extra copy constructor parameters used?

2021-12-29 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 30 December 2021 at 01:04:10 UTC, Ali Çehreli wrote: 2) Unlike the examples there, I think the parameter should most usefully be defined as 'const' unless there is a special reason: struct S { // const(S) instead of S: this(ref const(S) that) { } } Do you agree? When the

Re: Ambiguity issue with expanding and evaluating single template type parameter enums

2021-12-27 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 28 December 2021 at 00:42:18 UTC, data pulverizer wrote: On Tuesday, 28 December 2021 at 00:32:03 UTC, Paul Backus wrote: In this case, the simplest solution is to have your code generator accept a string as its input, rather than a type. For example: ```d enum instantiate(string

Re: Ambiguity issue with expanding and evaluating single template type parameter enums

2021-12-27 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 28 December 2021 at 00:13:13 UTC, data pulverizer wrote: The types I'm generating are a template type I've constructed for R's SEXP, so that my wrapped numeric vector (struct) type is denoted `RVector!(REALSXP)`. But `alias REALSXP = SEXPTYPE.REALSXP` where `SEXPTYPE` is an `enum`.

Re: Protected Members in Class

2021-12-24 Thread Paul Backus via Digitalmars-d-learn
On Friday, 24 December 2021 at 15:46:17 UTC, Salih Dincer wrote: On Friday, 24 December 2021 at 14:29:29 UTC, Paul Backus wrote: `protected` in D means "this symbol can only be accessed from (a) the module where it's defined, and (b) classes that inherit from the class where it's defined."

Re: Protected Members in Class

2021-12-24 Thread Paul Backus via Digitalmars-d-learn
On Friday, 24 December 2021 at 12:10:32 UTC, Salih Dincer wrote: What is the difference between protected and private? Also how can a function outside of the class access it? `private` in D means "this symbol can only be accessed from the module where it's defined." `protected` in D

Re: Is it possible to exchange the linker with a dub project to use mold

2021-12-22 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 22 December 2021 at 15:20:15 UTC, Christian Köstlin wrote: https://github.com/rui314/mold Kind regards, Christian This was recently discussed in the "General" forum: https://forum.dlang.org/thread/fiyfgqykhdmglqypx...@forum.dlang.org

Re: Why does is the RandomAccessInfinite interface not a valid RandomAccessRange?

2021-12-18 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 18 December 2021 at 19:48:00 UTC, D Lark wrote: Can someone please tell me if this is expected behaviour and what the reasoning is behind this choice? Looks like a bug. I've filed a report on the D issue tracker: https://issues.dlang.org/show_bug.cgi?id=22608

Re: Restrict type of function parameter to a defined list of types?

2021-12-12 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 12 December 2021 at 13:42:08 UTC, Martin B wrote: On Sunday, 12 December 2021 at 13:21:06 UTC, Adam D Ruppe wrote: On Sunday, 12 December 2021 at 13:11:58 UTC, Martin B wrote: Just add a forwarding overload: Hi Adam, i am wondering if there is another possibility without having to

Re: Wouldn't the compiler be smart with this shadowing variable?

2021-12-11 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 11 December 2021 at 20:22:13 UTC, frame wrote: ```d // iteration works, but scope behind does nothing for({int i=0; j=0;} i<10; ++i, {++i; ++j;} ){} // endless loop for({int i=0; j=0;} i<10; {++i; ++j;} ){} ``` Not sure if bug or feature but it is inconsistent for me and thus a

Re: sleeping vs sched_yield

2021-12-04 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 2 December 2021 at 23:29:17 UTC, Chris Katko wrote: Is there a D std.library accessible version of POSIX sched_yield: https://man7.org/linux/man-pages/man2/sched_yield.2.html D bindings for POSIX headers are provided by modules in the package `core.sys.posix`. So, for

Re: A pass() identity range?

2021-12-02 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 2 December 2021 at 11:35:53 UTC, D Lark wrote: I am a newcomer to D and I am looking for equivalent functionality in phobos (so far I have not found). The function you are looking for is [`std.range.tee`][1]. It was added to Phobos in 2014 by [pull request #1965][2],

Re: What is pure used for?

2021-11-25 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 25 November 2021 at 07:26:48 UTC, sclytrack wrote: int * pureFunction() 1) the pointer needs to be the same. 2) the value that the pointer points to needs to be the same. I call this the "value of interest" with relation to pure. The pointer doesn't matter. 3) both the pointer

Re: Why does this call the copy constructor 2 times and the assigment constructor once?

2021-11-19 Thread Paul Backus via Digitalmars-d-learn
On Friday, 19 November 2021 at 14:05:40 UTC, rempas wrote: So, when I assign the value of the variable "name" in the "other_name", first it will call the copy constructor, then it will call the assignment constructor and then it will call the copy constructor again. Why is this happening? I

Re: writeln the struct from the alis this Example from the home page

2021-11-18 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 18 November 2021 at 13:51:42 UTC, Martin Tschierschke wrote: Hello, if you take the example from the home page, with the additional last line: ```d struct Point { private double[2] p; // Forward all undefined symbols to p alias p this; double dot(Point rhs) {

Re: mixins

2021-11-17 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 17 November 2021 at 14:51:58 UTC, Abby wrote: Hello I would like to create validation mixin or mixin template which would return on error. Something like this: ``` mixin template Validate(a, b) { if(a > b) { writeln("invalid input"); return false; } }

Re: Using in one class a constant defined in another class

2021-11-16 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 16 November 2021 at 18:12:34 UTC, chopchop wrote: Hi, I have a class Ground which defines some playground constants (at least constant to the class): ``` class Ground { immutable WALL = -2; immutable playgroundWidth = 77; immutable playgroundHeight

Re: How to return a reference to structs?

2021-11-04 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 4 November 2021 at 18:21:06 UTC, Andrey Zherikov wrote: On Thursday, 4 November 2021 at 13:03:54 UTC, Paul Backus wrote: Have the lambda return by reference: ```d auto get() { return idx.map!(ref (i) => a[i]); } ``` Making this example a bit complex: I want `get` to return

Re: How to return a reference to structs?

2021-11-04 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 4 November 2021 at 11:26:30 UTC, Andrey Zherikov wrote: I have the following code example: ```d struct A{} A[5] a; ulong[] idx = [1,3,4]; auto get() { return idx.map!(_ => a[_]); } foreach(i; 0 .. a.length) write([i], " "); writeln; foreach(ref b; get()) write(, "

Re: __cpuid like in C

2021-11-01 Thread Paul Backus via Digitalmars-d-learn
On Monday, 1 November 2021 at 16:00:05 UTC, Arsium wrote: Hello, Currently, I'm working to implement myself WinAPI functions. However, I could not find anything matching with : __cpuid like : https://gist.github.com/boxmein/7d8e5fae7febafc5851e Any idea ? Not sure if it's exactly the

Re: srand in D

2021-10-31 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 31 October 2021 at 16:54:35 UTC, pascal111 wrote: Hi! I'm C learner and found the high similarity between C and D, and was converting C code into D but couldn't get the equivalent of this C statement "srand(time(NULL));". Since D gives you access to the C standard library, you can

Re: Does associative array change the location of values?

2021-10-29 Thread Paul Backus via Digitalmars-d-learn
On Friday, 29 October 2021 at 17:40:38 UTC, Andrey Zherikov wrote: I want to have a pointer to a value in an associative array. Does AA guarantee that the value will remain at the same address all the time unless I remove the corresponding key? I couldn't find any guarantees similar to C++

Re: SumType

2021-10-28 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 28 October 2021 at 09:02:52 UTC, JG wrote: I am heavily using SumType (which I like very much). The problem I am having is that is seems to be causing slow compile times (as can be observed by profiling during the compile). The problem seems to be with match (which is extremely

Re: Question re specific implicit type coercion

2021-10-18 Thread Paul Backus via Digitalmars-d-learn
On Monday, 18 October 2021 at 15:04:11 UTC, Don Allen wrote: Section 12.17 of the Language Reference does not indicate any circumstance in which a dynamic array, which the literal is, is implicitly coerced to a pointer. This is a special case for string literals, covered in [section

Re: Why is opIndexAssign replaced by opSlice here?

2021-10-17 Thread Paul Backus via Digitalmars-d-learn
On Monday, 18 October 2021 at 03:42:35 UTC, Paul Backus wrote: My guess is that you got into this situation by trying to follow the example in the spec's section on ["Slice Assignment Operator Overloading"][2]. Unfortunately, that example is incorrect. [2]:

Re: Why is opIndexAssign replaced by opSlice here?

2021-10-17 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 17 October 2021 at 22:52:27 UTC, Elmar wrote: Hello Dear community. I'd like to overload `opIndexAssign` for a struct which wraps around a generic array (so that it can't support `opIndex` due to unknown return type). Broken down as much as possible this is the code: ``` import

Re: Obtaining type and value of a variable named in another variable

2021-10-16 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 17 October 2021 at 02:42:54 UTC, Tejas wrote: Doesn't solve the compile-time only problem though :( The only solution I can think of is something with `variant`s, but it'll be messy. Well, the fundamental issue is that in a language like D that compiles to machine code, variable

Re: Obtaining type and value of a variable named in another variable

2021-10-16 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 16 October 2021 at 23:07:22 UTC, DLearner wrote: ```d void main() { import std.stdio; int fooVar = 4; string strVar; strVar = "fooVar"; writeln(typeof(mixin(strVar))); writeln(mixin(strVar)); } ``` Failed with 2x "Error: variable `strVar` cannot be read at

Re: How to make a function that accepts optional struct but can accept struct literal too

2021-10-15 Thread Paul Backus via Digitalmars-d-learn
On Friday, 15 October 2021 at 20:33:33 UTC, JN wrote: Is there some nice way of achieving something like this C99 code in D? ```c #include typedef struct { int x, y; } inputs_t; void foo(inputs_t* optional_inputs) { if (!optional_inputs) { printf("0 0\n"); } else {

Re: Parameter forwarding

2021-10-14 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 14 October 2021 at 16:53:17 UTC, Kostiantyn Tokar wrote: Take a look at `Tuple` [constructor](https://github.com/dlang/phobos/blob/4130a1176cdb6111b0c26c7c53702e10011ff067/std/typecons.d#L672). ```d this(Types values) { field[] = values[]; } ``` Actual fields are constructed

Re: How to test if a string is pointing into read-only memory?

2021-10-12 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 12 October 2021 at 21:42:45 UTC, IGotD- wrote: On Tuesday, 12 October 2021 at 09:20:42 UTC, Elronnd wrote: There is no good way. Can't it be done using function overloading? Function overloading lets you distinguish between arguments with different types, but strings in

Re: problem with alias this and Tuple

2021-10-12 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 12 October 2021 at 15:55:40 UTC, Johann Lermer wrote: Thanks, understood. But isn't this a deficiency in the library that should be fixed? You mean the part about how `Object.toHash` doesn't work with `const`? Yes, it is a deficiency in the library. The problem is, it cannot be

Re: problem with alias this and Tuple

2021-10-12 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 12 October 2021 at 09:30:57 UTC, Johann Lermer wrote: Hi all, I have a problem with Tuples and struct templates that contain an alias this: ```d import std; struct Element(T) { T payload; alias payload this; this (T p) { payload =

Re: Output Range Problem? How to make it work?

2021-10-11 Thread Paul Backus via Digitalmars-d-learn
On Monday, 11 October 2021 at 15:57:00 UTC, apz28 wrote: The subject is why the call is not allowed (format is not mention in question). Below sample is a bit more clear [...] ref Writer outFail(Writer, Char)(return ref Writer sink) if (isOutputRange!(Writer, Char) &&

Re: Output Range Problem? How to make it work?

2021-10-10 Thread Paul Backus via Digitalmars-d-learn
On Monday, 11 October 2021 at 00:19:44 UTC, apz28 wrote: /* Getting this error onlineapp.d(34): Error: none of the overloads of `toString` are callable using argument types `(Buffer)`, candidates are: onlineapp.d(19):`onlineapp.Foo.toString()` onlineapp.d(26):

Re: UFC creating name conflict

2021-10-09 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 9 October 2021 at 21:26:52 UTC, Chris Piker wrote: Unfortunately importing `core.time` brings in a seconds function, which due to UFC is confused with a structure member of the same name. How can I explicitly tell the compiler that I'm referring to: ```d thing.seconds # The

Re: Mutually recursive template expansion

2021-10-04 Thread Paul Backus via Digitalmars-d-learn
On Monday, 4 October 2021 at 11:38:04 UTC, bauss wrote: Actually it is covered by the spec. See: https://dlang.org/spec/expression.html#mixin_expressions It clearly says: ``` Each AssignExpression in the ArgumentList is evaluated at compile time ``` Which means that Br cannot be used in

Re: Regular Templates May Be `mixin`d?

2021-10-03 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 3 October 2021 at 03:34:19 UTC, surlymoor wrote: Lord, I'm careless. Thanks. So the difference between a `mixin template` and a regular one is that the former may only be used with a `mixin` statement? Yes, exactly.

Re: Regular Templates May Be `mixin`d?

2021-10-02 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 3 October 2021 at 02:52:20 UTC, surlymoor wrote: This compiles and works. I checked the spec, and I don't see anything; probably missed it, however; mentioning the fact that regular templates may be used with `mixin`. Is this expected? Yes, this is intentional and expected. From

Re: type in extern declaration

2021-09-20 Thread Paul Backus via Digitalmars-d-learn
On Monday, 20 September 2021 at 20:02:24 UTC, NonNull wrote: How do I write the type of a function so as to alias it, and use that in an extern(C) declaration? For example, how do I write the type of an external function int main2(int argc, char** argv) { // } You can create an alias to

Re: Cannot Instantiate SumType

2021-09-20 Thread Paul Backus via Digitalmars-d-learn
On Monday, 20 September 2021 at 11:21:28 UTC, surlymoor wrote: The error in question... ``` Error: variable `std.typecons.ReplaceTypeUnless!(isSumTypeInstance, This, SumType!(Foo!(bar)), Foo!(bar)).F!(bar).replaceTemplateArgs` type `void` is inferred from initializer `bar()`, and variables

Re: D's dll and classes

2021-09-19 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 19 September 2021 at 12:00:22 UTC, Hipreme wrote: Basically: I have a main program which would contain a lot of code. I have a secondary program which I want to call code from the main program, but it will be compiled as a DLL to the main program call a single entry point from that

Re: Return complete multi-dimensional array after appending

2021-09-15 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 15 September 2021 at 20:32:12 UTC, eXodiquas wrote: ```d [1,0,3,4,0,5] .fold!((a, e) => e != 0 ? a[0] ~ e : a[1] ~ e)(cast(int[][]) [[],[]]) .flatten .writeln ``` This should sort all non 0s into the `a[0]` array and all 0s into the `a[1]` array. But it won't work because the

Re: Which operators cannot be overloaded and why not?

2021-09-13 Thread Paul Backus via Digitalmars-d-learn
On Monday, 13 September 2021 at 14:42:42 UTC, jfondren wrote: On Monday, 13 September 2021 at 14:33:03 UTC, user1234 wrote: - condition al expression ` cond ? exp : exp ` And many other boolean operators, unary !, binary && and || https://dlang.org/spec/operatoroverloading.html lists all the

Re: Development of the foundation of a programming language

2021-09-13 Thread Paul Backus via Digitalmars-d-learn
On Monday, 13 September 2021 at 00:53:06 UTC, leikang wrote: I want to contribute to the development of the dlang language, but I feel that I am insufficient, so I want to ask the big guys, can I participate in the development of the Dlang language after learning the principles of compilation?

Re: Looking to get typeof parseXML return value

2021-09-07 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 7 September 2021 at 05:00:50 UTC, Chris Piker wrote: On Tuesday, 7 September 2021 at 04:40:25 UTC, jfondren wrote: typeof(parseXML!simpleXML("")) xml; Hey, I like this trick! I was wondering what to use for the const(char)[] variable in the typeof statement. It's

Re: Absence of isAllocator trait

2021-09-06 Thread Paul Backus via Digitalmars-d-learn
On Monday, 6 September 2021 at 13:24:56 UTC, Basile B. wrote: It's because the clients of an allocator should rather statically check for specific traits of an allocator, there are too many possible permutations of capabilities possible, not all can allocate and deallocate, not all can

Re: "+=" (overloads) with custom array slices on both lhs, and rhs ??

2021-09-05 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 5 September 2021 at 19:43:20 UTC, james.p.leblanc wrote: Dear D-ers, I have constructed a custom array type that works, but is missing correct functioning on some operator overloads. [...] ```d import std.stdio; import myarray_mod; ``` Please post the source code for

Re: Phobos Unittest

2021-09-03 Thread Paul Backus via Digitalmars-d-learn
On Friday, 3 September 2021 at 23:39:44 UTC, Per Nordlöw wrote: When is a phobos unittest supposed to be qualified with version `(StdUnittest)`? Almost never. `version (StdUnittest)` should be used in Phobos wherever you would normally use a `version (unittest)` block. It is not for the

Re: Phobos Unittest

2021-09-03 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 4 September 2021 at 00:09:37 UTC, H. S. Teoh wrote: This is related to the bogonity of the current behaviour of -unittest, which compiles *all* unittests of *all* imported modules, even when you're compiling user code that has no interest in Phobos unittests. Well, no; it

Re: Module import incompatibility

2021-08-31 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 31 August 2021 at 14:09:01 UTC, Steven Schveighoffer wrote: Are you sure this is the problem? `PdfSurface` is not a valid identifier here except for the class. In order to access the package, you need to use `cairo.PdfSurface`. Must've changed since you last checked: ```d //

Re: Module import incompatibility

2021-08-31 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 31 August 2021 at 12:57:33 UTC, frame wrote: No, it has one, eg: ```d module cairo.PdfSurface; ``` but the filename is PdfSurface.d and class name also :\ You can use a selective import: ```d import cairo.PdfSurface: PdfSurface; ```

Re: byte + byte = int: why?

2021-08-29 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 29 August 2021 at 16:21:40 UTC, jfondren wrote: ... after Phobos is patched. ``` error: undefined identifier ‘Lhs’, did you mean alias ‘Rhs’? ``` Shows how much anyone actually uses this code, I guess--the bug was introduced [in 2017][1], and as far as I can tell has never even

Re: byte + byte = int: why?

2021-08-29 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 29 August 2021 at 15:42:18 UTC, Ali Çehreli wrote: Depending on the situation, you may want to use std.conv.to, which does a value range check and throws an exception to prevent an error: byte foo(byte a, byte b) { import std.conv : to; return (a + b).to!byte; }

Re: Scope of Mixins

2021-08-26 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 26 August 2021 at 16:16:55 UTC, DLearner wrote: Please confirm that mixins of format: ``` string mxn1(string VarName) { ... } ``` Invoked like: ``` mixin(mxn1("Var1")); ``` Have a wider scope than mixins like: ``` string mxn2(string VarName)() { ... } ``` Invoked like: ```

Re: scope(exit) with expected library

2021-08-25 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 25 August 2021 at 14:42:07 UTC, Steven Schveighoffer wrote: I think it's possible to work with some mechanics that aren't necessarily desirable. Something like: ```d ErrorHandler error = registerErrorHandler; error.onFailure({writeln("division failed");});

Re: scope(exit) with expected library

2021-08-25 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 25 August 2021 at 14:04:54 UTC, WebFreak001 wrote: Would it be possible to extend `scope(exit)` and `scope(success)` to trigger properly for functions returning `Expected!T` as defined in the [expectations](https://code.dlang.org/packages/expectations) and

Re: classify a user struct as an "array" or "slice"

2021-08-20 Thread Paul Backus via Digitalmars-d-learn
On Friday, 20 August 2021 at 15:12:25 UTC, james.p.leblanc wrote: Greetings, I have a user created struct, let's call this "**fakeArray**": For all intents and purposes fakeArray behaves like an array (or slice, I guess). (i.e. It has a number of operator overloadings, and *foreach*

Re: D equivalent of C++ explicit

2021-08-19 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 19 August 2021 at 18:04:58 UTC, Tejas wrote: On Thursday, 19 August 2021 at 17:43:59 UTC, Paul Backus wrote: On Thursday, 19 August 2021 at 17:38:14 UTC, Tejas wrote: As the topic says: Is there an equivalent to C++'s `explicit` keyword in D? No, because all constructors are

Re: D equivalent of C++ explicit

2021-08-19 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 19 August 2021 at 17:38:14 UTC, Tejas wrote: As the topic says: Is there an equivalent to C++'s `explicit` keyword in D? No, because all constructors are explicit in D.

Re: std.stdio.File is throwing with the message of: "Access Violation"

2021-08-18 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 18 August 2021 at 17:42:53 UTC, Ruby The Roobster wrote: Output(Given to me by a message box that display's Throwable.msg in it's body): Access Violation Is this a bug, or me being stupid? If it's the latter, than tell me what went wrong. I am using DMD 2.097.2 It's

Re: Non-consistent implicit function template specializations

2021-08-18 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 18 August 2021 at 11:10:49 UTC, Rekel wrote: I tried looking into how isArray is defined. Like, does being able to index mean it's an array, or are these only static &/or dynamic arrays? Did you read the documentation? https://phobos.dpldocs.info/std.traits.isArray.html

Re: simple (I think) eponymous template question ... what is proper idimatic way ?

2021-08-17 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 17 August 2021 at 19:53:52 UTC, james.p.leblanc wrote: On Tuesday, 17 August 2021 at 19:44:29 UTC, H. S. Teoh wrote: You could use a helper template and an AliasSeq for this: template isAmong(T, S...) { static if (S.length == 0)

Re: How to get element type of a slice?

2021-08-17 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 17 August 2021 at 12:21:31 UTC, Ferhat Kurtulmuş wrote: Hello folks, Hope everyone is doing fine. Considering the following code, in the first condition, I am extracting the type Point from the slice Point[]. I searched in the std.traits, and could not find a neater solution

Re: Drawbacks of exceptions being globally allocated

2021-08-15 Thread Paul Backus via Digitalmars-d-learn
On Monday, 16 August 2021 at 02:26:04 UTC, Tejas wrote: Agh >_< if I remove the `scope`and replace it with `auto`? No longer having anything to do with the stack or RAII, just using malloc + emplace instead of GC? Yeah it might leak memory unless the catch block explicitly frees the

Re: Drawbacks of exceptions being globally allocated

2021-08-15 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 15 August 2021 at 18:47:27 UTC, Tejas wrote: Do you see anything wrong with the following `emplace`-allocated, RAII following exceptions: [...] Is this good enough for general use now? Any other drawbacks? It only works if you're throwing and catching in the same function.

Re: Anyway to achieve the following

2021-08-15 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 15 August 2021 at 07:10:17 UTC, JG wrote: Hi, This is exactly the behaviour I was trying to obtain. It however comes with a fair amount of overhead, as can be seen in the following llvm ir: [...] I'm not really familiar with llvm ir, but looking at it on godbolt, it seems

Re: Drawbacks of exceptions being globally allocated

2021-08-14 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 14 August 2021 at 15:58:17 UTC, Tejas wrote: If you're willing to help further, would you please tell me why there is a GC allocation in the code below that uses ```emplace```? Will such code truly work if GC is never linked in the program? https://run.dlang.io/is/XEc2WJ ```

<    1   2   3   4   5   6   7   8   9   >