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

Re: Help optimizing UnCompress for gzipped files

2018-01-02 Thread Stefan Koch via Digitalmars-d-learn
On Tuesday, 2 January 2018 at 10:27:11 UTC, Christian Köstlin wrote: Hi all, over the holidays, I played around with processing some gzipped json data. First version was implemented in ruby, but took too long, so I tried, dlang. This was already faster, but not really satisfactory fast. Then

Re: Behavior of joining mapresults

2017-12-20 Thread Stefan Koch via Digitalmars-d-learn
On Wednesday, 20 December 2017 at 15:28:00 UTC, Christian Köstlin wrote: When working with json data files, that we're a little bigger than convenient I stumbled upon a strange behavior with joining of mapresults (I understand that this is more or less flatmap). I mapped inputfiles, to

Re: Question for compiler gurus about compile-time strings

2017-12-09 Thread Stefan Koch via Digitalmars-d-learn
On Saturday, 9 December 2017 at 18:45:18 UTC, Steven Schveighoffer wrote: I was thinking that all strings generated at compile-time have a null-terminator added. But then I thought, wait, maybe that's only specifically for string literals. What is the true answer? If you generate a string,

Re: Basic questions about D lang?

2017-11-28 Thread Stefan Koch via Digitalmars-d-learn
On Tuesday, 28 November 2017 at 13:39:11 UTC, Jayam wrote: Is D language open source? Do this have GUI Desktop application support ? Do this have web api support ? Can we compile our program to multi program ? yes yes some (dlang-ui for example) yes some (vibe.d or arsd) I don't know what you

Re: Tried C++ to D. Wrong result.

2017-11-27 Thread Stefan Koch via Digitalmars-d-learn
On Monday, 27 November 2017 at 14:08:27 UTC, Dmitry wrote: I tried translate C++ programm to D, but result is different. original: https://github.com/urraka/alpha-bleeding/blob/master/src/alpha-bleeding.cpp result (with removed alpha):

Re: Passing this to void *

2017-11-22 Thread Stefan Koch via Digitalmars-d-learn
On Wednesday, 22 November 2017 at 15:23:58 UTC, Tim Hsu wrote: I am afraid what will happen when casting this reference to void * a ref is a ptr. The cast will produce a ptr which is valid as long as the ref is valid.

Re: Passing this to void *

2017-11-22 Thread Stefan Koch via Digitalmars-d-learn
On Wednesday, 22 November 2017 at 15:11:08 UTC, Tim Hsu wrote: On Wednesday, 22 November 2017 at 15:07:54 UTC, Stefan Koch will do. I've tried it in the first place. ... Error: this is not an lvalue In that case casting to void* should be fine.

Re: Passing this to void *

