Re: Challenge: Make a data type for holding one of 8 directions allowing increment and overflow

2024-03-15 Thread Daniel N via Digitalmars-d-learn
On Tuesday, 12 March 2024 at 05:38:03 UTC, Liam McGillivray wrote: I am in need of a data type for holding direction information; one of 8 directions on a single axis. They are named in terms of compass directions. If D had a 4-bit datatype, I would just use this and do `+=2` whenever I want

Re: gdc or ldc for faster programs?

2022-01-25 Thread Daniel N via Digitalmars-d-learn
On Tuesday, 25 January 2022 at 20:04:04 UTC, Adam D Ruppe wrote: On Tuesday, 25 January 2022 at 19:52:17 UTC, Ali Çehreli wrote: ldc: ~0.95 seconds gdc: ~0.79 seconds dmd: ~1.77 seconds Maybe you can try --ffast-math on ldc.

Re: Trying to reduce memory usage

2021-02-13 Thread Daniel N via Digitalmars-d-learn
On Saturday, 13 February 2021 at 04:19:17 UTC, Ali Çehreli wrote: On 2/11/21 6:22 PM, H. S. Teoh wrote: >bool[size_t] hashes; I would start with an even simpler solution until it's proven that there still is a memory issue: import std.stdio; void main() { bool[string] lines;

Re: Is garbage detection a thing?

2020-11-29 Thread Daniel N via Digitalmars-d-learn
On Sunday, 29 November 2020 at 16:35:26 UTC, Mark wrote: Maybe I should just install Linux. But ... the drivers... My Thinkpad just doesn't like any Linux. I run out of ideas. In the first place all I wanted to do is make some music. Kind regards You could try a linux image in VirtualBox

Re: Is garbage detection a thing?

2020-11-29 Thread Daniel N via Digitalmars-d-learn
On Sunday, 29 November 2020 at 16:05:04 UTC, Mark wrote: Thanks a lot for reading, and sorry for a lot of text that is off-topic and is not related to D. Sounds like what you want is ASAN? You can use it with plain C or D(LDC). https://clang.llvm.org/docs/AddressSanitizer.html

Re: Run code before dub dependency's `shared static this()`

2019-05-05 Thread Daniel N via Digitalmars-d-learn
On Sunday, 5 May 2019 at 08:24:29 UTC, Vladimirs Nordholm wrote: Hello. I have dub dependency which has a `shared static this()`. In my project, can I run code code before the dependency's `shared static this()`? This might work: pragma(crt_constructor) extern(C) void early_init() { }

Re: bug in doc?

2019-03-14 Thread Daniel N via Digitalmars-d-learn
On Thursday, 14 March 2019 at 14:47:18 UTC, Adam D. Ruppe wrote: On Thursday, 14 March 2019 at 14:22:52 UTC, spir wrote: https://dlang.org/spec/hash-map.html#static_initialization: Well, bug in implementation. That is *supposed* to work, but the compiler never implemented it. The docs

Re: Benchmarking sigmoid function between C and D

2018-04-07 Thread Daniel N via Digitalmars-d-learn
On Saturday, 7 April 2018 at 18:53:57 UTC, Arun Chandrasekaran wrote: What am I doing wrong here that makes the D equivalent 2.5 times slower than it's C equivalent? Compilers used: LDC2: LDC - the LLVM D compiler (1.8.0) GCC: gcc (Ubuntu 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609 11:36:39

Re: Looking for an equivalent to C++ std::getline in D

2017-05-08 Thread Daniel N via Digitalmars-d-learn
On Monday, 8 May 2017 at 10:51:52 UTC, Ola Fosheim Grøstad wrote: On Sunday, 7 May 2017 at 20:50:10 UTC, Patrick Schluter wrote: If you look on TIOBE [1] newest stats, D does not look so bad after all. It's ranked 23 with a 1.38% share. The so Tiobe is a "hoax". Stack overflow counts for

Re: Mixin template confusion / compiler error.

2017-01-19 Thread Daniel N via Digitalmars-d-learn
On Thursday, 19 January 2017 at 08:41:53 UTC, Chris Katko wrote: Thank you! So: 1 - Is there any way TO get the output 64,64? Would this work for you? import std.meta; alias sizer1D = AliasSeq!(64); alias sizer2D = AliasSeq!(64,64); array_t!sizer2D caseX; array2_t!sizer1D caseY;

Re: Using Dub

2017-01-15 Thread Daniel N via Digitalmars-d-learn
On Sunday, 15 January 2017 at 13:23:25 UTC, Russel Winder wrote: Is there any way of setting dub to default to ldc2 rather than dmd as the compiler of use? (I do not want to have to put --compiler ldc2 on every dub command.) I have never used dub, but I know it's now also bundled with ldc2.

Re: BetterC classes

2016-12-16 Thread Daniel N via Digitalmars-d-learn
On Friday, 16 December 2016 at 15:17:15 UTC, Ilya Yaroshenko wrote: Hi Is it possible to use classes, which do not have monitor and other DRuntime stuff? Object can be allocated/deallocated using allocators, but they are very complex for betterC mode (monitor, mutex, object.d dependency).

struct to json/yaml/xml/whatever codegen

