Re: Looking for a workaround
On Wednesday, 6 April 2022 at 18:10:32 UTC, Guillaume Piolat wrote: Any idea how to workaround that? I really need the same UDA in parent and child class. Use a frontend >= dmd 2.099, it works according to run.dlang.io.
Re: How to use ImportC?
On Friday, 4 March 2022 at 01:30:00 UTC, Leonardo wrote: Thanks but not worked here. ``` [leonardo@leonardo-pc dimportc]$ dmd --version DMD64 D Compiler v2.098.1 ``` Please retry with the [beta](https://dlang.org/download.html#dmd_beta) or [nightly build](https://github.com/dlang/dmd/releases/tag/nightly). I think your bug was already fixed since 2.098.1.
Re: How to convert a string command line argument to an int?
On Thursday, 3 March 2022 at 07:32:24 UTC, BoQsc wrote: I tried to use `std.conv.parse(args[2])`, [...] But I'm getting this error The code doesn't declare the type to be parsed, use `parse!uint(...)`. But `to!uint` seems more appropriate for your code because `parse` ignores non-number characters after the number, e.g. ```d void main() { string input = "123abc"; writeln(parse!uint(input)); // 123 } ```
Re: how to handle very large array?
On Wednesday, 9 February 2022 at 10:03:21 UTC, MichaelBi wrote: day6 of the advent of code 2021 needs to handle an array of 10^12 length, or even bigger... As others have mentioned, huge arrays require appropriate memory / the use of memory-mapped files to actually store it. But the calculation will take a *long* time even if your program could allocate an array of that size. There's a way to use a much smaller array to manage the lanternfish population...
Re: Why does is the RandomAccessInfinite interface not a valid RandomAccessRange?
On Sunday, 19 December 2021 at 09:19:31 UTC, D Lark wrote: Do you know if there's a nightly version I can specify to use your fix? Nightly builds are available at https://github.com/dlang/dmd/releases/tag/nightly.
Re: Structured binding declaration (like in C++)
On Wednesday, 13 October 2021 at 20:02:05 UTC, Vindex wrote: Is there a decomposition for tuples and other data structures? No, but you can emulate it, e.g. by using AliasSeq: ```d import std.meta : AliasSeq; import std.typecons : tuple; import std.stdio : writeln; void main() { int a; string b; AliasSeq!(a, b) = tuple(1, "hello"); writeln("a = ", a); writeln("b = ", b); } ``` https://run.dlang.io/is/aUEtSK
Re: Download a file into array (using std.net.curl.download)
On Wednesday, 7 July 2021 at 10:27:47 UTC, notna wrote: On Windows: [...] Nice and helpful Error messages is on the top of our desires list, right? It's hard to give proper error backtraces without debug information (-g). Anyways, I can reproduce the error when compiling with `-m32` (the default), using `-m32mscoff` and `-m64` works as expected. You should probably avoid `-m32` in general (as dub does btw).
Re: Download a file into array (using std.net.curl.download)
On Monday, 5 July 2021 at 14:57:20 UTC, BoQsc wrote: Let's say I can't store information into files. Is it possible to download a file into an array. Yes, use [`get`](https://dlang.org/phobos/std_net_curl.html#.get): ```d import std.net.curl; void main() { char[] content = get("https://gist.githubusercontent.com/deekayen/4148741/raw/98d35708fa344717d8eee15d11987de6c8e26d7d/1-1000.txt;); } ```
Re: how do i fix this node_dlang error?
On Monday, 7 June 2021 at 19:03:44 UTC, Jack wrote: actually i didnt so I just added: ```d shared static this() { Runtime.initialize(); } shared static ~this() { Runtime.terminate(); } ``` but it didn't change anything That doesn't work because `Runtime.initialize()` is responsible to execute the module ctors. You could try `pragma(crt_constructor)`[1] instead. [1] https://dlang.org/spec/pragma.html#crtctor
Re: how do i fix this node_dlang error?
On Monday, 7 June 2021 at 02:33:38 UTC, Jack wrote: What am I missing? Does your code / `node_dlang` initialize Druntime before calling `writeln`? Try replacing the `writeln` with `puts` (from `core.stdc.stdio`) which doesn't require an initialized runtime.
Re: dmd error in wsl2
On Tuesday, 25 May 2021 at 15:54:31 UTC, bharathyes wrote: I wrote the basic code: You have a typo in your code, `std.studio` instead of `std.stdio`.
Re: How do you compile DMD on Windows?
On Saturday, 1 May 2021 at 22:44:34 UTC, Blatnik wrote: They say to use the digitalmars make tool and not the normal make that I have installed. Great, no problem, except it didn't come installed with the compiler as is advertised. I don't have a make program in D/dmd2/windows/bin and I can't find a version of it online. Missed that in my initial reply. DM make is included in DMC which is available on this site, see the "other downloads". e.g. http://downloads.dlang.org/other/dm857c.zip
Re: How do you compile DMD on Windows?
On Saturday, 1 May 2021 at 22:44:34 UTC, Blatnik wrote: I wanna hack on the compiler, but I've spend 3 hours and I can't get the damned thing to compile! You probably need to update the VS paths to match your local installation, Microsoft apparently changed their directory layout a few years ago AFAICT. I use the following patch for win64.mak in druntime/phobos: ```patch diff --git a/win64.mak b/win64.mak index 1b4a9208..6f37ba13 100644 --- a/win64.mak +++ b/win64.mak @@ -6,7 +6,7 @@ MODEL=64 #VCDIR=\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110 #SDKDIR=\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0 # Visual Studio 2015 and before -VCDIR=\Program Files (x86)\Microsoft Visual Studio 10.0\VC +VCDIR=C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\Hostx64\x64 SDKDIR=\Program Files (x86)\Microsoft SDKs\Windows\v7.0A DMD_DIR=..\dmd @@ -19,9 +19,9 @@ DMD=$(DMD_DIR)\generated\$(OS)\$(BUILD)\$(MODEL)\dmd # Visual Studio 2015 and before BINDIR=$(VCDIR)\bin\amd64 -CC=$(BINDIR)\cl -LD=$(BINDIR)\link -AR=$(BINDIR)\lib +CC=$(VCDIR)\cl +LD=$(VCDIR)\link +AR=$(VCDIR)\lib CP=cp DOCDIR=doc ```
Re: How to skip class/function when using -HC flag to generate C++ headers?
On Monday, 19 April 2021 at 17:43:34 UTC, evilrat wrote: On Monday, 19 April 2021 at 17:37:31 UTC, MoonlightSentinel wrote: Omit the modules from your blacklist when generating the header file (allthough that requires rerunning dmd) Ok thanks, well, time for new dub subconfig. Or... maybe at least pre-build step for that specific module. That being said, it might be worthwhile to add a flag to customize the minimum visibility for declarations (currently it only omits private declarations)
Re: How to skip class/function when using -HC flag to generate C++ headers?
On Monday, 19 April 2021 at 16:26:20 UTC, evilrat wrote: Or maybe there is a way to tell it whitelist/blacklist modules? The header generator only translates modules passed on the command line, other declarations are omitted unless they are required by another symbol. Omit the modules from your blacklist when generating the header file (allthough that requires rerunning dmd)
Re: DMD64 2.095.1 unresolved _D4core8internal7switch___T14__switch_error in optimized build only
On Friday, 9 April 2021 at 11:36:21 UTC, x3g6h7k8 wrote: The interesting point is this happens only in optimized builds. In debug builds everything is fine. Looks like DMD skips the codegen for this template instance because it erroneously assumes that the template is already emitted in another object file. This decision is probably affected by some code in a `debug` statement which makes it work when compiling with `-debug`. You can try to compile the release version with `-allinst`.
Re: Package import order with extern(C++) classes and std.container.array failure
On Tuesday, 6 April 2021 at 09:33:32 UTC, cc wrote: Just encountered this compilation failure in DMD winx64 2.096, which previously worked in 2.095 and prior versions. DMD 2.094.2 fails with the same error? But current master works for me. Just wondering if it's a bug, or a new issue to keep in mind when importing modules? Sorry for the complex nature of this scenario but I'll try to keep it as simple as possible. That's a bug, ordering of import should never affect whether some code compiles or not. I'm curious why this worked in prior dmd versions, and if it's something I'll need to worry about going forward when creating complex multi-file modules. The ordering of imports can make a difference in some cases because it affects the order in which dmd analyses declarations - which might hide or reveal a bug. Please file a bug report at https://issues.dlang.org if you encounter such issues.
Re: Broken examples
On Saturday, 6 March 2021 at 09:38:54 UTC, Ali Çehreli wrote: Are you getting the same errors with those dmd versions? My locally installed compiler is dmd 2.094.2, which seems to be too old for parse's new doCount template parameter. (I look inside /usr/include/dmd/phobos/std/conv.d on my Linux installation to be sure.) Ali The new template parameter was introduced in 2.095.0. See https://dlang.org/changelog/2.095.0.html#conv_parse_count
Re: Broken examples
On Saturday, 6 March 2021 at 08:15:16 UTC, Imperatorn wrote: Are you sure? 樂 I tried switching to dmd-beta, dmd-nightly, ldc and ldc-beta and none of them worked. Yes. All of those were stuck at 2.093 due to some issues with Travis. We've resolved those issues over the last few days and automatically updated the host compilers today. Note that the output of doc examples is apparently cached, so you might need to make some changes to get the actual output (until the cache invalidates(?) ).
Re: Broken examples
On Friday, 5 March 2021 at 22:01:37 UTC, Imperatorn wrote: Any idea why? The examples are compiled using an older host compiler (__VERSION__ is 2.093) but use features introduced in a later version. This will be fixed by upgrading the compiler (the examples are checked using current master IIRC).
Re: Can someone explain this?
On Saturday, 6 February 2021 at 14:39:38 UTC, Jeff wrote: So, I'm guessing there's something going on under-the-hood using the ~ operator with the enum and I'd like to understand what it is. Enum to string conversion is usually implemented using the name of the enum member, regardless of it's value (which might be any type). String concatenation is not defined for A, so the enum member is implicitly converted to it's base type (see [1], paragraph 5). Likewise, if there's an easier method of getting the "value of enum" I haven't discovered yet, that'd be just as nice to know. ;) You can use an is expression to determine the base type... ``` is(A BaseType == enum) ``` ...and use `cast(BaseType) A.foo` [1] https://dlang.org/spec/enum.html#named_enums
Re: More elaborate asserts in unittests?
On Thursday, 22 October 2020 at 04:20:35 UTC, Mathias LANG wrote: Unfortunately this switch still has some bugs, so you can easily run into linker errors. I'm hoping to ultimately make it the default though. Which is more of a template emission problem because `-checkaction=context` uses a templated hook in druntime (`core.internal.dassert._d_assert_fail`). `-checkaction=context` should support any unary and binary expression and properly format all data types (unless we've missed some special case). Note that it currently does not support complex expressions (e.g `assert(0 <= a && a < 10);` but I/someone else might implement that in the future.
Re: Template: get function name
On Monday, 17 August 2020 at 09:59:21 UTC, novice3 wrote: On Monday, 17 August 2020 at 09:45:55 UTC, novice3 wrote: access violation occur. reduced code https://run.dlang.io/is/U58t9R The wrapper parameters don't inherit the storage classes from the wrapped function. Try using std.traits.Parameters instead: https://run.dlang.io/is/wTyJWD. ``` import std.traits : Parameters; void test(out int x) { x = 42; } void call (alias fn)(Parameters!fn args) { fn(args); } void main() { int a; a = 111; test(a); assert(a == 42); a = 222; call!test(a); assert(a == 42); } ```
Re: getopt Basic usage
On Saturday, 15 August 2020 at 04:09:19 UTC, James Gray wrote: I am trying to use getopt and would not like the program to throw an unhandled exception when parsing command line options. Try passing config.passThrough, it should disable the exception for unknown arguments.
Using D with PlatformIO
Currently working on a PlatformIO [1] based project in C++ and want to throw some D into the mix. Couldn't find an existing solution and I'm not sure how to implement a proper solution using PIO's scripting capabilities. Did somebody try this before and could share his experiences? [1] https://platformio.org
Re: 2-D array initialization
On Friday, 31 July 2020 at 23:42:45 UTC, Andy Balba wrote: How does one initialize c in D ? ubyte[3][4] c = [ [5, 5, 5], [15, 15,15], [25, 25,25], [35, 35,35] ]; none of the statements below works c = cast(ubyte) [ [5, 5, 5], [15, 15,15], [25, 25,25], [35, 35,35] ]; This is an invalid cast because it tries to coerce the entire literal into an ubyte. Also it would be an assignment instead of an initialization because this is independent of c's declaration. c[0] = ubyte[3] [5, 5, 5] ; c[1] = ubyte[3] [15, 15,15] ; c[2] = ubyte[3] [25, 25,25] ; c[3] = ubyte[3] [35, 35,35] ; A cast is usually specified as `cast(TargetType) value` but not necesseray in this example. Use this instead: c[0] = [5, 5, 5] ; c[1] = [15, 15,15] ; c[2] = [25, 25,25] ; c[3] = [35, 35,35] ; for (int i= 0; i<3; i++) for (int j= 0; i<4; j++) c[i][j]= cast(ubyte)(10*i +j) ; The array indices and the inner loop condition are wrong for (int i= 0; i<3; i++) for (int j= 0; j<4; j++) c[j][i]= cast(ubyte)(10*i +j) ; You could also use foreach-loops, e.g. foreach (j, ref line; c) foreach (i, ref cell; line) cell = cast(ubyte) (10 * i + j);
Re: Why are std.bitmanip.bitfields so big ?
On Tuesday, 28 July 2020 at 09:28:27 UTC, wjoe wrote: It was run on the doc page. I suppose the examples are wrapped in a unittest block? Indeed, see https://github.com/dlang/phobos/blob/cd2ba0d2c378a893ec0eaefc57b87d0770a1990c/std/bitmanip.d#L293-L314
Re: Finding the file and unittest that triggers an ICE during dub project build only when unittests are enabled
On Monday, 15 June 2020 at 16:55:00 UTC, MoonlightSentinel wrote: And these unittests trigger the segfault: https://github.com/nordlow/phobos-next/blob/4a18833e226be0d3363fb07f02a7bcf531892e17/src/nxt/cyclic_array.d#L704-L712 https://github.com/nordlow/phobos-next/blob/4a18833e226be0d3363fb07f02a7bcf531892e17/src/nxt/cyclic_array.d#L1020-L1072 Adding version(none) removes the segfaults but yields other error messages.
Re: Finding the file and unittest that triggers an ICE during dub project build only when unittests are enabled
On Monday, 15 June 2020 at 10:54:47 UTC, Per Nordlöw wrote: What have I missed? My mistake, dub dustmite expects a path to an temporary directory suitable for dustmite (it copies the entire projet + all dependencies s.t. dustmite sees the entire source code). That path needs to be somewhere outside of the project directory. But "dub dustmite ..." failed the first tests so I've reduced this manually by determining the correct compiler invocation (dub test -v) and running dustmite against all (remaining) source files. The test condition was a script which ran dmd in gdb and checked whether it segfaulted at the specific line of code. The segfault happens when compiling CyclicArray with preview=dtorfields, see the bug report below for a reduced example. TLDR: Found your bug and reported it here: https://issues.dlang.org/show_bug.cgi?id=20934
Re: Finding the file and unittest that triggers an ICE during dub project build only when unittests are enabled
On Friday, 12 June 2020 at 18:18:25 UTC, Per Nordlöw wrote: How do I most easily track down which unittest in which file that causes the crash? You could try to reduce your code using Dustmite through dub. This should do the job IIRC: dub dustmite --compiler=dmd --build=unittest --compiler-status=139 See `dub dustmite --help` for more details.
Re: Alpine support for D
On Tuesday, 9 June 2020 at 14:23:34 UTC, Jesse Phillips wrote: I notice that in the new release for Alpine Linux it mentions support for D. Announcement: https://forum.dlang.org/thread/raue6j$1vp4$2...@digitalmars.com
Re: Should it compile?
On Saturday, 6 June 2020 at 08:55:20 UTC, Jack Applegame wrote: Should it compile? No, moveEmplace just sees a const reference and doesn't know that a is void-initialized.
Re: Sum string lengths
On Wednesday, 13 May 2020 at 13:52:13 UTC, Andrey wrote: Hi, I want to sum lengths of all strings in array: auto data = ["qwerty", "az", ""]; Fold and reduce doesn't work: auto result = data.fold!`a + b.length`(0U); gives error: static assert: "Incompatible function/seed/element: binaryFun/uint/string" How to do it in one line? The problem is that you provide a uint as seed (which determines the type of the accumulated value) but your function returns a ulong (or rather size_t). You can fix this by changing the type of your seed, either use ulong or size_t. auto result = data.fold!`a + b.length`(0UL); auto result = data.fold!`a + b.length`(size_t(0));
Re: Simple array problem
On Saturday, 4 April 2020 at 09:09:44 UTC, Giovanni Di Maria wrote: Why the followin code gives me the error? Error: only one index allowed to index `int[3][3]` Use matrix[2][2] instead of matrix[2,2].
Re: Linear array to matrix
On Saturday, 4 April 2020 at 09:25:14 UTC, Giovanni Di Maria wrote: Is there a Built-in function (no code, only a built-in function) that transform a linear array to a Matrix? You can combine slide [1] and array [2]: import std; void main() { auto input = [10,20,30,40,50,60,70,80,90,100,110,120]; auto output = input.slide(3, 3).array; writeln(input); writeln(); writeln(output); } Note that output is a view of input and not a copy. [1] https://dlang.org/phobos/std_range.html#.slide [2] https://dlang.org/phobos/std_array.html#.array
Re: How to code Z-Function of string?
On Thursday, 26 March 2020 at 19:34:08 UTC, Quantium wrote: string s="abc"; writeln(s[1]); // Should write 'b' or not??? Is it a legit code or it doesn't work ? Yes, but keep in mind that char[] implies UTF8. Hence this won't work if your input contains e.g. chinese characters. Refer to std.utf (https://dlang.org/phobos/std_utf.html) for some utilities to deal with UTF.
Re: OR in version conditional compilation
On Wednesday, 18 March 2020 at 16:23:26 UTC, IGotD- wrote: you get the idea. So is this possible at all or do you have to duplicate the code for each version identifier despite they are equal for many version identifiers? The usual workaround is to define a common version, e.g. version(X86) version = X86_ANY version(X86_64) version = X86_ANY version(X86_ANY) { // your code here }
Re: static foreach / How to construct concatenated string?
On Sunday, 8 March 2020 at 20:28:01 UTC, Robert M. Münch wrote: You can get rid of the enum [...] That depends on your use case. You will need enum if you want to use the value at compile time (e.g. when using it as a template parameter). Otherwise a normal string will suffice. und the static and it will work too. Yesh, I forgot about the old implicit static foreach loop.
Re: static foreach / How to construct concatenated string?
On Saturday, 7 March 2020 at 16:30:59 UTC, Robert M. Münch wrote: Is this possible at all? You can use an anonymous lambda to build the string in CTFE: -- struct S { int a; bool b; } import std; enum string sql = { string s = "CREATE TABLE data("; static foreach(f; FieldNameTuple!S) { s ~= f ~ ","; } s ~= ");"; return s; } (); pragma(msg, sql); -- This prints "CREATE TABLE data(a, b);"
Re: core.atomic.atomicStore and structs
On Tuesday, 3 March 2020 at 11:04:53 UTC, Saurabh Das wrote: PS: Any chance this will make it into DMD 2.091.0? Yes, this fix will be in the upcoming release.
Re: core.atomic.atomicStore and structs
On Tuesday, 3 March 2020 at 09:12:40 UTC, Saurabh Das wrote: Is this supposed to not work anymore? Or is this a bug? That is a bug, see https://issues.dlang.org/show_bug.cgi?id=20629
Re: Is deprecating a template supposed to work?
On Thursday, 20 February 2020 at 22:31:16 UTC, aliak wrote: Is this suppose to give a deprecation error message? deprecated("a") alias A(T) = B!T; template B(T) { alias B = T; } void main() { A!int a; // should this cause a message "a" ? } ?? Or am I using it wrong maybe? It's a bug, see https://issues.dlang.org/show_bug.cgi?id=20190
Re: D create many thread
On Wednesday, 5 February 2020 at 13:05:59 UTC, Eko Wahyudin wrote: What is this thread for? and is it normal in D? According to the stack trace your applications triggered a GC cycle. The marking is done in parallel to minimize pause times, see https://dlang.org/spec/garbage.html
Re: digger: Failed to spawn new process (The system cannot find the file specified.)
On Monday, 3 February 2020 at 20:41:00 UTC, Anonymouse wrote: It doesn't seem to include debugging symbols. Does digger not build its dmds with -g? The exceptions happens inside of build.d not dmd which wasn't built with debug informations until recently. Here's the full log: https://pastebin.com/raw/6MyVDFPc Thanks. I can't tell exactly what went wrong but i would suggest building build.d with debug symbols and running it in verbose mode, e.g.: ..\generated\build.exe --called-from-make OS=windows BUILD=release MODEL=32 HOST_DMD= HOST_DC=C:\Temp\work\dl\dmd-2.079.0\dmd2/windows/bin\dmd.exe ..\generated\windows\release\32\lexer.lib -v The repository should be checked out in work/repo/dmd IIRC
Re: digger: Failed to spawn new process (The system cannot find the file specified.)
On Monday, 3 February 2020 at 16:54:20 UTC, Anonymouse wrote: It does a `dmd.exe -of..\generated\build.exe`, but then the immediately following call to `..\generated\build.exe` fails? What am I doing wrong? The executable was launched because make would yield a different error message otherwise. This seems to be an error during the environment processing of build.d, could you provide the full stack trace for this exception? std.process.ProcessException@std\process.d(752): Failed to spawn new process (The system cannot find the file specified.)
Re: How do I fix my failed PRs?
On Sunday, 2 February 2020 at 16:29:34 UTC, bauss wrote: Since he just edited markdown files then it shouldn't matter. Why? The grep checks explicitly for trailing whitespace in markdown files.
Re: How do I fix my failed PRs?
On Sunday, 2 February 2020 at 08:54:02 UTC, mark wrote: However, four have not been accepted, apparently for technical reasons. But I don't understand what's wrong or what I need to do to fix them. (I'm not very knowledgeable about github.) The Travis log suggest that your PRs contain some whitespace errors: The command "grep -nr --include \*.md '\s$' . ; test $? -eq 1" exited with 1 You could try to execute the ggrep command locally to identify lines containing possible errors. PS: Feel free to comment on your PR directly s.t. reviewers/bypassers can see that you could use some assistance.
Re: Cannot implicitly convert expression [[0, -1, 2], [4, 11, 2]] of type int[][] to const(int[2])[]
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, -1], [1, 2], [6, 1]]; matA is an SA containing <2> elements of type int[3]. matB is an SA containing <3> elements of type int[2].
Re: DMD won't compile re-init of variable
On Thursday, 30 January 2020 at 21:09:41 UTC, Simon wrote: Hi dlang community, I'm trying to implement a "reset" functionality which should revert all variables to the program start initial state. Example: import Graph; protected Edge[string] m_string2edge; int main() { // adding some elements // not important how it works // m_string2edge[name] = e; // resetting it m_string2edge = null; m_string2edge = new Edge[string]; // <- won't compile return 0; } How do I revert my variable to the init state? Thanks in advance, Simon You can use m_string2edge.clear() if you want to remove all entries from m_string2edge. See https://dlang.org/spec/hash-map.html#properties
Re: Template Usage with Eponymous Trick
On Thursday, 30 January 2020 at 17:00:08 UTC, ShadoLight wrote: Agreed. My question though is should the 'shorthand' notation _replace_ the 'longhand' notation, or be available _in addition_ to the 'longhand' notation in the eponymous case (so the eponymous notation is just 'syntax sugar' if you will). Consider the following example: T foo(T = int)(T val = T.init) { return val + 1; } void main() { auto i = foo!().foo(); writeln(i); } What should be the value of i? 1: foo!() is the template instantiation, foo() the method call 2: foo!() and foo() are method calls. The answer is 2 (because empty braces are optional) but with your proposed change it would be ambigous (unless one interpreation was prioritized which would probably be more confusing). Maybe we should rather ask what benefit results from allowing this explicit notation? IMHO the entire purpose of epynemous templates is to make templates containing one public* symbol less verbose which is a common use case. *public ~ useful outside of the templated symbol And, in that case some of the examples in the documentation needs fixing. Agreed, the documentation could use some polishing.
Re: Template Usage with Eponymous Trick
On Thursday, 30 January 2020 at 15:14:43 UTC, ShadoLight wrote: Is there a technical reason for this limitation? Why are the 'classical' invocation style not allowed for eponymous templates as well? It seems somewhat arbitrary - note that inner/outer functions does not have this limitation - the fllowing is legal and compiles (and does not lead to infinite recursion): I guess the intention is to e.g. allow UFCS on the return values of templated functions without ambiguities, e.g.: void main() { import std.algorithm, std.stdio; int[] values = [ 1, 2, 3, 4 ]; values.filter!(i => i % 2 == 0) .map!(i => i / 2) // Does not refer to any hidden member of template filter .each!writeln; } From my POV is void foo(T)() { ... } just a shorthand notation for template foo(T) { void foo() {} } allthough it could probably use some improvements to the documentation.
Re: Deprecation message from phobos compiling a vibe.d app.
On Thursday, 30 January 2020 at 13:05:05 UTC, drug wrote: That's probably triggered by some constraints. I had the issue like this with Nullable: https://github.com/dlang/phobos/pull/7324 The core problem here stems from the fact that templates are always instantiated in the scope of the template declaration [1]. Hence dmd instantiates some template using a deprecated symbol in a non-deprecated scope and issues these warnings. I'm currently working on a PR [2] to resolve this issue but still have to fix some issues when dealing with overloaded symbols as template alias parameters. [1] https://dlang.org/spec/template.html#instantiation_scope [2] https://github.com/dlang/dmd/pull/10677
Re: CT regex in AA at compile time
On Tuesday, 7 January 2020 at 15:40:58 UTC, Taylor Hillegeist wrote: but I can't get it to work. it says its an Error: non-constant expression. I imagine this has to do with the ctRegex template or something. maybe there is a better way? Does anyone know? This issue is unrelated to ctRegex, AA literals are non-constant expressions (probably due to their implementation). You can work around this by using module constructors or lazy initialisation inside of a function: static Regex!char[TokenType] Regexes; shared static this() { Regexes = [ TokenType.Plus: ctRegex!(`^ *\+`), TokenType.Minus: ctRegex!(`^ *\-`), TokenType.LPer: ctRegex!(`^ *\(`), TokenType.RPer: ctRegex!(`^ *\)`), TokenType.Number: ctRegex!(`^ *[0-9]+(.[0-9]+)?`) ]; }
Re: Finding position of a value in an array
On Monday, 30 December 2019 at 23:15:48 UTC, JN wrote: I also had to ask because I couldn't find it. In other languages it's named "index()", "indexOf()" or "find()". D is the only language I know which uses the "countUntil" scheme. And even so it's not obvious from the name if it's the index of the element or number of preceding elements. The main difference to other languages is that countUntil works an arbitrary ForwardRanges which might not offer random access, hence index would be misleading for them. But improvements to the documentation could probably help to alleviate this confusion.
Re: Some code that compiles but shouldn't
On Monday, 30 December 2019 at 18:18:49 UTC, uranuz wrote: So as you see I have added a lot of enforce to test if all variables are not null. But nothing was null and the reason of segfault were unclear. What about moduleName, mod and the return value of mod.toStdJSON()? And whats the return type of ctx.response.write? (Returning a void expression is allowed and avoids some special casing in generic code)
Re: Finding position of a value in an array
On Monday, 30 December 2019 at 14:30:12 UTC, Ron Tarrant wrote: I was trying to do this with an array of pointers, but I get an error (which suggests to me that I don't know what data type a pointer is): It's not a ulong? Have I forgotten so much? D disallows implicit conversion from integers to pointers and hence they cannot be compared. You would need to explicitly cast your ulong to an appropriate pointer type
Re: Finding position of a value in an array
On Sunday, 29 December 2019 at 08:31:13 UTC, mipri wrote: On Sunday, 29 December 2019 at 08:26:58 UTC, Daren Scot Wilson wrote: Reading documentation... Array, Algorithms, ... maybe I've been up too late... how does one obtain the index of, say, 55 in an array like this int[] a = [77,66,55,44]; I want to do something like: int i = a.find_value_returning_its_index(55); assert(i==2) I'm sure it's obvious but I'm not seeing it right now. int i = a.countUntil!(v => v == 55); assert(i == 2); A predicate isn’t required, countUntil accepts single elements: int i = a.countUntil(55);
Re: array of functions/delegates
On Tuesday, 24 December 2019 at 07:37:02 UTC, Rumbu wrote: I am trying to create an array of functions inside a struct. struct S { void f1() {} void f2() {} alias Func = void function(); immutable Func[2] = [, ] } What I got: Error: non-constant expression '' Tried also with delegates (since I am in a struct context but I got: no `this` to create delegate `f1`. So, is there any way to have an array of functions without adding them at runtime? You can set funcs within the constructor but not as a default initializer because they have to be compile time constants (https://dlang.org/spec/struct.html#default_struct_init) struct S { void f1() {} void f2() {} alias Func = void delegate(); immutable Func[2] funcs; this(bool) { funcs = [, ]; } } creates a delegate which contain a function pointer and the context pointer (struct, closure, ...). In this example the latter contains a pointer to a concrete instance of S which is a usually a runtime value. (https://dlang.org/spec/type.html#delegates)
Re: array of functions/delegates
On Tuesday, 24 December 2019 at 13:13:12 UTC, MoonlightSentinel wrote: On Tuesday, 24 December 2019 at 10:40:16 UTC, Mike Parker wrote: struct S {} void f1(S s) {} void f2(S s) {} alias Func = immutable(void function()); immutable Func[2] funcs = [cast(Func), cast(Func)]; Though, it's not clear to me wy the one requires casting the pointer type and the other doesn't. Because typeof() == void function(S) Working example without casts using type deduction: import std.stdio: writeln; struct S {} void f1(S s) { writeln("f1"); } void f2(S s) { writeln("f2"); } immutable funcs = [, ]; void main() { S s; foreach(f; funcs) { f(s); } }
Re: array of functions/delegates
On Tuesday, 24 December 2019 at 10:40:16 UTC, Mike Parker wrote: struct S {} void f1(S s) {} void f2(S s) {} alias Func = immutable(void function()); immutable Func[2] funcs = [cast(Func), cast(Func)]; Though, it's not clear to me wy the one requires casting the pointer type and the other doesn't. Because typeof() == void function(S)