2017-11-22 Thread Stefan Koch via Digitalmars-d-learn
On Wednesday, 22 November 2017 at 15:07:08 UTC, Tim Hsu wrote: I am a C++ game developer and I want to give it a try. It seems "this" in Dlang is a reference instead of pointer. How can I pass it as void *? void foo(void *); class Pizza { public: this() { Pizza newone = this;

Re: partiallyQualifiedName?

2017-10-17 Thread Stefan Koch via Digitalmars-d-learn
On Monday, 16 October 2017 at 23:56:00 UTC, Nicholas Wilson wrote: using fullyQualifiedName [here] (https://github.com/libmir/dcompute/blob/master/source/dcompute/driver/ocl/util.d#L120) leads to a large compilation slowdown, but I only need it to disambiguate up to the module level i.e. so

Re: Choosing between __traits(compiles, { ... } ) and is(typeof( { ... } ))

2017-09-20 Thread Stefan Koch via Digitalmars-d-learn
On Wednesday, 20 September 2017 at 12:01:21 UTC, Nordlöw wrote: When is __traits(compiles, { ... } ) preferred over is(typeof( { ... } )) and vice versa when writing stuff like enum isCopyable(S) = is(typeof( { S foo = S.init; S copy = foo; } )); ? Further, are there cases

Re: Internal error mixing templates and CTFE

2017-09-15 Thread Stefan Koch via Digitalmars-d-learn
On Friday, 15 September 2017 at 05:58:47 UTC, David Bennett wrote: Hi Guys, I've been playing around with CTFE today to see how far I would push it but I'm having an issue appending to an array on a struct in CTFE from a template: [...] are you using ucent ?

Re: Performance Issue

2017-09-05 Thread Stefan Koch via Digitalmars-d-learn
On Tuesday, 5 September 2017 at 09:44:09 UTC, Vino.B wrote: Hi, The below code is consume more memory and slower can you provide your suggestion on how to over come these issues. [...] Much slower then ?

Re: Parse tree node allocator

2017-08-31 Thread Stefan Koch via Digitalmars-d-learn
On Thursday, 31 August 2017 at 15:43:05 UTC, Per Nordlöw wrote: Which allocator is best suited for allocating tree nodes (all of equal size around 40-60 bytes in size) in one shot and then delete them all in one go? My use case is parse trees. Region Allocator.

Re: Remove all blank lines from a file

2017-08-31 Thread Stefan Koch via Digitalmars-d-learn
On Thursday, 31 August 2017 at 14:44:07 UTC, vino wrote: Hi All, Can some provide me a example of how to remove all blank lines from a file. From, Vino.B ubyte[] fileData; ubyte[] writeThis; uint lastP; fileData = readRaw(fileName); foreach(uint p; ubyte b;fileData) { if (b ==

Re: writeln() sometimes double prints from main() if I run a thread checking for input?

2017-08-30 Thread Stefan Koch via Digitalmars-d-learn
On Wednesday, 30 August 2017 at 10:55:20 UTC, Timothy Foster wrote: On Wednesday, 30 August 2017 at 10:44:43 UTC, Ivan Kazmenko wrote: On Wednesday, 30 August 2017 at 10:13:57 UTC, Timothy Foster wrote: I'm not sure if this is a known issue, or if I just don't understand how to use threads,

Re: Tools to help me find memory leaks?

2017-08-23 Thread Stefan Koch via Digitalmars-d-learn
On Wednesday, 23 August 2017 at 17:30:40 UTC, Drake44 wrote: I'm on a Windows 7 machine and I'm using VisualD as my IDE. I'm trying to work out what's chewing up all the RAM in a program I'm writing... is there a tool that I can use that'll show me what in my program keeps allocating memory?

Re: wth!! ctfe cannot format floating point at compile time?

2017-08-14 Thread Stefan Koch via Digitalmars-d-learn
On Monday, 14 August 2017 at 04:29:17 UTC, Johnson wrote: ``` auto valueToString(alias v)(){return v.stringof;} enum a = valueToString!(0.75); static assert(a == "0.75"); ``` Thanks! You'd think that to would do this internally automatically ;/ It only works on literals. valueToString!(a)

Re: rename file, execute os, etc at compile time

2017-08-07 Thread Stefan Koch via Digitalmars-d-learn
On Monday, 7 August 2017 at 00:07:26 UTC, Johnson Jones wrote: On Sunday, 6 August 2017 at 23:11:56 UTC, Nicholas Wilson wrote: On Sunday, 6 August 2017 at 19:56:06 UTC, Johnson Jones wrote: [...] It is deliberately not possible. reproducible builds security ect. have a look at dubs

Re: lambda function with "capture by value"

2017-08-05 Thread Stefan Koch via Digitalmars-d-learn
On Saturday, 5 August 2017 at 18:19:05 UTC, Stefan Koch wrote: On Saturday, 5 August 2017 at 18:17:49 UTC, Simon Bürger wrote: If a lambda function uses a local variable, that variable is captured using a hidden this-pointer. But this capturing is always by reference. Example: int i = 1;

Re: lambda function with "capture by value"

2017-08-05 Thread Stefan Koch via Digitalmars-d-learn
On Saturday, 5 August 2017 at 18:17:49 UTC, Simon Bürger wrote: If a lambda function uses a local variable, that variable is captured using a hidden this-pointer. But this capturing is always by reference. Example: int i = 1; auto dg = (){ writefln("%s", i); }; i = 2; dg(); //

Re: Getting enum from value

2017-08-05 Thread Stefan Koch via Digitalmars-d-learn
On Saturday, 5 August 2017 at 15:33:57 UTC, Matthew Remmel wrote: I feel like I'm missing something, but there has to be an easier way to convert a value into an enum than switching over every possible value: i.e [...] What you want is already in the standard library. std.conv.to can

Re: BigInt foreach loop

2017-08-04 Thread Stefan Koch via Digitalmars-d-learn
On Friday, 4 August 2017 at 13:09:55 UTC, Steven Schveighoffer wrote: Any foreach range statement like this: foreach(var; A .. B) is treated as if you wrote: for(auto var = A; var < B; ++var) So it's pretty much exactly like what you wrote, just the initializer is different but the result

Re: BigInt foreach loop

2017-08-04 Thread Stefan Koch via Digitalmars-d-learn
On Friday, 4 August 2017 at 12:49:30 UTC, Q. Schroll wrote: One can do BigInt n = returnsBigInt(); foreach (i; BigInt(0) .. n) { .. } How is this implemented? The code for BigInt is very large and I didn't find it. And is it more efficient than for (BigInt i = 0; i < n; ++i) { .. }

Re: Can you parse the d source file during compile time with std.regex?

2017-08-01 Thread Stefan Koch via Digitalmars-d-learn
On Tuesday, 1 August 2017 at 16:16:46 UTC, 12345swordy wrote: I don't see this anywhere in the documentation. I am asking this as I want to know that it's possible to create a attribute to prevent certain functions being called in the body of a function. To enforce a certain code standard upon

Re: Specify rhs at initialisation or assignment of typedef' d variable

2017-07-31 Thread Stefan Koch via Digitalmars-d-learn
On Monday, 31 July 2017 at 08:53:10 UTC, Cecil Ward wrote: [ ... ] I suspect that I am asking for something that literally makes no sense at all. I wanted to try and avoid opening the door to allowing the following kind of typing error now, eg enum ip_address = 0x11223344; [ ... ]

Re: Profiling after exit()

2017-07-27 Thread Stefan Koch via Digitalmars-d-learn
On Thursday, 27 July 2017 at 14:30:33 UTC, Eugene Wissner wrote: I have a multi-threaded application, whose threads normally run forever. But I need to profile this program, so I compile the code with -profile, send a SIGTERM and call exit(0) from my signal handler to exit the program. The

Re: Appending static arrays

2017-07-18 Thread Stefan Koch via Digitalmars-d-learn
On Tuesday, 18 July 2017 at 08:46:50 UTC, Jack Applegame wrote: On Monday, 17 July 2017 at 17:38:23 UTC, Nordlöw wrote: I'm want to define a specialization of `append()` that takes only static arrays as inputs and returns a static array being the sum of the lengths of the inputs. Have

Re: How do I cast to from byte[] <-> double for making a small assembler language VM to work?

2017-07-18 Thread Stefan Koch via Digitalmars-d-learn
On Tuesday, 18 July 2017 at 11:06:22 UTC, Enjoys Math wrote: [ ... ] The cast at the bottom gives a compiler error (can't cast byte[] to double). If you want to see how it's done check: https://github.com/UplinkCoder/dmd/blob/newCTFE_on_master/src/ddmd/ctfe/bc.d Though if you have the choice

Re: How do I cast to from byte[] <-> double for making a small assembler language VM to work?

2017-07-18 Thread Stefan Koch via Digitalmars-d-learn
On Tuesday, 18 July 2017 at 11:06:22 UTC, Enjoys Math wrote: class OpCode { private: byte[] bytes_; public: void opCall(Program program) const; byte[] bytes() const { return bytes_.dup; } } class AddD : OpCode { private: uint d, s;

Re: Appending static arrays

2017-07-17 Thread Stefan Koch via Digitalmars-d-learn
On Monday, 17 July 2017 at 18:38:16 UTC, Nordlöw wrote: On Monday, 17 July 2017 at 17:46:42 UTC, ag0aep6g wrote: int[n + m] result = a ~ b; Further, the expression `a ~ b` here will allocate and create a copy on the GC-heap before writing `result`. Maybe LDC optimizes away this now or

Re: Exception handling

2017-07-14 Thread Stefan Koch via Digitalmars-d-learn
On Friday, 14 July 2017 at 23:02:24 UTC, Moritz Maxeiner wrote: On Friday, 14 July 2017 at 21:20:29 UTC, Jonathan M Davis wrote: Basically, the compiler _never_ looks at the bodies of other functions when determining which attributes apply. It always [...]. I'm well aware of that, but it

Re: Silly struct behaviour

2017-07-13 Thread Stefan Koch via Digitalmars-d-learn
On Thursday, 13 July 2017 at 18:45:45 UTC, JN wrote: I know that's a wrong syntax, I was just showing an example. Yes, here it will work, but if you want to initialize only some fields (poor man's keyword arguments), you can't use the default constructor. easily fixable by using

Re: Read from terminal when enter is pressed, but do other stuff in the mean time...

2017-07-13 Thread Stefan Koch via Digitalmars-d-learn
On Thursday, 13 July 2017 at 15:52:57 UTC, Dustmight wrote: How do I read in input from the terminal without sitting there waiting for it? I've got code I want to run while there's no input, and then code I want to act on input when it comes in. How do I do both these things? You have to ask

Re: CTFE output is kind of weired

2017-07-09 Thread Stefan Koch via Digitalmars-d-learn
On Sunday, 9 July 2017 at 04:03:09 UTC, H. S. Teoh wrote: On Sat, Jul 08, 2017 at 03:09:09PM -0700, Ali Çehreli via Digitalmars-d-learn wrote: On 07/08/2017 02:29 PM, Andre Pany wrote: > I use assert(false, tmp) to see the content of variable tmp > as it seems there is no other way in CTFE.

Re: Bulk allocation and partial deallocation for tree data structures.

2017-07-02 Thread Stefan Koch via Digitalmars-d-learn
On Monday, 3 July 2017 at 02:51:49 UTC, Filip Bystricky wrote: Anyone? The answer is no. Partial deallocation in an arbitrary fashion is not advisable. And there are no standard library mechanisms for it.

Re: ReadProcessMemory + address from ollydbg

2017-06-30 Thread Stefan Koch via Digitalmars-d-learn
On Friday, 30 June 2017 at 23:53:19 UTC, bauss wrote: I suspect the address is wrong, but it's the static address I picked up from ollydbg, so I'm kinda lost as for how ollydbg can get the correct string and I get the wrong one using same address. You are aware that processes life in

Re: Get Function Body

2017-06-30 Thread Stefan Koch via Digitalmars-d-learn
On Friday, 30 June 2017 at 16:38:45 UTC, bauss wrote: Is there a way to retrieve the body of a function as a string? Scenario. I want to pass a function to a mixin template and just mixin the body of the function. Ex. mixin template Foo(alias fun) { void bar() {

Re: Force usage of double (instead of higher precision)

2017-06-30 Thread Stefan Koch via Digitalmars-d-learn
On Friday, 30 June 2017 at 16:29:22 UTC, kinke wrote: On Friday, 30 June 2017 at 16:21:18 UTC, kinke wrote: CTFE only (incl. parsing of literals). Just make sure you don't happen to call a std.math function only accepting reals; I don't know how many of those are still around. Oh, apparently

Re: Force usage of double (instead of higher precision)

2017-06-29 Thread Stefan Koch via Digitalmars-d-learn
On Thursday, 29 June 2017 at 12:02:48 UTC, Simon Bürger wrote: On Thursday, 29 June 2017 at 00:07:35 UTC, kinke wrote: On Wednesday, 28 June 2017 at 22:16:48 UTC, Simon Bürger wrote: I am currently using LDC on 64-bit-Linux if that is relevant. It is, as LDC on Windows/MSVC would use 64-bit

Re: Force usage of double (instead of higher precision)

2017-06-28 Thread Stefan Koch via Digitalmars-d-learn
On Wednesday, 28 June 2017 at 23:56:42 UTC, Stefan Koch wrote: As for your problems they can be worked around. by assigning every temporary to a variable. Which will enforce the discarding of precision. Sorry for the misinformation! I was using the newCTFE fork which fixes this. Indeed you'll

Re: Force usage of double (instead of higher precision)

2017-06-28 Thread Stefan Koch via Digitalmars-d-learn
On Wednesday, 28 June 2017 at 22:16:48 UTC, Simon Bürger wrote: (If you are interested in the "double double" type, take a look here: https://github.com/BrianSwift/MetalQD which includes a double-double and even quad-double implementation in C/C++/Fortran) Nice work can you re or dual

Re: Converting a ubyte[] to a struct with respect to endianness?

2017-06-24 Thread Stefan Koch via Digitalmars-d-learn
On Saturday, 24 June 2017 at 02:52:23 UTC, Felix wrote: I'm trying to read in just the first part of a .png file to peek at it's width and height without loading in the whole file. I'm using FreeImage for reading the whole file but since it doesn't have a function to let me peek at the image

Re: What's the fastest way to check if a slice points to static data

2017-06-24 Thread Stefan Koch via Digitalmars-d-learn
On Saturday, 24 June 2017 at 12:22:54 UTC, Petar Kirov [ZombineDev] wrote: [ ... ] /** * Returns: * A pointer to a null-terminated string in O(1) time, * (with regards to the length of the string and the required * memory, if any) or `null` if * the time constraint * can't be met. */

Re: O(1) sum

2017-06-12 Thread Stefan Koch via Digitalmars-d-learn
On Monday, 12 June 2017 at 06:15:07 UTC, Biotronic wrote: On Monday, 12 June 2017 at 01:36:04 UTC, Stefan Koch wrote: On Monday, 12 June 2017 at 01:02:58 UTC, helxi wrote: Is it possible to sum an array in O(1)? No. If you want to sum the elements you have to at-least look at all the

Re: O(1) sum

2017-06-11 Thread Stefan Koch via Digitalmars-d-learn
On Monday, 12 June 2017 at 01:02:58 UTC, helxi wrote: Is it possible to sum an array in O(1)? No. If you want to sum the elements you have to at-least look at all the elements. So it'll always be O(N). it's the best you can do.

Re: D and GDB

2017-06-04 Thread Stefan Koch via Digitalmars-d-learn
On Sunday, 4 June 2017 at 18:13:41 UTC, Russel Winder wrote: On Sun, 2017-06-04 at 20:31 +0300, ketmar via Digitalmars-d-learn wrote: [...] Sadly even using the correct command, I am not getting any data that helps infer what the is going on. :-( [...] My guess is a null pointer :)

Re: Linker cannot find malloc and free on OS X

2017-06-04 Thread Stefan Koch via Digitalmars-d-learn
On Sunday, 4 June 2017 at 10:45:23 UTC, Nordlöw wrote: My gmp-d tests successfully on Linux as dub test but on OS X it fails as Undefined symbols for architecture x86_64: "free", referenced from: ... "malloc", referenced from: ... Any ideas on why?

Re: Strange expression found in std.variant

2017-06-03 Thread Stefan Koch via Digitalmars-d-learn
On Saturday, 3 June 2017 at 16:22:33 UTC, Francis Nixon wrote: When looking at std.variant I found the following line: return q{ static if (allowed!%1$s && T.allowed!%1$s) if (convertsTo!%1$s && other.convertsTo!%1$s) return VariantN(get!%1$s %2$s other.get!%1$s);

Re: Trouble with SList for generic Stack class

2017-06-02 Thread Stefan Koch via Digitalmars-d-learn
On Friday, 2 June 2017 at 22:21:07 UTC, Mark wrote: Hello, I am trying to make a class that can accept any type as an argument. [...] the stack class needs to be a template as well. This is not java ;)

Re: D scripting in D

2017-06-02 Thread Stefan Koch via Digitalmars-d-learn
On Friday, 2 June 2017 at 17:50:30 UTC, H. S. Teoh wrote: On Fri, Jun 02, 2017 at 05:22:20PM +, Stefan Koch via Digitalmars-d-learn wrote: On Friday, 2 June 2017 at 16:13:03 UTC, Laeeth Isharc wrote: > [...] No there is not. First it's woefully incomplete and secondly it's tightly bo

Re: D scripting in D

2017-06-02 Thread Stefan Koch via Digitalmars-d-learn
On Friday, 2 June 2017 at 16:13:03 UTC, Laeeth Isharc wrote: On Friday, 2 June 2017 at 02:06:27 UTC, Mike B Johnson wrote: [...] Stefan Koch has written a good part of an interpreter for D AST, no? And I guess the lexing and parsing stage doesn't take so long, whereas not having to link

Re: D scripting in D

2017-06-01 Thread Stefan Koch via Digitalmars-d-learn
On Friday, 2 June 2017 at 02:32:43 UTC, Mike B Johnson wrote: 1. change test12.wav to test123.wav 2. save file 3. recompile. 4. run 5. Get back to same test point(could be a lot or a little amount of work). If that is all you want; then compile your code into a dll/so and load the new

Re: Creating and loading D plugins in D app

2017-06-01 Thread Stefan Koch via Digitalmars-d-learn
On Thursday, 1 June 2017 at 23:24:13 UTC, aberba wrote: Want to create and load plugins written in D into a D app at run-time, the kind that can make api calls or extended main app with other functionality. I'm currently interested in it for a vibe.d app. How does these stuff work? It

Re: Changing Template Static Ifs to Recursion

2017-05-31 Thread Stefan Koch via Digitalmars-d-learn
On Wednesday, 31 May 2017 at 18:50:27 UTC, jmh530 wrote: I have a struct that I am using like a Tuple, but I want to be able to opIndex in a different way than Tuple's opIndex. I want to be able to opIndex whatever is underlying the Tuple. [...] You could also use string mixins. Which will

Re: purity question

2017-05-28 Thread Stefan Koch via Digitalmars-d-learn
On Monday, 29 May 2017 at 01:01:46 UTC, Stefan Koch wrote: There is void[] myPureMalloc(uint size) pure @trusted nothrow @nogc { import core.stdc.stdlib : malloc; alias pure_malloc_t = @nogc pure nothrow void* function(size_t size); return (cast(pure_malloc_t))(size)[0 .. size]; }

Re: purity question

2017-05-28 Thread Stefan Koch via Digitalmars-d-learn
On Monday, 29 May 2017 at 00:53:25 UTC, Brad Roberts wrote: On 5/28/2017 5:34 PM, Jonathan M Davis via Digitalmars-d-learn wrote: On Sunday, May 28, 2017 16:49:16 Brad Roberts via Digitalmars-d-learn wrote: Is there a mechanism for declaring something pure when it's built from parts which

Re: [Starting with D] d2html.d issues an error

2017-05-25 Thread Stefan Koch via Digitalmars-d-learn
On Thursday, 25 May 2017 at 15:02:33 UTC, Oleksii wrote: Hi everyone, Could you please help me? I'm get the following error from all.sh: $ /e/D/dmd2/windows/bin/shell.exe all.sh shell 1.05 ..\..\windows\bin\dmd d2html d2html.d(18): Error: module stream is in file 'std\stream.d'

Re: C++ binding issues with C++ function returning a simple POD struct.

2017-05-21 Thread Stefan Koch via Digitalmars-d-learn
On Sunday, 21 May 2017 at 19:33:06 UTC, ParticlePeter wrote: I am statically linking to ImGui [1] on Win 10 x64, quite successfully till this issue came up. The noticed error so far comes when an ImGui function returns an ImVec2, a simple POD struct of two float members. I can use this struct

Re: Multiple template variadic list not working

2017-05-21 Thread Stefan Koch via Digitalmars-d-learn
On Sunday, 21 May 2017 at 15:13:55 UTC, bastien penavayre wrote: I've been trying to translate the following idea expressed here in c++: template void func(Arguments... args) {} so I tried void func(UserArgs..., Arguments...)(Arguments args) {} and then void func(Args...)(Filter!(isType,

Re: how to disable inlining of ldc2 when 'dub build --build=release'?

2017-05-20 Thread Stefan Koch via Digitalmars-d-learn
On Saturday, 20 May 2017 at 08:08:38 UTC, Johan Engelen wrote: On Saturday, 20 May 2017 at 08:02:26 UTC, lixiaozi wrote: [...] I noticed it's the inline optimization in ldc2 that caused the crash. If you are certain that your code is 100% correct, please file a bug report. Inlining is done

Re: Code improvement for DNA reverse complement?

2017-05-19 Thread Stefan Koch via Digitalmars-d-learn
On Friday, 19 May 2017 at 07:29:44 UTC, biocyberman wrote: I am solving this problem http://rosalind.info/problems/revc/ as an exercise to learn D. This is my solution: https://dpaste.dzfl.pl/8aa667f962b7 Is there some D tricks I can use to make the `reverseComplement` function more concise

Re: struct File. property size.

2017-05-11 Thread Stefan Koch via Digitalmars-d-learn
On Thursday, 11 May 2017 at 07:24:00 UTC, AntonSotov wrote: import std.stdio; int main() { auto big = File("bigfile", "r+"); //bigfile size 20 GB writeln(big.size); // ERROR! return 0; } // std.exception.ErrnoException@std\stdio.d(1029): Could

Re: Lookahead in unittest

2017-05-10 Thread Stefan Koch via Digitalmars-d-learn
On Wednesday, 10 May 2017 at 16:09:06 UTC, Raiderium wrote: Heyo, On 2.074.0, the following test fails with "Error: undefined identifier 'B' " unittest { class A { B b; } class B { } } I can't figure out if this is intended behaviour. It's making a template-heavy module

Re: Problems with Array Assignment?

2017-05-10 Thread Stefan Koch via Digitalmars-d-learn
On Wednesday, 10 May 2017 at 13:34:30 UTC, Samwise wrote: I'm really sure this is just a stupid mistake I made, but I can't for the life of me figure out what is going on. Basically I'm trying to assign a reference to an object to an array, and the objects exist (an explicit destructor is

Re: Structure of platform specific vs non platform specific code

2017-05-09 Thread Stefan Koch via Digitalmars-d-learn
On Tuesday, 9 May 2017 at 15:28:20 UTC, WhatMeWorry wrote: On Monday, 8 May 2017 at 21:16:53 UTC, Igor wrote: Hi, I am following Casey Muratori's Handmade Hero and writing it in DLang. This sounds very interesting. Maybe make it a public github project? It can only accessible for those

Re: Transitive bit-packing of fields

2017-04-30 Thread Stefan Koch via Digitalmars-d-learn
On Sunday, 30 April 2017 at 11:02:52 UTC, Nordlöw wrote: Have anybody found a way to do transitive packing of bitfields? For instance, in import std.bitmanip : bitfields; struct X { // one bit too many to fit in one byte mixin(bitfields!(bool, `a`, 1, bool, `b`,

Re: typeof(this) return wrong type

2017-04-22 Thread Stefan Koch via Digitalmars-d-learn
On Saturday, 22 April 2017 at 11:33:22 UTC, Andrey wrote: Hello, I trying to add custom attribute OnClickListener, the problem is that typeof always return BaseView type instead of MyView. struct OnClickListener { string id; } class BaseView { void onCreate() {

Re: Generating switch at Compile Time

2017-04-17 Thread Stefan Koch via Digitalmars-d-learn
On Thursday, 13 April 2017 at 21:06:52 UTC, Jesse Phillips wrote: I realize that this is likely really pushing the compile time generation but a recent change to the switch statement[1] is surfacing because of this usage. uninitswitch2.d(13): Deprecation: 'switch' skips declaration of

Re: Duplicated functions not reported?

2017-04-16 Thread Stefan Koch via Digitalmars-d-learn
On Sunday, 16 April 2017 at 17:10:14 UTC, Temtaime wrote: On Sunday, 16 April 2017 at 15:54:16 UTC, Stefan Koch wrote: On Sunday, 16 April 2017 at 10:56:37 UTC, Era Scarecrow wrote: On Saturday, 15 April 2017 at 11:10:01 UTC, Stefan Koch wrote: It would requires an O(n^2) check per

Re: Duplicated functions not reported?

2017-04-16 Thread Stefan Koch via Digitalmars-d-learn
On Sunday, 16 April 2017 at 10:56:37 UTC, Era Scarecrow wrote: On Saturday, 15 April 2017 at 11:10:01 UTC, Stefan Koch wrote: It would requires an O(n^2) check per declaration. Even it is never used. which would make imports that much more expensive. Seems wrong to me... If you made a

Re: Strange stack variable corruption error after calling extern(C) function

2017-04-16 Thread Stefan Koch via Digitalmars-d-learn
On Sunday, 16 April 2017 at 08:34:12 UTC, cc wrote: All this with extern(Windows) rather than extern(C) by the way. Why not use loadLibraryA ? then all the problems go away :) this is how derelict does it as well.

Re: Duplicated functions not reported?

2017-04-15 Thread Stefan Koch via Digitalmars-d-learn
On Saturday, 15 April 2017 at 09:17:08 UTC, Jacob Carlborg wrote: I'm not sure if I'm missing something obvious here, but the following code compiles and runs: void foo() {} void foo() {} void main() {} Although if I do call "foo", the compiler will complain that it matches both versions of

Re: Deduplicating template reflection code

2017-04-14 Thread Stefan Koch via Digitalmars-d-learn
On Friday, 14 April 2017 at 08:24:00 UTC, Johannes Pfau wrote: I've got this code duplicated in quite some functions: - foreach (member; __traits(derivedMembers, API)) { // Guards against private members static if (__traits(compiles, __traits(getMember, API,

Re: ctfe append too slow, but can't speed up

2017-04-12 Thread Stefan Koch via Digitalmars-d-learn
On Tuesday, 11 April 2017 at 02:20:37 UTC, Jethro wrote: ctfe string appending is way to slow, I have tried the suggested methods and nothing works and slows down by at least an order of magnitude. I need a drop in replacement(no other changes) that can take over the duties of string and

Re: CTFE using of replaceAll from std.regex posible?

2017-04-12 Thread Stefan Koch via Digitalmars-d-learn
On Wednesday, 12 April 2017 at 12:00:27 UTC, Martin Tschierschke wrote: It there a way to use "replaceAll" at compile time? Regards mt. Not yet :) I assume it would bring the current system to it's needs. I you want to experiment you could replace malloc with new.

Re: Strange CTFE issue, string replacement

2017-04-09 Thread Stefan Koch via Digitalmars-d-learn
On Sunday, 9 April 2017 at 20:20:55 UTC, Jethro wrote: On Sunday, 9 April 2017 at 19:55:57 UTC, Stefan Koch wrote: On Sunday, 9 April 2017 at 19:38:33 UTC, Jethro wrote: [...] The constructor is nuts. You do not need to zero the string! Also avoid templates if you can. Please don't

Re: Strange CTFE issue, string replacement

2017-04-09 Thread Stefan Koch via Digitalmars-d-learn
On Sunday, 9 April 2017 at 19:38:33 UTC, Jethro wrote: I tried to make a string like replacement called fstring which uses buffering to avoid lots of little allocations. The problem is, that it actually causes the compiler to use 10x the memory and about 10 times slower. It doesn't do

Re: -fPIC and 32-bit dmd.conf settings

2017-04-09 Thread Stefan Koch via Digitalmars-d-learn
On Sunday, 9 April 2017 at 09:23:07 UTC, Joseph Rushton Wakeling wrote: Thanks for the explanation. TBH I find myself wondering whether `-fPIC` should be in the flags defined in dmd.conf _at all_ (even for 64-bit environments); surely that should be on request of individual project builds

Re: Does the CTFE engine reuse variables?

2017-04-09 Thread Stefan Koch via Digitalmars-d-learn
On Sunday, 9 April 2017 at 05:42:02 UTC, Jethro wrote: Suppose one has a function that will be used in CTFE and it uses a lot of local variables. Does each call of the function end up allocating space for these without ever releasing them or are they reused? or used on the stack like normal?

Re: Spreading D Arrays

2017-04-06 Thread Stefan Koch via Digitalmars-d-learn
On Thursday, 6 April 2017 at 18:25:27 UTC, Russel Winder wrote: Many languages have a "spread" operator which takes a sequence and creates positional argument to a (usually variadic but not necessarily) function. Does D have such a facility? (Such a facility looks like it might be really,

Re: Single exe vibe.d app

2017-04-06 Thread Stefan Koch via Digitalmars-d-learn
On Wednesday, 5 April 2017 at 12:13:38 UTC, Satoshi wrote: Hi, How can I build single exe application with vibe.d (windows)? now it require zlib.dll, libeay32.dll and ssleay32.dll But I need it as single app. One solution would be to compile vibe.d without ssl support that way it will not

<    1   2   3   4   >