Re: How to profile compile times of a source code?

2021-01-30 Thread Stefan Koch via Digitalmars-d-learn
On Saturday, 30 January 2021 at 23:34:50 UTC, Stefan Koch wrote: this special version of dmd will generate a trace file which can be read with the included printTraceHeader tool you will want to take a look at the PhaseHist command which shows you the compiler phase that took the most time.

Re: How to profile compile times of a source code?

2021-01-30 Thread Stefan Koch via Digitalmars-d-learn
On Saturday, 30 January 2021 at 22:47:39 UTC, Ahmet Sait wrote: I'm looking for ways to figure out what parts of the code slows down the compiler other than brute force trial. Can I use -vtemplates switch for this? Would -v (verbose) switch helpful in some way? How would I know if my

Re: Where is pragma Declaration in the grammar?

2020-12-04 Thread Stefan Koch via Digitalmars-d-learn
On Saturday, 5 December 2020 at 02:59:58 UTC, Paul Backus wrote: On Saturday, 5 December 2020 at 00:57:04 UTC, Stefan Koch wrote: Hi, today I've been dusting my SDC fork and implemented a rudimentary version of pragma(msg). I could pragmaStatement as in void f() { pragma(msg,

Where is pragma Declaration in the grammar?

2020-12-04 Thread Stefan Koch via Digitalmars-d-learn
Hi, today I've been dusting my SDC fork and implemented a rudimentary version of pragma(msg). I could pragmaStatement as in void f() { pragma(msg, typeof(f)); } but not a declaration as in pragma(msg, typeof(f)) without a function body. there is a StaticAssert is in the grammar under

Re: lambdas with types

2020-11-21 Thread Stefan Koch via Digitalmars-d-learn
On Friday, 20 November 2020 at 14:08:23 UTC, jmh530 wrote: Doing something like below fails because I don't seem to be able to make a templated lambda that just takes types. Is the only way to do something similar to create a separate function to handle the condition, or is there some other

Re: is type checking in D undecidable?

2020-10-22 Thread Stefan Koch via Digitalmars-d-learn
On Thursday, 22 October 2020 at 18:33:52 UTC, Ola Fosheim Grøstad wrote: In general, it is hard to tell if a computation is long-running or unsolvable. You could even say ... it's undecidable :)

Re: Deprecation in traits

2020-09-30 Thread Stefan Koch via Digitalmars-d-learn
On Wednesday, 30 September 2020 at 08:33:58 UTC, Frak wrote: On Tuesday, 29 September 2020 at 18:25:03 UTC, Steven Schveighoffer wrote: On 9/29/20 1:08 PM, Frak wrote: [...] Because it's probably coming from a constraint, you probably can't figure out the exact usage. What's more annoying

__traits for checking if a type is dynamic array (slice)

2020-08-18 Thread Stefan Koch via Digitalmars-d-learn
https://forum.dlang.org/post/ptgud7$16f6$1...@digitalmars.com On Monday, 26 November 2018 at 14:02:15 UTC, Andrei Alexandrescu wrote: On 11/26/18 4:04 AM, Per Nordlöw wrote: Why is there no - __traits(isArray, T) alongside - __traits(isStaticArray, T) and - __traits(isAssociativeArray, T)

Re: Forcing inline functions (again) - groan

2020-07-15 Thread Stefan Koch via Digitalmars-d-learn
On Wednesday, 15 July 2020 at 13:38:34 UTC, Cecil Ward wrote: I recently noticed pragma(inline, true) which looks extremely useful. A couple of questions : 1. Is this cross-compiler compatible? 2. Can I declare a function in one module and have it _inlined_ in another module at the call

Re: Should a parser type be a struct or class?

2020-06-17 Thread Stefan Koch via Digitalmars-d-learn
On Wednesday, 17 June 2020 at 11:50:27 UTC, Per Nordlöw wrote: Should a range-compliant aggregate type realizing a parser be encoded as a struct or class? In dmd `Lexer` and `Parser` are both classes. In general how should I reason about whether an aggregate type should be encoded as a

Re: Why is there no range iteration with index by the language?

2020-06-09 Thread Stefan Koch via Digitalmars-d-learn
On Tuesday, 9 June 2020 at 23:53:16 UTC, Q. Schroll wrote: Is there any particular reason why std.range : enumerate is a thing and [...] I don't think there is any particular reason. Other than that might shadow an opApply. And C++ iterators didn't have it.

Re: Fastest way to check using if identifier has already been defined, using static if or similar?

2020-06-04 Thread Stefan Koch via Digitalmars-d-learn
On Thursday, 4 June 2020 at 14:20:45 UTC, Q. Schroll wrote: On Thursday, 4 June 2020 at 09:03:40 UTC, Simen Kjærås wrote: string exists(string s) { return "__traits(compiles, { mixin(\"alias _ = "~s~";\"); })"; } Little nitpicking, but D has many forms of string literals. Escaping is

Re: Fastest way to check using if identifier has already been defined, using static if or similar?

2020-06-03 Thread Stefan Koch via Digitalmars-d-learn
On Wednesday, 3 June 2020 at 09:39:34 UTC, Basile B. wrote: On Wednesday, 3 June 2020 at 09:03:22 UTC, drathier wrote: [...] You can use this template: enum Exists(alias T) = is(typeof(T)); I don't know if there's a faster way bu this technic is used, notatbly in phobos, to workaroud

