Re: Static array as immutable

2017-12-11 Thread Radu via Digitalmars-d-learn
On Tuesday, 12 December 2017 at 07:33:47 UTC, Ivan Trombley wrote: Is there some way that I can make this array immutable? static float[256] ga = void; static foreach (i; 0 .. 256) ga[i] = (i / 255.0f) ^^ (1 / 2.2f); Check https://dlang.org/phobos/std_exception.html#assumeUnique

Re: Capturing by reference with "visit" from std.variant

2018-02-20 Thread Radu via Digitalmars-d-learn
On Tuesday, 20 February 2018 at 16:01:11 UTC, Smaehtin wrote: I'm trying to understand why the following doesn't work: import std.stdio; import std.variant; void main() { Algebraic!(string, int) test = "Test"; test.tryVisit!( (ref string s) { s = "Why does this not work?"; }

Struct ctor called with cast

2018-02-27 Thread Radu via Digitalmars-d-learn
I have this: enum Type { a }; struct S(Type t = Type.a) { this(Type)(Type t) { import std.stdio; writeln("ctor called."); } } void main() { auto x = S!(Type.a)(Type.a); void* y = &x; auto z = (cast(S!(Type.a)) y); } Surprisingly the cast will actually c

Re: Struct ctor called with cast

2018-02-27 Thread Radu via Digitalmars-d-learn
On Tuesday, 27 February 2018 at 20:51:25 UTC, ag0aep6g wrote: On 02/27/2018 09:30 PM, Radu wrote: enum Type { a }; struct S(Type t = Type.a) {     this(Type)(Type t)     {     import std.stdio;     writeln("ctor called.");     } } void main() {    auto x = S!(Type.a)(Type.a);   

Re: Struct ctor called with cast

2018-02-27 Thread Radu via Digitalmars-d-learn
On Tuesday, 27 February 2018 at 21:04:59 UTC, ag0aep6g wrote: On 02/27/2018 09:59 PM, Radu wrote: On Tuesday, 27 February 2018 at 20:51:25 UTC, ag0aep6g wrote: On 02/27/2018 09:30 PM, Radu wrote: [...] [...] [...] So the bug is that somehow the templated version makes it so there is an impl

Re: how to make private class member private

2018-03-12 Thread Radu via Digitalmars-d-learn
On Tuesday, 13 March 2018 at 06:14:49 UTC, psychoticRabbit wrote: On Tuesday, 13 March 2018 at 06:01:43 UTC, ketmar wrote: ah, yes, sorry: i completely forgot that C++ was invented after c# and java. mea maxima culpa! My point was, that the 2 most widely used and popular languages on the pl

Re: how to make private class member private

2018-03-13 Thread Radu via Digitalmars-d-learn
On Tuesday, 13 March 2018 at 08:05:43 UTC, psychoticRabbit wrote: On Tuesday, 13 March 2018 at 06:03:11 UTC, Mike Parker wrote: I think it's a great feature and I use it frequently. It's allows more flexibility in class design. Without it, we'd need another protection attribute to enable the

Re: signbit question

2018-03-16 Thread Radu via Digitalmars-d-learn
On Friday, 16 March 2018 at 07:00:36 UTC, ashit axar wrote: On Thursday, 15 March 2018 at 17:30:48 UTC, Seb wrote: They generate the same assembly: https://godbolt.org/g/4ohTJx import std.stdio; void main() { writeln("hello"); } this generate error for dmd there. `writeln` is not sup

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

2018-03-18 Thread Radu 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. add "-O3" also to the compiler switches.

Re: Are Fibers just broken in D?

2018-04-24 Thread Radu via Digitalmars-d-learn
On Tuesday, 24 April 2018 at 00:46:39 UTC, Byron Heads wrote: On Friday, 20 April 2018 at 20:52:17 UTC, Byron Moxie wrote: On Friday, 20 April 2018 at 20:46:20 UTC, Steven Schveighoffer wrote: On 4/20/18 2:58 PM, Byron Moxie wrote: [...] It sounds like the problems may be due to Win32 and no

Re: Are Fibers just broken in D?

2018-04-24 Thread Radu via Digitalmars-d-learn
On Tuesday, 24 April 2018 at 13:36:48 UTC, Steven Schveighoffer wrote: On 4/24/18 5:11 AM, bauss wrote: On Tuesday, 24 April 2018 at 07:58:01 UTC, Radu wrote: On Tuesday, 24 April 2018 at 00:46:39 UTC, Byron Heads wrote: [...] This is not a fiber issue but a more memory management issue. Yo

Re: Are Fibers just broken in D?

2018-04-24 Thread Radu via Digitalmars-d-learn
On Tuesday, 24 April 2018 at 16:05:48 UTC, Steven Schveighoffer wrote: On 4/24/18 10:16 AM, Radu wrote: On Tuesday, 24 April 2018 at 13:36:48 UTC, Steven Schveighoffer wrote: On 4/24/18 5:11 AM, bauss wrote: On Tuesday, 24 April 2018 at 07:58:01 UTC, Radu wrote: On Tuesday, 24 April 2018 at 00

Re: `this` and nested structs

2018-05-09 Thread Radu via Digitalmars-d-learn
On Thursday, 10 May 2018 at 03:23:50 UTC, Mike Franklin wrote: Consider the following code: --- struct S { // intentionally not `static` struct SS { int y() { return x; } // Error: need `this` for `x` of type `int` } int x; SS ss; } void main() { S s;

Re: LDC with ARM backend

2016-07-15 Thread Radu via Digitalmars-d-learn
On Friday, 15 July 2016 at 14:09:40 UTC, Claude wrote: Hello, I would like to cross-compile a D program from a x86 machine to an ARM target. I work on GNU/Linux Ubuntu 64-bit. I have an ARM gcc toolchain, which I can use to make programs on an ARM Cortex-A9 architecture running a Linux kerne

Re: [Semi-OT] I don't want to leave this language!

2016-12-08 Thread Radu via Digitalmars-d-learn
On Thursday, 8 December 2016 at 11:09:12 UTC, ketmar wrote: what can be done, tho, is article (or series of articles) describing what exactly druntime is, how it is compared to libc and libc++, why it doesn't hurt at all, how to do "bare metal" with custom runtime, why GC is handy (and how to l

Calling destroy on struct pointer

2017-02-25 Thread Radu via Digitalmars-d-learn
I'm puzzled by the way destroy works when passed a pointer to a struct, observe: --code.d-- int i; struct C { this(ref int i) { ++i; ii = &i; } ~this() { --(*i

Re: Calling destroy on struct pointer

2017-02-25 Thread Radu via Digitalmars-d-learn
On Saturday, 25 February 2017 at 08:36:02 UTC, Ali Çehreli wrote: On 02/25/2017 12:17 AM, Radu wrote: > destroy(cc) -> does c = C.init > destroy(*cc); -> calls the C dtor > > Is this by design? If so - how can I destroy and get the dtor called > without dereferencing the pointer? It's by design

Re: Calling destroy on struct pointer

2017-02-25 Thread Radu via Digitalmars-d-learn
On Saturday, 25 February 2017 at 13:14:24 UTC, Moritz Maxeiner wrote: On Saturday, 25 February 2017 at 10:44:07 UTC, Radu wrote: On Saturday, 25 February 2017 at 08:36:02 UTC, Ali Çehreli wrote: On 02/25/2017 12:17 AM, Radu wrote: > destroy(cc) -> does c = C.init > destroy(*cc); -> calls the C

Re: Calling destroy on struct pointer

2017-02-25 Thread Radu via Digitalmars-d-learn
On Saturday, 25 February 2017 at 13:18:21 UTC, Moritz Maxeiner wrote: On Saturday, 25 February 2017 at 13:14:24 UTC, Moritz Maxeiner wrote: --- struct A {} auto a = cast (A*) malloc(A.sizeof); // Allocate emplace(a, 42); // Construct destroy(a); //

Re: Calling destroy on struct pointer

2017-02-28 Thread Radu via Digitalmars-d-learn
On Saturday, 25 February 2017 at 16:39:18 UTC, Moritz Maxeiner wrote: On Saturday, 25 February 2017 at 15:13:27 UTC, Radu wrote: [...] Thanks for the example. [...] Hm, that's an issue you'd best take up to the bugtracker, I think. Maybe there's a way around that, but I don't know. [..

alias symbol name

2018-06-26 Thread Radu via Digitalmars-d-learn
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 m _D9onlineapp4mainFZ1sm --- I'm looking for a way to g

Re: alias symbol name

2018-06-26 Thread Radu via Digitalmars-d-learn
On Tuesday, 26 June 2018 at 09:24:15 UTC, Stefan Koch wrote: 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)));

Re: alias symbol name

2018-06-26 Thread Radu via Digitalmars-d-learn
On Tuesday, 26 June 2018 at 10:19:44 UTC, Jonathan M Davis wrote: On Tuesday, June 26, 2018 09:47:44 Radu via Digitalmars-d-learn wrote: On Tuesday, 26 June 2018 at 09:24:15 UTC, Stefan Koch wrote: > On Tuesday, 26 June 2018 at 09:14:11 UTC, Radu wrote: >> Consider this https://run.dl

Re: alias symbol name

2018-06-26 Thread Radu via Digitalmars-d-learn
On Tuesday, 26 June 2018 at 12:19:16 UTC, Jonathan M Davis wrote: On Tuesday, June 26, 2018 11:28:11 Radu via Digitalmars-d-learn wrote: > [...] Ha! :) yeah I was pretty sure this will not work. I'm looking to generate some custom wrappers and knowing when something is really `si

Re: High memory usage in vibe.d application

2018-06-29 Thread Radu via Digitalmars-d-learn
On Friday, 29 June 2018 at 09:44:27 UTC, Anton Fediushin wrote: Almost forgot, there are two timers which call this function for two different streams. Value of `metaint` is 16000, which means that only 16KB of memory are allocated for the `buffer`, then it reads another byte which contains l

Re: UFCS confusion

2018-07-13 Thread Radu via Digitalmars-d-learn
On Friday, 13 July 2018 at 10:21:54 UTC, Michael wrote: Hello, I am nesting some function calls, and I'm pretty used to making use of D's Uniform Function Call Syntax, but I'm getting an error if I try to convert this line: createSet(createVector(langSize, index)).length; which works, int

Re: UFCS confusion

2018-07-13 Thread Radu via Digitalmars-d-learn
On Friday, 13 July 2018 at 11:12:47 UTC, Michael wrote: On Friday, 13 July 2018 at 10:52:54 UTC, Radu wrote: On Friday, 13 July 2018 at 10:21:54 UTC, Michael wrote: [...] Do you try to call member functions? UFCS only works with free functions, meaning declared at module level. https://dla

Re: Is there any plan for a dependency-free subset of "core" runtime?

2018-07-19 Thread Radu via Digitalmars-d-learn
On Thursday, 19 July 2018 at 11:35:00 UTC, Seb wrote: On Thursday, 19 July 2018 at 10:27:36 UTC, Zheng (Vic) Luo wrote: Current implementation of d-runtime relies on a lot of symbols from libc, librt, libpthread, which makes it hard to create a minimal runtime used for embedded devices. Althoug

Re: Is there any plan for a dependency-free subset of "core" runtime?

2018-07-20 Thread Radu via Digitalmars-d-learn
On Thursday, 19 July 2018 at 18:16:17 UTC, kinke wrote: On Thursday, 19 July 2018 at 12:44:30 UTC, Radu wrote: [...] Removing some superfluous explicit druntime dependencies from Phobos would be a start. Your (nice) example compiles fine with this 4-lines Phobos hack: [...] Was able to g

Re: Dlang on OpenWrt

2018-08-02 Thread Radu via Digitalmars-d-learn
On Thursday, 2 August 2018 at 10:47:33 UTC, Ky-Anh Huynh wrote: Hi, can I build my program on OpenWrt? I haven't found any resources on internet maybe I'm missing something. Thanks a lot. LDC 1.10+ should have pretty good support for OpenWRT uClibc for ARM, and some support for uClibc MIPS

Re: Dlang on OpenWrt

2018-08-10 Thread Radu via Digitalmars-d-learn
On Thursday, 2 August 2018 at 10:47:33 UTC, Ky-Anh Huynh wrote: Hi, can I build my program on OpenWrt? I haven't found any resources on internet maybe I'm missing something. Thanks a lot. A status report on what works and how to get LDC to compile for OpenWRT uClibc ARM: https://github.co

Re: why mixin template can not inclulde statement;

2018-08-10 Thread Radu via Digitalmars-d-learn
On Friday, 10 August 2018 at 13:05:24 UTC, Kagamin wrote: Mixim template can only introduce declarations, not statements, a workaround is a lambda called in place. mixin template test(A...){ __gshared a = A; int dummy = (){ a++; return 0; }(); } extern(C) void main(){ m

Re: Cross compile windows programs on linux

2018-08-24 Thread Radu via Digitalmars-d-learn
On Friday, 24 August 2018 at 16:30:56 UTC, John Burton wrote: On Friday, 24 August 2018 at 15:26:30 UTC, kinke wrote: On Friday, 24 August 2018 at 13:10:40 UTC, John Burton wrote: Is in the subject. Are there any cross compilers that will run on a linux system but compile D code using Win32 int

Re: How do you actually run the "Start a minimal webserver" example on the home page

2018-08-25 Thread Radu via Digitalmars-d-learn
On Saturday, 25 August 2018 at 20:37:04 UTC, Everlast wrote: On Saturday, 25 August 2018 at 20:28:55 UTC, Chris M. wrote: On Saturday, 25 August 2018 at 20:17:35 UTC, AN wrote: I downloaded the script and made it executable. I also have dub on `/usr/bin/dub` . The example just stalls with no o

Re: Cannot make sense of LLD linker error with ldc 1.11.0

2018-08-30 Thread Radu via Digitalmars-d-learn
On Thursday, 30 August 2018 at 13:36:58 UTC, Per Nordlöw wrote: Recently the benchmark https://github.com/nordlow/phobos-next/tree/master/benchmarks/containers/dub.sdl [...] There is a way to specify the linker to be used ``` -linker= - Linker to use ```

Re: is there something like `stm32-rs` in D?

2018-09-25 Thread Radu via Digitalmars-d-learn
On Wednesday, 26 September 2018 at 03:46:21 UTC, dangbinghoo wrote: hi, https://github.com/adamgreig/stm32-rs looks great, is there something like this in Dlang? thanks! --- dangbinghoo You might take a look at https://github.com/JinShil/stm32f42_discovery_demo and https://github.com/JinSh

Re: is there something like `stm32-rs` in D?

2018-09-26 Thread Radu via Digitalmars-d-learn
On Wednesday, 26 September 2018 at 05:55:49 UTC, dangbinghoo wrote: On Wednesday, 26 September 2018 at 05:24:08 UTC, Radu wrote: On Wednesday, 26 September 2018 at 03:46:21 UTC, dangbinghoo wrote: hi, https://github.com/adamgreig/stm32-rs looks great, is there something like this in Dlang?

Function parameters UDAs

2018-11-14 Thread Radu via Digitalmars-d-learn
Looks like that there is no easy way to extract a function parameters UDA list. The following: ``` import std.traits; struct s { string foo; } void foo(@s("aaa") int a, bool x); void main() { alias P = Parameters!foo; enum udas = __traits(getAttributes, P); pragma(msg, udas); } ```

Re: Function parameters UDAs

2018-11-14 Thread Radu via Digitalmars-d-learn
On Wednesday, 14 November 2018 at 18:05:55 UTC, Adam D. Ruppe wrote: On Wednesday, 14 November 2018 at 16:28:19 UTC, Radu wrote: Looks like that there is no easy way to extract a function parameters UDA list. Indeed, the only way I can find is kinda crazy: --- void foo(int f, @("test") string

Re: Writing Postgresql extension in D

2018-11-15 Thread Radu via Digitalmars-d-learn
On Friday, 16 November 2018 at 02:18:11 UTC, Ranjan wrote: On Thursday, 15 November 2018 at 17:03:55 UTC, Andrea Fontana wrote: On Thursday, 15 November 2018 at 13:05:59 UTC, Ranjan wrote: This is my first time on the Dlang forum. I like the language but my usecase is a bit different. I want

Re: struct sta­tic ini­tial­izer method apply to UDA

2018-12-06 Thread Radu via Digitalmars-d-learn
On Thursday, 6 December 2018 at 11:09:47 UTC, Basile B. wrote: On Thursday, 6 December 2018 at 11:04:23 UTC, learnfirst1 wrote: my question is how to easy use struct sta­tic ini­tial­izer method with UDA. Fake code: struct DbColumn { string name; boolunique ; bool

Re: GC options

2019-01-25 Thread Radu via Digitalmars-d-learn
On Friday, 25 January 2019 at 13:33:25 UTC, Alex wrote: I'm experimenting with GC, and reading https://dlang.org/spec/garbage.html#gc_config There is an option setting possible via ´´´ extern(C) __gshared string[] rt_options = [ "gcopt=gc:precise" ]; //gc:conservative|precise|manual ´´´ conser

Re: Cannot link vibe.d sample / optlink error

2019-04-08 Thread Radu via Digitalmars-d-learn
On Monday, 8 April 2019 at 13:42:31 UTC, Michal Minich wrote: I used dmd 2.085.0 and 2.085.1 on Win 10 I followed sample at https://vibed.org/blog/posts/a-scalable-chat-room-service-in-d Just the beginning, where you you should compile hello word web app. command line: "dub" compilation fin

Re: OT - Git training Lon/HK and book recommendation on taste in programming

2019-05-02 Thread Radu via Digitalmars-d-learn
On Wednesday, 1 May 2019 at 09:51:01 UTC, Laeeth Isharc wrote: Second question. Lots of people these days start to program to solve their problems at work but they may never have been shown the basic principles of design, structuring and maintenance of their code. If I could give them one bo

Re: Blog Post #0038 - Dialogs IV - Saving a File

2019-05-24 Thread Radu via Digitalmars-d-learn
On Friday, 24 May 2019 at 09:52:38 UTC, Ron Tarrant wrote: Today's blog post over on gtkDcoding.com is about using a GTK dialog for saving a file. You can find it here: http://gtkdcoding.com/2019/05/24/0038-file-save-dialog.html Interesting posts you have. I might not be the first one to ask

Re: Blog Post #0038 - Dialogs IV - Saving a File

2019-05-24 Thread Radu via Digitalmars-d-learn
On Friday, 24 May 2019 at 11:06:47 UTC, Ron Tarrant wrote: I'm still debating this idea, but I won't say I'm adamantly opposed to it. Research into how people learn seems to support both sides of the argument: should imagery be included or not? And I suppose if I ever pull all this stuff toge

Re: Converting a ulong to a byte array and constructing a ulong from it

2019-10-24 Thread Radu via Digitalmars-d-learn
On Thursday, 24 October 2019 at 13:33:30 UTC, 9898287 wrote: What's the function for converting a ulong to a native-endian byte array? For example, auto bytes = 0x1234567890123456u64.to_ne_bytes(); // should yield // [0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56] in big-endian and // [0x56,

std.Algebraic alias this

2015-10-05 Thread Radu via Digitalmars-d-learn
There is a weird rule on how compiler treats alias this for the N and S types bellow. As you can see, somehow S losses it's type and ends up a plain string withing the Algebraic type. I would expect that all types should be the treated the same, why a string alias will be different then a boo

Re: std.Algebraic alias this

2015-10-05 Thread Radu via Digitalmars-d-learn
On Tuesday, 6 October 2015 at 06:37:16 UTC, Nicholas Wilson wrote: On Monday, 5 October 2015 at 11:31:32 UTC, Radu wrote: There is a weird rule on how compiler treats alias this for the N and S types bellow. [...] Please file a bug report. Also do the errors change if you reverse the order

Re: std.Algebraic alias this

2015-10-06 Thread Radu via Digitalmars-d-learn
On Tuesday, 6 October 2015 at 06:37:16 UTC, Nicholas Wilson wrote: On Monday, 5 October 2015 at 11:31:32 UTC, Radu wrote: There is a weird rule on how compiler treats alias this for the N and S types bellow. [...] Please file a bug report. Also do the errors change if you reverse the order

Re: Strange exception, with EXTREMELY SIMPLE toString() in a struct

2015-12-07 Thread Radu via Digitalmars-d-learn
On Monday, 7 December 2015 at 08:17:27 UTC, Enjoys Math wrote: Exception Message: First-chance exception: std.format.FormatException Unterminated format specifier: "%" at C:\D\dmd2\windows\bin\..\..\src\phobos\std\format.d(828) [CODE] module set; import std.conv; struct Set(T) { stri