2016-09-29 Thread Daniel N via Digitalmars-d-learn
Is anyone aware of a tool which does something akin to the following: Given a C-like definition, automatically generate pure C code with no dependencies. Input c-struct: struct Person { int id; char* name; } Output minimal c-code: void dumpPerson(Person* p) {

Re: Is there a way to make a class variable visible but constant to outsiders, but changeable (mutable) to the class itself?

2016-05-22 Thread Daniel N via Digitalmars-d-learn
On Saturday, 21 May 2016 at 17:32:47 UTC, dan wrote: Is it possible to have a class which has a variable which can be seen from the outside, but which can only be modified from the inside? Something like: class C { int my_var = 3; // semi_const?? void do_something() { my_var = 4; } }

Re: Is this template constraint a bug?

2016-05-12 Thread Daniel N via Digitalmars-d-learn
On Thursday, 12 May 2016 at 15:33:24 UTC, Eric wrote: is(T : A!T) tells if T can automatically be converted to A!T. The last line below is doing just that, yet the template constraint does not work. class A(T) if (is(T : A!T)) { } Yes, it's a bug. Please file an issue. Meanwhile try

Re: mixed-in ctor not on par with explicit one?

2016-01-13 Thread Daniel N via Digitalmars-d-learn
On Wednesday, 13 January 2016 at 12:39:36 UTC, Jacob Carlborg wrote: On 2016-01-13 10:48, Shriramana Sharma wrote: This is not what alias <> this is supposed to do, right? No. So how am I supposed to get the mixed in ctors work? Looks like a limitation in the language. This works:

Re: Capturing __FILE__ and __LINE in a variadic templated function

2015-11-02 Thread Daniel N via Digitalmars-d-learn
On Monday, 2 November 2015 at 09:54:50 UTC, John Colvin wrote: Why can't I make Args a sequence of aliases? Works for me on multiple compilers. To be precise, this worked: Except it prints Arg instead of x, try: debug write(Args[i].stringof, " is ", Arg);

Re: Capturing __FILE__ and __LINE in a variadic templated function

2015-11-02 Thread Daniel N via Digitalmars-d-learn
On Monday, 2 November 2015 at 11:36:27 UTC, Nordlöw wrote: I want it to print the name of Arg in the closing as x is 11 See my previous comment: Arg -> Args[i].stringof

Re: friends with phobos, workaround?

2015-09-11 Thread Daniel N via Digitalmars-d-learn
On Thursday, 10 September 2015 at 13:19:08 UTC, Adam D. Ruppe wrote: On Thursday, 10 September 2015 at 08:22:29 UTC, Daniel N wrote: this(string caller = __MODULE__)(int val) if(caller == "std.conv") // Use scoped!Awesome That's disgustingly genius. I'm a bit jealous I didn't think of

Re: Huge output size for simple programs

2015-09-11 Thread Daniel N via Digitalmars-d-learn
On Friday, 11 September 2015 at 11:15:33 UTC, NX wrote: I compile a simple hello world program in C and the results: hello_world.o -> 1.5 KB hello_world (linux executable) -> 8.5 KB If you care about binary sizes, use ldc2: ldc 225544 bytes (stripped + writeln) ldc 175736 bytes (stripped +

Re: friends with phobos, workaround?

2015-09-10 Thread Daniel N via Digitalmars-d-learn
On Thursday, 10 September 2015 at 08:22:29 UTC, Daniel N wrote: import std.typecons; class Awesome1 { private: int val; this(string caller = __MODULE__)(int val) if(caller == "std.conv") // Use scoped!Awesome { this.val = val; } } class Awesome2 { private: int val;

Re: friends with phobos, workaround?

2015-09-10 Thread Daniel N via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 23:44:14 UTC, Idan Arye wrote: How about using a mixin template(http://dlang.org/template-mixin.html)? Thanks, it's a good solution. My only reservation is I would prefer to find a way to directly invoke a symbol in std.* as otherwise different frameworks

friends with phobos, workaround?

2015-09-09 Thread Daniel N via Digitalmars-d-learn
For the record, I think D made the right decision... omitting friends. However there's one case in particular which I find useful, anyone see a good workaround for this? #include class Friendly { private: int val; Friendly(int&& val) : val(val) {} friend std::unique_ptr

Re: Array initialization with Struct templates

2015-08-31 Thread Daniel N via Digitalmars-d-learn
On Monday, 31 August 2015 at 05:38:54 UTC, Jonathan M Davis wrote: So, you're going to need to pass it a Chameleon!(float, purpose.POSITIONAL) and a Chameleon!(float, purpose.COLOR_ONLY color), not 6 doubles - either that, or you're going to need to declare a constructor for VertexData which

Re: [Rosettacode] sum of powers conjecture

2015-07-26 Thread Daniel N via Digitalmars-d-learn
On Sunday, 26 July 2015 at 18:40:59 UTC, bearophile wrote: I've translated the C++ entry to D as third D entry, but it's not a good translation, I've just converted iterators to pointers instead of using ranges (the resulting speed is acceptable). You're welcome to improve it:

Re: Mixin template functions are ignored in struct

2014-10-14 Thread Daniel N via Digitalmars-d-learn
On Tuesday, 14 October 2014 at 20:58:19 UTC, tcak wrote: I have written a struct and a mixin template, and that mixin template is mixed into that struct as follows. Use a normal mixin + token strings(q{}). enum TestCommonMethods = q{ public bool apply( int d, int e ){