Re: Compilation memory use

2020-05-04 Thread Stefan Koch via Digitalmars-d-learn
On Monday, 4 May 2020 at 17:00:21 UTC, Anonymouse wrote: TL;DR: Is there a way to tell what module or other section of a codebase is eating memory when compiling? I'm keeping track of compilation memory use using zsh `time` with some environmental variables. It typically looks like this.

Re: odd atomicOp errors from vibe-core

2020-04-09 Thread Stefan Koch via Digitalmars-d-learn
On Friday, 10 April 2020 at 01:54:14 UTC, Steven Schveighoffer wrote: I'm building a library that uses vibe-core as an indirect dependency. Specifically, I'm testing the library with dub test. [...] Those are signed unsigned mismatches when it tries to lock. that's probably in vibe-d

Re: How do I disable the multithreaded GC?

2020-04-09 Thread Stefan Koch via Digitalmars-d-learn
On Thursday, 9 April 2020 at 20:56:59 UTC, Johan wrote: On Thursday, 9 April 2020 at 20:42:18 UTC, Stefan Koch wrote: Simple question, how do I keep the GC from spawning threads? Cheers, Stefan https://dlang.org/changelog/2.087.0.html#gc_parallel Thanks a lot.

How do I disable the multithreaded GC?

2020-04-09 Thread Stefan Koch via Digitalmars-d-learn
Simple question, how do I keep the GC from spawning threads? Cheers, Stefan

Re: Fixing race issues the right way

2020-04-05 Thread Stefan Koch via Digitalmars-d-learn
On Sunday, 5 April 2020 at 22:24:27 UTC, solidstate1991 wrote: My game engine is currently broken due to some race issue I don't really know how to resolve. It seems that the compiler tries to skip instructions that are not locked with a `writeln()` or something similar. Usually I can safely

Re: Find the heir.

2020-03-29 Thread Stefan Koch via Digitalmars-d-learn
On Sunday, 29 March 2020 at 14:04:53 UTC, TodNaz wrote: Hello! class A { ... } class B : A { ... } class C : A { ... } A example1; B example2 = new B(...); A = example2; auto heir = A.whoheir(); /// The question in this code is: is it possible to track the class inheritor? Or is

Re: Strange counter-performance in an alternative `decimalLength9` function

2020-02-26 Thread Stefan Koch via Digitalmars-d-learn
On Wednesday, 26 February 2020 at 00:50:35 UTC, Basile B. wrote: So after reading the translation of RYU I was interested too see if the decimalLength() function can be written to be faster, as it cascades up to 8 CMP. [...] It can be made faster using binary search. Not by much though.

Re: Speeding up compilation of template-heavy code

2020-02-22 Thread Stefan Koch via Digitalmars-d-learn
On Saturday, 22 February 2020 at 12:24:56 UTC, drathier wrote: On Saturday, 22 February 2020 at 11:53:38 UTC, Dennis wrote: On Saturday, 22 February 2020 at 11:26:19 UTC, Per Nordlöw wrote: Is there a dmd flag that shows the code after template instantiations has been performed? The -vcg-ast

Re: Speeding up compilation of template-heavy code

2020-02-22 Thread Stefan Koch via Digitalmars-d-learn
On Saturday, 22 February 2020 at 11:26:19 UTC, Per Nordlöw wrote: We're looking for a way to speed up compilation of template-heavy code. So we are trying to find out which parts of the code that is most costly to compile. Is there a dmd flag that shows the code after template instantiations

Re: betterC CTFE nested switch

2020-02-21 Thread Stefan Koch via Digitalmars-d-learn
On Friday, 21 February 2020 at 09:03:26 UTC, Abby wrote: On Monday, 17 February 2020 at 19:02:50 UTC, Stefan Koch wrote: Sorry I just realized I never published the code. I am going to add it to ctfeutils. Hi Stefan, I'm sorry to bother you, I just wanted to kindly ask if you would upload

Re: How to get the name of an object's class at compile time?

2020-02-18 Thread Stefan Koch via Digitalmars-d-learn
On Tuesday, 18 February 2020 at 03:33:21 UTC, Basile B. wrote: On Monday, 17 February 2020 at 22:34:31 UTC, Stefan Koch wrote: Upon seeing this I just implemented typeid(stuff).name; https://github.com/dlang/dmd/pull/10796 With any luck this will be possible in the next release ;) Can this

Re: How to get the name of an object's class at compile time?

2020-02-17 Thread Stefan Koch via Digitalmars-d-learn
On Monday, 17 February 2020 at 18:49:55 UTC, Steven Schveighoffer wrote: On 2/17/20 2:28 AM, Nathan S. wrote: What I want is something like this: string className(in Object obj) {     return obj is null ? "null" : typeid(obj).name; } ...except I want it to work in CTFE. What is the

Re: betterC CTFE nested switch

2020-02-17 Thread Stefan Koch via Digitalmars-d-learn
On Monday, 17 February 2020 at 11:51:03 UTC, Abby wrote: On Monday, 17 February 2020 at 11:05:46 UTC, Stefan Koch wrote: On Monday, 17 February 2020 at 10:18:32 UTC, Abby wrote: [...] I have a ctfe compatible string formatter, you should be to find it here

Re: betterC CTFE nested switch

2020-02-17 Thread Stefan Koch via Digitalmars-d-learn
On Monday, 17 February 2020 at 10:18:32 UTC, Abby wrote: Hi there guys, I was trying to generated code during compile time. Bassicly I'm creating a tokenizer and I would like to generated nested switch using betterC. [...] I have a ctfe compatible string formatter, you should be to find

Re: "register int n" alternative

2020-02-16 Thread Stefan Koch via Digitalmars-d-learn
On Sunday, 16 February 2020 at 13:48:43 UTC, Виталий Фадеев wrote: Possible mark variable for force use register ? Example C-code: { register char *buf; long pos; register int n; register int r; if (!n) return 0; } How to implement in D ? Don't you

Re: Unable to pass a D function member to a C callback

2019-11-02 Thread Stefan Koch via Digitalmars-d-learn
On Saturday, 2 November 2019 at 17:49:09 UTC, Luh wrote: Hello, When trying to pass a D function to the C callback, the compiler says: 'Error: cannot implicitly convert expression of type extern (C) bool delegate(const(short*) a, ulong b, void* c) to extern (C) bool

Re: Eliding of slice range checking

2019-10-25 Thread Stefan Koch via Digitalmars-d-learn
On Wednesday, 23 October 2019 at 12:01:47 UTC, Per Nordlöw wrote: On Wednesday, 23 October 2019 at 11:33:56 UTC, kinke wrote: For your example, the template is inferred to be @safe, and `-release` only elides bounds checks in @system functions (corresponding to `-boundscheck=safeonly`). Use

Re: x64 ABI

2019-10-14 Thread Stefan Koch via Digitalmars-d-learn
On Monday, 14 October 2019 at 16:02:28 UTC, Marcel wrote: It appears that the ABI specification only describes the register convention for x86. Where can I find which registers get preserved across function calls for 64-bit targets? It's the same as c++.

Re: initialize float4 (core.simd)

2019-09-21 Thread Stefan Koch via Digitalmars-d-learn
On Saturday, 21 September 2019 at 13:42:09 UTC, Bogdan wrote: Well, this seems to be working: float[4] doSimd(float[4] values, float delta) { float4 v_delta = delta; float4 v_values = __simd(XMM.ADDPS, __simd(XMM.LODAPS, values[0]),

Re: Why are extern(C/C++) definitions and references mangled differently in separately compiled modules?

2019-09-06 Thread Stefan Koch via Digitalmars-d-learn
On Friday, 6 September 2019 at 15:09:22 UTC, Max Samukha wrote: Consider the following two modules: 1. test.d: module test; import lib.a; void main() { foo(); } 2. lib/a.d: module lib.a; extern(C) void foo() {} When compiled separately (dmd -c lib/a.d; dmd test.d a.o), the

Re: D1 code to D2I

2019-08-22 Thread Stefan Koch via Digitalmars-d-learn
On Thursday, 22 August 2019 at 18:10:51 UTC, jicman wrote: Greetings! Is there any tool out there, I searched around and didn't find any, that would take ton of D1 code and convert it to D2? Thanks. josé There is: https://github.com/sociomantic-tsunami/d1to2fix It might be please ask

Re: Slow UDF call?

2019-08-17 Thread Stefan Koch via Digitalmars-d-learn
On Saturday, 17 August 2019 at 19:43:22 UTC, Giovanni Di Maria wrote: Hi, i have seen that a simple operation (in a loop) is faster than the equivalent UDF. The first example takes 4 seconds, the second example takes 16 seconds. Local variables influence the speed of execution? Thank you very

Re: Manipulating alias sequences

2019-07-15 Thread Stefan Koch via Digitalmars-d-learn
On Monday, 15 July 2019 at 13:40:29 UTC, Ben Ogles wrote: I have written a simple function that can call another function over integral types with random arguments: [...] You cannot. meta-programming and compile-time evaluation are supposed to be deterministic, and hence cannot take random

Re: Windows segfault, need brief help

2019-07-12 Thread Stefan Koch via Digitalmars-d-learn
On Friday, 12 July 2019 at 22:46:11 UTC, Anonymouse wrote: I'm suddenly getting segfaults when running tests on Windows. It works fine on Linux. I reduced it to a few lines (plus a dependency) with dustmite, but they don't really make sense[1]. Nevertheless they do trigger the segfault. Can

Re: Does -profile need the D runtime?

2019-05-18 Thread Stefan Koch via Digitalmars-d-learn
On Saturday, 18 May 2019 at 16:35:44 UTC, Robert M. Münch wrote: I want to profile my windows app which has a WinMain(). One of the first statements in WinMain() within a try{} is: Runtime.initialize(); But when I compile my app with -profile, it crashes on entry of WinMain(). Looks like

Re: Creating a RedBlackTree

2019-05-15 Thread Stefan Koch via Digitalmars-d-learn
On Wednesday, 15 May 2019 at 13:08:18 UTC, Bogdan wrote: I don't have any experience with using templates. Is it possible to create a RB tree containing structs, where the nodes are ordered by one struct member? ``` import std.stdio; import std.container; enum KeyID: uint { KEY_A,

Re: CTFE in imported static initializers

2019-05-14 Thread Stefan Koch via Digitalmars-d-learn
On Tuesday, 14 May 2019 at 08:26:41 UTC, Steven Schveighoffer wrote: On 5/13/19 9:39 PM, Steven Schveighoffer wrote: Does anyone have a good answer for why this should happen, or should I file a bug? It's been mentioned to me that type inference is used here. However, one could argue that

Re: CTFE sort of tuples

2019-05-02 Thread Stefan Koch via Digitalmars-d-learn
On Thursday, 2 May 2019 at 02:54:03 UTC, Andrey wrote: Hello, I have got this code: [...] I want to sort array of tuples using "data" element in CTFE. But this code give me errors: [...] As I understand the function "sort" sometimes can't be run at CT because of reinterpreting cast.

Re: alias fails to compile

2019-04-22 Thread Stefan Koch via Digitalmars-d-learn
On Monday, 22 April 2019 at 08:02:06 UTC, Arun Chandrasekaran wrote: What am I doing wrong here? struct A { union B { int bb; } B b; alias aa = B.bb; } void main() { A a = A(); // a.b.bb = 4; // works a.aa = 4; // fails } https://run.dlang.io/is/kXaVy2

Re: Poor regex performance?

2019-04-04 Thread Stefan Koch via Digitalmars-d-learn
On Thursday, 4 April 2019 at 10:31:43 UTC, Julian wrote: On Thursday, 4 April 2019 at 09:57:26 UTC, rikki cattermole wrote: If you need performance use ldc not dmd (assumed). LLVM has many factors better code optimizes than dmd does. Thanks! I already had dmd installed from a brief look at D

Re: Build an alias array

2019-04-02 Thread Stefan Koch via Digitalmars-d-learn
On Tuesday, 2 April 2019 at 03:15:36 UTC, Alex wrote: Is there any way to build an alias array at compile time that isn't too heavy in resources? {...} Hi Alex, I agree that there should be a way to do that. As soon as newCTFE is a releasable state, I'll work on that again :) I'd be

Re: Why is my @pure function @system when placed in a struct?

2019-02-27 Thread Stefan Koch via Digitalmars-d-learn
On Wednesday, 27 February 2019 at 17:23:21 UTC, Q. Schroll wrote: I have a template function `fImpl` I whish to instantiate manually using the new name `f`. Reason is simple: `f` should not be a template, but overloading it makes it easier that way. Nothing's more simple in D: [...] the

Re: How does Rebindable suppress the compiler's optimizations for immutable?

2019-02-14 Thread Stefan Koch via Digitalmars-d-learn
On Thursday, 14 February 2019 at 23:55:18 UTC, SimonN wrote: std.typecons.Rebindable!(immutable A) is implemented as: private union { immutable(A) original; A stripped; } ...@trusted assignment operators... @property inout(immutable(A)) get() @trusted pure

Re: How to ensure string compatibility In D?

2019-01-22 Thread Stefan Koch via Digitalmars-d-learn
On Tuesday, 22 January 2019 at 16:47:45 UTC, FrankLike wrote: On Tuesday, 22 January 2019 at 16:18:17 UTC, Adam D. Ruppe wrote: Use "mystring"w, notice the w after the closing quote. Or toStringz is not work like c_str() in C++? stringz creates a char* but you need a wchar*

Re: Pass reference to void*

2019-01-09 Thread Stefan Koch via Digitalmars-d-learn
On Monday, 7 January 2019 at 13:15:44 UTC, Andre Pany wrote: On Monday, 7 January 2019 at 13:01:57 UTC, Stefan Koch wrote: On Monday, 7 January 2019 at 12:19:57 UTC, Andre Pany wrote: [...] From the function declaration seems to be the correct thing to use here. Have you checked that Open

Re: Pass reference to void*

2019-01-07 Thread Stefan Koch via Digitalmars-d-learn
On Monday, 7 January 2019 at 12:19:57 UTC, Andre Pany wrote: Hi, I call a C function from a dll (SO on linux). While the following code works fine for DMD on windows, there are strange errors for LDC on windows. Also the equivalent code does not work for DMD/LDC on linux. (When calling other

Re: Converting an integer to a string with std.format.

2019-01-07 Thread Stefan Koch via Digitalmars-d-learn
On Sunday, 6 January 2019 at 21:53:31 UTC, Per Nordlöw wrote: When converting a single integer to a string is `formatValue` preferred over `formattedWrite` in terms of compilation and run-time performance? I've written my own itos function because using std.conv was too expensive. see

Re: Compile time opAssign/@property constraints

2019-01-04 Thread Stefan Koch via Digitalmars-d-learn
On Friday, 4 January 2019 at 11:45:24 UTC, Jacob Shtokolov wrote: On Friday, 4 January 2019 at 10:34:07 UTC, Basile.B wrote: Show us some code. Here is the simple example: https://run.dlang.io/gist/1a06dd703bea5548ee72b4713a7ce5f6 The thing I'm trying to do is to make an experimental port

Re: Checking if CTFE is used?

2018-12-18 Thread Stefan Koch via Digitalmars-d-learn
On Tuesday, 18 December 2018 at 12:21:44 UTC, berni wrote: Is there a way to check if a function is indeed executed at compile time or not? (Other than going through the whole executable binaries...) I tried static this() { if (__ctfe) pragma(msg,"works"); // some other stuff } but

Re: D is supposed to compile fast.

2018-11-26 Thread Stefan Koch via Digitalmars-d-learn
On Friday, 23 November 2018 at 08:57:57 UTC, Chris Katko wrote: Any time I see people mention the benefits of D, I see "compile times" "compile times" "compile times" over and over. I'm using very modest amounts of templates, for a fairly small sized program (very early work toward a game),

Re: D is supposed to compile fast.

2018-11-23 Thread Stefan Koch via Digitalmars-d-learn
On Friday, 23 November 2018 at 08:57:57 UTC, Chris Katko wrote: Any time I see people mention the benefits of D, I see "compile times" "compile times" "compile times" over and over. [...] If you can share the code privately I can use my custom profiling build of dmd to analyze the problem.

Re: Why does nobody seem to think that `null` is a serious problem in D?

2018-11-22 Thread Stefan Koch via Digitalmars-d-learn
On Thursday, 22 November 2018 at 15:38:18 UTC, Per Nordlöw wrote: The natural way forward for D is to add static analysis in the compiler that tracks use of possibly uninitialized classes (and perhaps also pointers). This has been discussed many times on the forums. The important thing with

Re: Why does nobody seem to think that `null` is a serious problem in D?

2018-11-21 Thread Stefan Koch via Digitalmars-d-learn
On Wednesday, 21 November 2018 at 10:47:35 UTC, NoMoreBugs wrote: On Monday, 19 November 2018 at 21:39:22 UTC, Adam D. Ruppe wrote: On Monday, 19 November 2018 at 21:23:31 UTC, Jordi Gutiérrez Hermoso wrote: What's the reasoning for allowing this? The mistake is immediately obvious when you

Re: how do I activate contracts for phobos functions in dmd

2018-11-02 Thread Stefan Koch via Digitalmars-d-learn
On Friday, 2 November 2018 at 14:10:35 UTC, Richard Palme wrote: My guess is that I have to build phobos with: $make -f posix.mak BUILD=debug but then what do I do next? I'm using Linux and I built dmd+phobos manually by following this guide: https://wiki.dlang.org/Building_under_Posix

Re: CT BitArray

2018-10-31 Thread Stefan Koch via Digitalmars-d-learn
On Wednesday, 31 October 2018 at 23:14:08 UTC, Bastiaan Veelo wrote: Currently, BitArray is not usable at compile time, so you cannot do ``` enum e = BitArray([1, 1, 1, 0]); ``` This gives /dlang/dmd/linux/bin64/../../src/phobos/std/bitmanip.d(1190): Error: `bts` cannot be interpreted at

Re: x64 Privileged instruction

2018-09-12 Thread Stefan Koch via Digitalmars-d-learn
On Wednesday, 12 September 2018 at 10:42:08 UTC, Josphe Brigmo wrote: x64 gives Privileged instruction but x86 gives First-chance exception: std.file.FileException "C:\": The filename, directory name, or volume label syntax is incorrect. at std\file.d(4573) which is much more

Re: Structures and CTFE

2018-09-03 Thread Stefan Koch via Digitalmars-d-learn
On Monday, 3 September 2018 at 15:08:57 UTC, agorkvmh wrote: On Monday, 3 September 2018 at 15:00:33 UTC, Alex wrote: On Monday, 3 September 2018 at 14:00:23 UTC, agorkvmh wrote: [...] Yes. Put a pragma where you static assert for Foo(1).pos equality with 2: [...] Thanks, by the way,

Re: Prime number

2018-08-02 Thread Stefan Koch via Digitalmars-d-learn
On Thursday, 2 August 2018 at 08:30:05 UTC, Greatsam4sure wrote: I know D is very powerful from my little experience. What is the idiomatic way to get prime numbers say from 1-30 without using loops(outer and inner loop). Can map, filter, fold etc in algorithm be use. Pls show some code with

Re: extern(C++): Unresolved scalar deleting destructor

2018-07-24 Thread Stefan Koch via Digitalmars-d-learn
On Tuesday, 24 July 2018 at 15:48:28 UTC, Vladimir Marchevsky wrote: After reading 2.081 patchnotes about improvements with binding to cpp classes, I'm trying to test it - with simple examples and Qt as cpp library. My naive approach is to bind just a couple of used methods of specific

Re: turn range into tuple ?

2018-06-28 Thread Stefan Koch via Digitalmars-d-learn
On Thursday, 28 June 2018 at 09:26:10 UTC, Flaze07 wrote: On Thursday, 28 June 2018 at 08:52:33 UTC, Simen Kjærås wrote: On Thursday, 28 June 2018 at 08:36:54 UTC, Flaze07 wrote: is there some sort of ways to turn range into tuple ? ( an array preferably ) e.g uint[] arr = [ 10, 20, 30 ];

Re: turn range into tuple ?

2018-06-28 Thread Stefan Koch via Digitalmars-d-learn
On Thursday, 28 June 2018 at 08:36:54 UTC, Flaze07 wrote: is there some sort of ways to turn range into tuple ? ( an array preferably ) e.g uint[] arr = [ 10, 20, 30 ]; auto tup = rangeToTup( arr ); assert( tup[ 0 ] == 10 ); assert( tup[ 1 ] == 20 ); assert( tup[ 2 ] == 30 ); I think you are

Re: alias symbol name

2018-06-26 Thread Stefan Koch via Digitalmars-d-learn
On Tuesday, 26 June 2018 at 09:14:11 UTC, Radu wrote: Consider this https://run.dlang.io/is/HyY2qG --- void main() { import std.traits; size_t s; pragma(msg, typeof(s).stringof); pragma(msg, mangledName!(typeof(s))); pragma(msg, mangledName!s); } --- It outputs: --- ulong

Re: Determine if CTFE or RT

2018-06-24 Thread Stefan Koch via Digitalmars-d-learn
On Sunday, 24 June 2018 at 18:21:09 UTC, rjframe wrote: On Sun, 24 Jun 2018 14:43:09 +, Mr.Bingo wrote: let is(CTFE == x) mean that x is a compile time constant. CTFE(x) converts a x to this compile time constant. Passing any compile time constant essentially turns the variable in to a

Re: Debugging compile time memory usage

2018-06-24 Thread Stefan Koch via Digitalmars-d-learn
On Sunday, 24 June 2018 at 14:16:26 UTC, Kamil Koczurek wrote: I recently wrote a brainfuck compiler in D, which loads the BF source at compile time, performs some (simple) optimizations, translates everything to D and puts it into the source code with a mixin. I did manage to get some

Re: Move and CTFE

2018-06-21 Thread Stefan Koch via Digitalmars-d-learn
On Wednesday, 30 May 2018 at 23:07:26 UTC, Jonathan M Davis wrote: newCTFE is taking a very different approach to CTFE, and in theory, it will fix many of the problems that CTFE currently has, but it's taking Stefan quite a while to get it to where it needs to be to actually merge it. To

Re: How can I enforce an parameter to be constant know at compile time?

2018-06-12 Thread Stefan Koch via Digitalmars-d-learn
On Tuesday, 12 June 2018 at 18:27:17 UTC, Dr.No wrote: I'd like help of compiler to check this: consider this: int f(int n) { m_n = n; } f(10); // ok f(myTampleteFunction!(compileTimeParameter)); // ok enum n = 10; f(n); // I won't use this, but should also be ok int x = 10; f(x); // error

Re: WTF! new in class is static?!?!

2018-06-07 Thread Stefan Koch via Digitalmars-d-learn
On Thursday, 7 June 2018 at 21:07:26 UTC, DigitalDesigns wrote: class A; class B { A a = new A(); } auto b1 = new B(); auto b2 = new B(); assert(b1.a == b2.a)!! I'm glad I finally found this out! This is not typical behavior in most languages is it? I'd expect it to be translated to

Re: Confusion/trying to understand CTFE keywords

2018-06-05 Thread Stefan Koch via Digitalmars-d-learn
On Tuesday, 5 June 2018 at 18:00:05 UTC, Steven Schveighoffer wrote: No, it's definitely a bug. main is not being evaluated at compile time. The real result of this function should be a compile-time error -- __ctfe is a *runtime* value that is always defined based on whether you are __ctfe

Re: Confusion/trying to understand CTFE keywords

2018-06-05 Thread Stefan Koch via Digitalmars-d-learn
On Tuesday, 5 June 2018 at 13:27:35 UTC, Steven Schveighoffer wrote: On 6/5/18 6:40 AM, Simen Kjærås wrote: On Tuesday, 5 June 2018 at 09:36:22 UTC, Gopan wrote: void main() {     immutable n = __ctfe ? 1 : 2;     int[n] a;     assert(a.length == n); // fails, wat } That's gotta be a bug -

Re: Deserialize json on runtime type with vibed

2018-05-13 Thread Stefan Koch via Digitalmars-d-learn
On Saturday, 12 May 2018 at 20:23:27 UTC, boolangery wrote: Hi, I want to do something like that: The user first register some type associated to a string and a callback registerHandler!Foo("foo", (res) { info("message received"); }); I want the callback to be called when a json packet

Re: Concatenate strings at compile-time

2018-05-02 Thread Stefan Koch via Digitalmars-d-learn
On Wednesday, 2 May 2018 at 12:38:25 UTC, Jonathan M. Wilbur wrote: I have a method that cannot be @nogc only because it concatenates strings for a long exception message, as seen below. throw new ASN1ValuePaddingException ( "This exception was thrown

Re: cast const pointer to non-const and change value yields neither result nor error

2018-04-30 Thread Stefan Koch via Digitalmars-d-learn
On Monday, 30 April 2018 at 12:35:06 UTC, Timoses wrote: Hey, reading through https://dlang.org/articles/const-faq.html and experimenting a bit: ``` immutable int i = 3; const(int)* p = int* q = cast(int*)p; assert(q == p && p == ); writeln(i); // 3 *q = 1; //

Re: Using an external Assembler with D

2018-04-26 Thread Stefan Koch via Digitalmars-d-learn
On Wednesday, 25 April 2018 at 20:31:46 UTC, solidstate1991 wrote: On Wednesday, 25 April 2018 at 15:25:42 UTC, Stefan Koch wrote: Pass stuff on the stack ;) and use extern (C) functions. Thanks! What about extern (D)? Is there a big chaos in the D ABI under x86? I think the D abi is not

Re: Using an external Assembler with D

2018-04-25 Thread Stefan Koch via Digitalmars-d-learn
On Tuesday, 24 April 2018 at 21:02:07 UTC, solidstate1991 wrote: In order to make one of my own code more readable (and hopefully to avoid a lot of compiling errors under LDC, which don't happen in DMD for some reason), I'm planning to put my assembly functions into separate files for each

Re: Rotate array in writefln?

2018-04-18 Thread Stefan Koch via Digitalmars-d-learn
On Wednesday, 18 April 2018 at 06:54:29 UTC, Chris Katko wrote: I need to rotate an array by 90 degrees, or have writefln figure that out. I need, say: 0 4 5 6 0 0 0 0 0 0 0 0 0 0 0 0 But it's outputting: 0 0 0 0 4 0 0 0 5 0 0 0 6 0 0 0 int [4][4] data; file.writeln(format("%(%-(%d

Re: How/where to hack DMD to generate docs for string mixed members.

2018-04-15 Thread Stefan Koch via Digitalmars-d-learn
On Sunday, 15 April 2018 at 05:20:31 UTC, 9il wrote: Hey, How/where to hack DMD to generate docs for string mixed members? struct S { mixin(" /// auto bar() {} "); } Best regards, Ilya Yaroshenko hmm you should be able to see docs for string mixins, if not. try using

Re: Source expression passed to a lazy parameter

2018-04-09 Thread Stefan Koch via Digitalmars-d-learn
On Monday, 9 April 2018 at 08:27:50 UTC, Per Nordlöw wrote: Is it possible to get the source expression sent to a lazy function? So that I can implement something like show(Arg)(lazy Arg arg) { writeln(arg.sourceof, arg); } used as show(1+2+3); will print 1+2+3:6 Because of

Re: Does the compiler inline the predicate functions to std.algorithm.sort?

2018-03-18 Thread Stefan Koch via Digitalmars-d-learn
On Sunday, 18 March 2018 at 12:59:06 UTC, tipdbmp wrote: I can't read assembly but it seems to me that it doesn't: https://godbolt.org/g/PCsnPT I think C++'s sort can take a "function object" that can get inlined. Correct it does not get in-lined. Even with -O3 it does not. The reason is

Re: signbit question

2018-03-15 Thread Stefan Koch via Digitalmars-d-learn
On Thursday, 15 March 2018 at 15:28:16 UTC, Miguel L wrote: Why does std.math.signbit only work for floating point types? Is there an analogue function for integer types? what is the best way to compare the sign of a float with the sign of an integer? Thanks in advance integers don't have a

Re: core.stdc.stdlib._compare_fp_t and qsort

2018-03-11 Thread Stefan Koch via Digitalmars-d-learn
On Sunday, 11 March 2018 at 23:12:30 UTC, Joe wrote: I'm getting a compiler error in a qsort() call as follows: qsort(recs, num_recs, (Record *).sizeof, compar); Record is a struct, recs is a fixed array of pointers to Record's and num_recs is a size_t that holds the number of valid

Re: Forwarding arguments through a std.algorithm.map

2018-03-11 Thread Stefan Koch via Digitalmars-d-learn
On Saturday, 10 March 2018 at 20:48:06 UTC, Nordlöw wrote: If I have a function bool f(Rs...)(Rs rs) is it somehow possible to map and forward all its arguments `rs` to another function bool g(Rs...)(Rs rs); through a call to some map-and-forward-like-function `forwardMap` in

Re: Validity of cast(void*)size_t.max

2018-03-05 Thread Stefan Koch via Digitalmars-d-learn
On Monday, 5 March 2018 at 18:04:20 UTC, Nordlöw wrote: On Monday, 5 March 2018 at 16:07:49 UTC, Steven Schveighoffer wrote: No, I mean you call holeKey at *runtime*. Inlined, it's just returning a constant, so it should reduce to a constant. A compile-time constant visible to the optimizer?

Re: Equivalent to Python with Statement

2018-02-27 Thread Stefan Koch via Digitalmars-d-learn
On Tuesday, 27 February 2018 at 16:17:20 UTC, Jonathan wrote: I know Python's `with` statement can be used to have an automatic close action: ``` with open("x.txt") as file: #do something with file #`file.close()` called automatically ``` I know D's `with` statement does

Re: How do I trace that memory error?

2018-02-27 Thread Stefan Koch via Digitalmars-d-learn
On Monday, 26 February 2018 at 18:01:07 UTC, Marc wrote: I've tried both gdb and windbg debugger both it either get a "received signal ?" from gdb or crash the GUI application (windbg). The error is: core.exception.OutOfMemoryError@src\core\exception.d(696): Memory allocation failed How do

Re: Understanding the AST...

2018-02-22 Thread Stefan Koch via Digitalmars-d-learn
On Thursday, 22 February 2018 at 13:21:04 UTC, joe wrote: On Monday, 12 February 2018 at 08:47:58 UTC, RazvanN wrote: [...] Follow up question... Why is *.parent always null? e.g.: extern(C++) class MyVisitor(AST): ParseTimeTransitiveVisitor!AST { override void visit(AST.Import i) {

Re: std.zip size limit of 2 GB?

2018-02-15 Thread Stefan Koch via Digitalmars-d-learn
On Thursday, 15 February 2018 at 11:56:04 UTC, Andre Pany wrote: Hi, I just noticed that std.zip will throw an exception if the source files exceeds 2 GB. I am not sure whether this is a limitation of zip version 20 or a bug. On wikipedia a size limit of 4 GB is mentioned. Should I open an

Re: unable to fork: Cannot allocate memory / core.checkedint / gtkd

2018-02-13 Thread Stefan Koch via Digitalmars-d-learn
On Tuesday, 13 February 2018 at 14:10:44 UTC, number wrote: Ok, thanks for the info. I guess I'll just use printf then for larger enums. To get the same convince you can use. the enumToString from: https://forum.dlang.org/post/pnggoabnnkojdonyz...@forum.dlang.org and writeln the result oft

Re: unable to fork: Cannot allocate memory / core.checkedint / gtkd

2018-02-13 Thread Stefan Koch via Digitalmars-d-learn
On Tuesday, 13 February 2018 at 12:17:31 UTC, number wrote: On Sunday, 11 February 2018 at 15:05:26 UTC, number wrote: On Sunday, 11 February 2018 at 13:17:13 UTC, number wrote: unable to fork: Cannot allocate memory if i comment-out the line.. writeln(GdkKeysyms.GDK_Escape); then it

Re: Interactive Interpreter

2018-02-05 Thread Stefan Koch via Digitalmars-d-learn
On Monday, 5 February 2018 at 19:54:09 UTC, Jiyan wrote: Is there any work for an interactive interpreter for D -maybe just for ctfe-able expressions? It shouldnt be too hard to implement it regarding the fact, that ctfe is kinda doing what an interpreter should do i guess. There is

Re: Getting compiler Segfault

2018-02-04 Thread Stefan Koch via Digitalmars-d-learn
On Sunday, 4 February 2018 at 12:52:22 UTC, Ur@nuz wrote: Getting compiler stack overflow when building my project, but still do not know how to localize piece of code that triggers this bug. Maybe this bug is already registered in bugzilla or someone could give some advice where to dig into?

Re: rdmd main.d leads to Segmentation fault

2018-01-29 Thread Stefan Koch via Digitalmars-d-learn
On Friday, 26 January 2018 at 22:40:29 UTC, Timoses wrote: Hey, simple hello world crashes with segfault: [...] I can not reproduce this.

Re: D generates large assembly for simple function

2018-01-27 Thread Stefan Koch via Digitalmars-d-learn
On Saturday, 27 January 2018 at 19:43:50 UTC, Stefan Koch wrote: On Saturday, 27 January 2018 at 19:42:01 UTC, Matt wrote: Godbolt link: https://godbolt.org/g/t5S976 The actual code is : imul edi, edi mov eax, edi ret The rest is runtime initialization. which you can remove using an

Re: D generates large assembly for simple function

2018-01-27 Thread Stefan Koch via Digitalmars-d-learn
On Saturday, 27 January 2018 at 19:42:01 UTC, Matt wrote: Godbolt link: https://godbolt.org/g/t5S976 The actual code is : imul edi, edi mov eax, edi ret The rest is runtime initialization. which you can remove using an undocumented -betterC switch.

Re: Any sample how to use Sqlite-d?

2018-01-17 Thread Stefan Koch via Digitalmars-d-learn
On Wednesday, 17 January 2018 at 13:36:26 UTC, Marc wrote: I was looking for a library to use SQLite with D, found this (https://code.dlang.org/packages/sqlite-d) but it has no documentation or code example. I looked into files in the source code and wrote this: Database db =

Re: Possible dmd 2.078 regression ?

2018-01-12 Thread Stefan Koch via Digitalmars-d-learn
On Friday, 12 January 2018 at 14:13:22 UTC, Basile B. wrote: I have a simple program that only compiles if the dependency is not pre-compiled as a static library. It worked fine before. Please test this --- if [ ! -d "iz" ]; then git clone https://www.github.com/BBasile/iz.git fi cd

Re: Is old style compile-time foreach redundant?

2018-01-06 Thread Stefan Koch via Digitalmars-d-learn
On Sunday, 7 January 2018 at 01:08:44 UTC, H. S. Teoh wrote: On Sun, Jan 07, 2018 at 12:55:27AM +, Stefan Koch via Digitalmars-d-learn wrote: On Saturday, 6 January 2018 at 23:25:58 UTC, Ali Çehreli wrote: > Is 'static foreach' sufficient for all needs or is there any > value for r

Re: Is old style compile-time foreach redundant?

2018-01-06 Thread Stefan Koch via Digitalmars-d-learn
On Saturday, 6 January 2018 at 23:25:58 UTC, Ali Çehreli wrote: Is 'static foreach' sufficient for all needs or is there any value for regular foreach over compile-time sequences? Code unrelated to the question: import std.stdio; void main() { // Old style compile-time foreach. This

  1   2   3   >