Re: How to avoid variable capturing in `foreach` loop with lambdas?

2023-01-05 Thread Tejas via Digitalmars-d-learn
On Thursday, 5 January 2023 at 22:49:01 UTC, thebluepandabear wrote: Have fun reading this : https://issues.dlang.org/show_bug.cgi?id=21929 Thanks for the code suggestion although it still doesn't fix the bug. I am curious as to what those brackets do as well. Okay, my bad for writing the

Re: How to avoid variable capturing in `foreach` loop with lambdas?

2023-01-05 Thread Tejas via Digitalmars-d-learn
On Thursday, 5 January 2023 at 11:55:33 UTC, thebluepandabear wrote: I am using CSFML D bindings and I have created my own sort of UI library for drawing elements onto the screen. One of the classes I've created is a `Button` class, which contains a delegate called `onButtonClick` which is

Re: forgetting -betterC means no runtime bounds checking?

2023-01-05 Thread Tejas via Digitalmars-d-learn
On Thursday, 5 January 2023 at 09:10:00 UTC, areYouSureAboutThat wrote: I was playing around with betterC, when I discovered, that if i accidently forget to provide -betterC to the compiler, it will still compile this, but, there will be no runtime bounds checking occuring. My question is:

Re: Can you simplify nested Indexed types?

2022-12-27 Thread Tejas via Digitalmars-d-learn
On Tuesday, 27 December 2022 at 15:09:11 UTC, Sergei Nosov wrote: Consider, I have the following code: ``` auto a = [3, 6, 2, 1, 5, 4, 0]; auto indicies = iota(3); auto ai = indexed(a, indicies); ai = indexed(ai, iota(2)); writeln(ai); ``` Basically, my idea is to apply

Re: How to move from Unique(someClass) to Unique(someInterface)?

2022-11-27 Thread Tejas via Digitalmars-d-learn
On Sunday, 27 November 2022 at 17:06:31 UTC, vushu wrote: On Saturday, 16 May 2020 at 17:45:56 UTC, Konstantin wrote: [...] I'm actually also very curious about this issue, since I come from c++ where this is possible, and it is a very common functionality for example for dependency

Re: pointer escaping return scope bug?

2022-11-25 Thread Tejas via Digitalmars-d-learn
On Friday, 25 November 2022 at 17:45:57 UTC, Paul Backus wrote: On Friday, 25 November 2022 at 14:07:28 UTC, ShadoLight wrote: On Saturday, 19 November 2022 at 15:00:16 UTC, Paul Backus wrote: Since, in your example, `lf` has global lifetime, the compiler deduces that `lf.fp` also has global

Re: Is defining get/set methods for every field overkill?

2022-11-23 Thread Tejas via Digitalmars-d-learn
On Wednesday, 23 November 2022 at 11:06:12 UTC, []() {}() wrote: On Wednesday, 23 November 2022 at 09:51:46 UTC, FeepingCreature wrote: Why then should a programming language insist that all other code in the module should be able to bypass my specification, and do as it pleases to my

Re: Sorted Array (Container) Type

2022-11-13 Thread Tejas via Digitalmars-d-learn
On Sunday, 13 November 2022 at 18:51:09 UTC, Siarhei Siamashka wrote: On Saturday, 12 November 2022 at 14:07:46 UTC, Per Nordlöw wrote: Have anybody created a wrapper container ```d struct Sorted(ArrayLike, alias lessThanPred) ``` that wraps an array-like type `ArrayLike` so that it's always

Re: dmd as a library

2022-11-07 Thread Tejas via Digitalmars-d-learn
On Tuesday, 8 November 2022 at 00:05:18 UTC, vushu wrote: Any where to find learning material for using dmd as a library? thanks. https://github.com/Superbelko/dmdlib-notes This is the only resource I know of

Re: What's the correct way of creating an instance of class in D?

2022-11-03 Thread Tejas via Digitalmars-d-learn
On Thursday, 3 November 2022 at 15:40:02 UTC, H. S. Teoh wrote: On Thu, Nov 03, 2022 at 04:41:14AM +, Siarhei Siamashka via Digitalmars-d-learn wrote: [...] ```D @safe: import std.stdio; class A { void foo() { writeln("foo"); } } void main() { auto a1 = new A; a1.foo(); // prints

Re: What's the correct way of creating an instance of class in D?

2022-11-03 Thread Tejas via Digitalmars-d-learn
On Thursday, 3 November 2022 at 04:41:14 UTC, Siarhei Siamashka wrote: C++ code: ```C++ #include class A { public: void foo() { std::cout << "foo" << std::endl; } }; int main() { auto a1 = new A; a1->foo(); // prints "foo" A a2; a2.foo(); // prints "foo" delete a1; } ``` D code:

Re: Make IN Dlang

2022-11-01 Thread Tejas via Digitalmars-d-learn
On Tuesday, 1 November 2022 at 23:40:22 UTC, Christian Köstlin wrote: Dear dlang-folk, one of the tools I always return to is rake (https://ruby.github.io/rake/). For those that do not know it, its a little like make in the sense that you describe your build as a graph of tasks with

Re: A strange DMD error

2022-11-01 Thread Tejas via Digitalmars-d-learn
On Tuesday, 1 November 2022 at 15:49:54 UTC, Keivan Shah wrote: On Tuesday, 1 November 2022 at 15:42:43 UTC, Imperatorn wrote: On Tuesday, 1 November 2022 at 15:40:04 UTC, Keivan Shah wrote: Hello, Today I came across a strange bug while using D with `dmd`. I have still not been able to

Re: Find in assoc array then iterate

2022-10-22 Thread Tejas via Digitalmars-d-learn
On Friday, 21 October 2022 at 22:03:53 UTC, Kevin Bailey wrote: I'm trying to do this equivalent C++: unordered_map map; for (auto i = map.find(something); i != map.end(); ++i) ...do something with i... in D, but obviously with an associative array. It seems that it's quite

Re: Detect uninitialized class var access

2022-09-24 Thread Tejas via Digitalmars-d-learn
On Saturday, 24 September 2022 at 23:04:00 UTC, rassoc wrote: On 9/24/22 15:28, Adam D Ruppe via Digitalmars-d-learn wrote: gdb --args ./your_program and then it will tell you all the details you want to know about when this happens. Thank you for your input, Adam. Real shame that there's

Re: Can you access the same classes from C++ and D and vise versa, or do the classes have to not form dependency cycle?

2022-09-14 Thread Tejas via Digitalmars-d-learn
On Tuesday, 13 September 2022 at 03:13:59 UTC, Daniel Donnell, Jr wrote: On Sunday, 11 September 2022 at 02:14:51 UTC, zjh wrote: On Saturday, 10 September 2022 at 22:07:32 UTC, Ali Çehreli wrote: On 9/10/22 13:04, Daniel Donnell wrote: > https://dlang.org/spec/cpp_interface.html At DConf,

Re: Constructors not working

2022-09-02 Thread Tejas via Digitalmars-d-learn
On Friday, 2 September 2022 at 18:39:27 UTC, rikki cattermole wrote: I think you are wanting opAssign not opBinary. Also you made a mistake, since its a struct you don't want to new it when you construct and return it. ```d return new Time(secos / 3600, (secos % 3600) / 60, secos % 60); ```

Re: "Error: no property `offsetof` for type `char*`"

2022-08-19 Thread Tejas via Digitalmars-d-learn
On Friday, 19 August 2022 at 16:36:24 UTC, MyNameHere wrote: On Friday, 19 August 2022 at 14:30:50 UTC, kinke wrote: Oh and `DevicePath()` is a convenience member returning a pointer to the 'dynamic array' (as the array decays to a pointer in C too), so no need to fiddle with `.offsetof` and

Re: Arbitrary precision decimal numbers

2022-08-10 Thread Tejas via Digitalmars-d-learn
On Wednesday, 10 August 2022 at 14:11:04 UTC, Ruby The Roobster wrote: On Saturday, 6 August 2022 at 13:20:19 UTC, Sergey wrote: On Thursday, 4 August 2022 at 13:01:30 UTC, Ruby The Roobster wrote: Is there any implementation in phobos of something similar to BigInt but for non-integers as

Re: Python <==> d call both ways example (with PyD and autowrap)?

2022-06-22 Thread Tejas via Digitalmars-d-learn
On Wednesday, 22 June 2022 at 16:02:00 UTC, mw wrote: Hi, I know with PyD, D can call Python, and with autowrap, Python can call a D .dll, I'm just wondering if someone can show an example that Python <==> d can call both ways? esp. show passing D objects to Python and then call its member

Re: Better way to achieve the following

2022-06-21 Thread Tejas via Digitalmars-d-learn
On Tuesday, 21 June 2022 at 17:09:28 UTC, JG wrote: Suppose we are often writing something like ```d theFirstName[theFirstIndex].theSecondName[theSecondIndex].thirdName[theThirdIndex]=x; ``` One would like to something like ```d alias shortName =

Re: UFCS limit

2022-06-16 Thread Tejas via Digitalmars-d-learn
On Friday, 17 June 2022 at 01:04:28 UTC, Paul Backus wrote: Nope. The way UFCS works is that allows you to call free functions using member-function syntax, and member-function syntax is always `object.memberName`, so UFCS only works for functions that have a name, not anonymous functions.

Re: Can I create a package with friendly modules

2022-06-13 Thread Tejas via Digitalmars-d-learn
On Sunday, 12 June 2022 at 05:05:46 UTC, forkit wrote: Is it possible to create a package.d, consisting of (for example), two modules, where each module can access private declarations within each other. In essence, declaring 'a module level friendship', or a kind of 'extended module' if you

Re: Error: cannot use non-constant CTFE pointer in an initializer `cast(immutable(char)*)TEST`

2022-06-11 Thread Tejas via Digitalmars-d-learn
On Saturday, 11 June 2022 at 11:51:43 UTC, Tejas wrote: On Saturday, 11 June 2022 at 10:07:46 UTC, test123 wrote: how to work this around. ```d __gshared const TEST = import(`onlineapp.d`); extern(C) void main(){ __gshared bin_ptr = TEST.ptr; } ``` ```sh dmd2 -betterC -J. onlineapp.d

Re: Error: cannot use non-constant CTFE pointer in an initializer `cast(immutable(char)*)TEST`

2022-06-11 Thread Tejas via Digitalmars-d-learn
On Saturday, 11 June 2022 at 10:07:46 UTC, test123 wrote: how to work this around. ```d __gshared const TEST = import(`onlineapp.d`); extern(C) void main(){ __gshared bin_ptr = TEST.ptr; } ``` ```sh dmd2 -betterC -J. onlineapp.d onlineapp.d(3): Error: cannot use non-constant CTFE

Re: Anybody have any idea on how to do shared operator overloads?

2022-06-01 Thread Tejas via Digitalmars-d-learn
On Thursday, 2 June 2022 at 01:49:32 UTC, Ruby The Roobster wrote: On Thursday, 2 June 2022 at 01:29:39 UTC, Ruby The Roobster wrote: On Thursday, 2 June 2022 at 01:00:57 UTC, Ali Çehreli wrote: On 6/1/22 17:36, Ruby The Roobster wrote: > A stripped down version of some code I have: Not much

Re: static assert("nothing")

2022-05-31 Thread Tejas via Digitalmars-d-learn
On Tuesday, 31 May 2022 at 08:51:45 UTC, realhet wrote: Hi, In my framework I just found a dozen of compile time error handling like: ...else static assert("Invalid type"); This compiles without error. And it was useless for detecting errors because I forgot the first "false" or "0"

Re: gdc 12.1: undefined references when linking separately compiled files

2022-05-28 Thread Tejas via Digitalmars-d-learn
On Saturday, 28 May 2022 at 13:12:46 UTC, kdevel wrote: I am trying to build a project with GDC. It successfully compiles with dmd and ldmd2. When I use gdc in one go the binary is successfully build: [...] Is seperate compilation working successfully for dmd and ldc? The only bug I know

Re: Inferred attributes errors in template function.

2022-05-27 Thread Tejas via Digitalmars-d-learn
On Friday, 27 May 2022 at 08:39:08 UTC, vit wrote: Hello, I have this problem: ```d static int i; void bar(T)(){ static if(is(T == int)) (()@system => 1)(); static if(is(T == float)) i = 42; } void foo(T)(){ bar!T(); } void main()@safe pure{

Re: How to call destroy() in @nogc?

2022-05-23 Thread Tejas via Digitalmars-d-learn
On Tuesday, 24 May 2022 at 02:29:38 UTC, cc wrote: ```d import core.memory; import core.stdc.stdlib : malloc, free; import core.lifetime : emplace; [...] FWIW your code will compile if you add `extern(C++)` to `Foo`

Re: UI Library

2022-05-20 Thread Tejas via Digitalmars-d-learn
On Friday, 20 May 2022 at 02:37:48 UTC, harakim wrote: I need to write a piece of software to track and categorize some purchases. It's the kind of thing I could probably write in a couple of hours in C#/Java + html/css/javascript. However, something keeps drawing me to D and as this is a

Re: Unexplainable behaviour with direct struct assignment.

2022-05-18 Thread Tejas via Digitalmars-d-learn
On Wednesday, 18 May 2022 at 21:52:18 UTC, HuskyNator wrote: On Wednesday, 18 May 2022 at 21:49:14 UTC, HuskyNator wrote: After updating to `DMD 2.100.0` & `DUB 1.29.0`, I still get this behavior. Only when I use `dub run --b=debug` however (default for me). `dub run --b=release` does return

Re: Language server

2022-05-17 Thread Tejas via Digitalmars-d-learn
On Wednesday, 18 May 2022 at 01:04:16 UTC, Alain De Vos wrote: I tried neovim editor & serve-d and failed. I tried kate editor & serve-d and failed. https://github.com/Pure-D/serve-d Anyone has a clue ? I'm using [lunarvim](https://github.com/LunarVim/LunarVim). It provides you the ability

Re: D WebAssembly working differently than C++, Zig

2022-05-17 Thread Tejas via Digitalmars-d-learn
On Tuesday, 17 May 2022 at 09:38:31 UTC, Sergey wrote: On Monday, 16 May 2022 at 17:32:20 UTC, Allen Garvey wrote: I'm working on a comparison of WebAssembly performance for error propagation dithering using D, C++ and Zig. So far C++ and Zig work as expected, but for D, despite using the same

Re: Why are structs and classes so different?

2022-05-15 Thread Tejas via Digitalmars-d-learn
On Sunday, 15 May 2022 at 21:33:24 UTC, Ali Çehreli wrote: D programmers don't write move constructors or move assignment. Such concepts don't even exist. Never say never : https://github.com/dlang/DIPs/blob/master/DIPs/DIP1040.md Walter is one of the authors of the DIP Also, there's

Re: Back to Basics at DConf?

2022-05-12 Thread Tejas via Digitalmars-d-learn
On Friday, 13 May 2022 at 03:31:53 UTC, Ali Çehreli wrote: On 5/12/22 18:56, forkit wrote: > So...you want to do a talk that challenges D's complexity, by getting > back to basics? I wasn't thinking about challenging complexity but it gives me ideas. I am looking for concrete topics like

Re: Back to Basics at DConf?

2022-05-12 Thread Tejas via Digitalmars-d-learn
On Friday, 13 May 2022 at 04:19:26 UTC, Ola Fosheim Grøstad wrote: On Friday, 13 May 2022 at 03:31:53 UTC, Ali Çehreli wrote: On 5/12/22 18:56, forkit wrote: > So...you want to do a talk that challenges D's complexity, by getting > back to basics? I wasn't thinking about challenging

Re: What are (were) the most difficult parts of D?

2022-05-12 Thread Tejas via Digitalmars-d-learn
On Thursday, 12 May 2022 at 15:18:34 UTC, jmh530 wrote: On Thursday, 12 May 2022 at 12:13:32 UTC, Basile B. wrote: [snip] ``` is ( Type : TypeSpecialization , TemplateParameterList ) is ( Type == TypeSpecialization , TemplateParameterList ) is ( Type Identifier : TypeSpecialization ,

Re: What are (were) the most difficult parts of D?

2022-05-11 Thread Tejas via Digitalmars-d-learn
On Wednesday, 11 May 2022 at 14:20:07 UTC, H. S. Teoh wrote: On Wed, May 11, 2022 at 01:37:21PM +, matheus via Digitalmars-d-learn wrote: > [...] [...] [...] [...] My suggestion is: when prototyping, don't even think about attributes. Just templatize your functions and let the compiler

Re: Parameters of overloaded templated function

2022-05-10 Thread Tejas via Digitalmars-d-learn
On Tuesday, 10 May 2022 at 11:33:24 UTC, frame wrote: On Tuesday, 10 May 2022 at 11:26:44 UTC, frame wrote: On Tuesday, 10 May 2022 at 03:18:14 UTC, Tejas wrote: Can you try Makes no difference. OK, I tried it in separate test and works. Weird, I already tried that before, there must be

Re: Parameters of overloaded templated function

2022-05-09 Thread Tejas via Digitalmars-d-learn
On Tuesday, 10 May 2022 at 01:00:24 UTC, frame wrote: So `__traits(getOverloads)` returns also templated members and `__traits(isTemplate)` can select those members. Unfortunately, `Parameters!` does not work with the templated member. How can I pass a symbol of T or A... to `Parameters!` as

Re: Compile delegate with enum into proper function?

2022-05-08 Thread Tejas via Digitalmars-d-learn
On Saturday, 7 May 2022 at 18:36:40 UTC, jmh530 wrote: In the code below, there is a two parameter function `foo` and an override of it with only one parameter. In the override case, I force the second one to be 1, but ideally there should be a way to specify it at compile-time. It would be

Re: Compile delegate with enum into proper function?

2022-05-07 Thread Tejas via Digitalmars-d-learn
On Sunday, 8 May 2022 at 01:38:55 UTC, jmh530 wrote: On Saturday, 7 May 2022 at 23:30:37 UTC, Paul Backus wrote: [snip] Worth noting that you *can* write ```d alias foo = partial!(foo, a); ``` ...which will add the partially-applied version to `foo`'s overload set. You sure about that?

Re: Google Code Jam 2022

2022-05-06 Thread Tejas via Digitalmars-d-learn
On Friday, 6 May 2022 at 08:25:34 UTC, Siarhei Siamashka wrote: On Friday, 6 May 2022 at 07:05:35 UTC, zjh wrote: For example, I think `d` can also make use of `'winrt'`, which is very important for `GUI` programming . `D` officials should pay attention to `it`. I have downloaded `dwinrt`

Re: How to use destroy and free.

2022-05-03 Thread Tejas via Digitalmars-d-learn
On Tuesday, 3 May 2022 at 12:59:31 UTC, Alain De Vos wrote: Error: array literal in @nogc function test.myfun may cause a GC allocation @nogc void myfun(){ scope int[] i=[1,2,3]; }//myfun May is a fuzzy word... For this particular piece of code, you can use a static array to

Re: Parameters declared as the alias of a template won't accept the arguments of the same type.

2022-05-02 Thread Tejas via Digitalmars-d-learn
On Tuesday, 3 May 2022 at 00:38:34 UTC, Tejas wrote: On Monday, 2 May 2022 at 22:01:51 UTC, ag0aep6g wrote: On 02.05.22 22:47, Stanislav Blinov wrote: On Monday, 2 May 2022 at 20:16:04 UTC, ag0aep6g wrote: On 02.05.22 21:17, Stanislav Blinov wrote: On Monday, 2 May 2022 at 16:29:05 UTC,

Re: Parameters declared as the alias of a template won't accept the arguments of the same type.

2022-05-02 Thread Tejas via Digitalmars-d-learn
On Monday, 2 May 2022 at 22:01:51 UTC, ag0aep6g wrote: On 02.05.22 22:47, Stanislav Blinov wrote: On Monday, 2 May 2022 at 20:16:04 UTC, ag0aep6g wrote: On 02.05.22 21:17, Stanislav Blinov wrote: On Monday, 2 May 2022 at 16:29:05 UTC, Loara wrote: [...] ```d     template MyAlias(T){  

Re: Parameters declared as the alias of a template won't accept the arguments of the same type.

2022-05-01 Thread Tejas via Digitalmars-d-learn
On Sunday, 1 May 2022 at 03:57:12 UTC, Elfstone wrote: module test; struct MatrixImpl(S, size_t M, size_t N) { } [...] AFAICT, I'm afraid you'll have to stick to `dot2`  This DIP I believe does what you want but... It wasn't looked upon favorably...

Re: error connecting to mongodb atlas with vibe.d

2022-05-01 Thread Tejas via Digitalmars-d-learn
On Saturday, 30 April 2022 at 14:29:56 UTC, notsteve wrote: Hi, I am trying to setup a simple webserver in D using vibe.d (0.9.4) and want to use mongoDB as a database. To achieve this, I've set up a mongoDB atlas instance with the following command inside the standard app.d file created by

Re: How to use destroy and free.

2022-04-30 Thread Tejas via Digitalmars-d-learn
On Saturday, 30 April 2022 at 09:25:18 UTC, Dukc wrote: On Sunday, 24 April 2022 at 21:00:50 UTC, Alain De Vod wrote: [...] A few picks. 1: You do not need to import `destroy`. Everything in `object` is automatically imported. [...] Hell, just using `scope int[] i` should be enough to

Re: T... args!

2022-04-29 Thread Tejas via Digitalmars-d-learn
On Friday, 29 April 2022 at 16:10:52 UTC, Salih Dincer wrote: On Friday, 29 April 2022 at 12:57:15 UTC, Steven Schveighoffer wrote: [...] I see, think it can be done with mixin: ```d template prn(alias args) { string prn() { string result = "write("; foreach(s; args.split("|"))

Re: T... args!

2022-04-29 Thread Tejas via Digitalmars-d-learn
On Friday, 29 April 2022 at 12:57:15 UTC, Steven Schveighoffer wrote: On 4/28/22 10:48 PM, Salih Dincer wrote: [...] There is no string interpolation in D. You can use a function such as `std.conv.text` to produce a string given interleaving strings and items. Or you can use

Re: Is @live attribute working yet?

2022-04-24 Thread Tejas via Digitalmars-d-learn
On Sunday, 24 April 2022 at 09:31:40 UTC, elfstone wrote: Dub(DMD 2.099.1) builds and runs the following code without a warning. import std.stdio; import core.stdc.stdlib; @live void test() { int* p = cast(int*) malloc(32); p = cast(int*) malloc(32);

Re: A weird example of .toUTF16z concatination side-effects in wcsncat

2022-04-07 Thread Tejas via Digitalmars-d-learn
On Thursday, 7 April 2022 at 10:50:35 UTC, BoQsc wrote: Here I try to concatenate three character strings using `wcsncat()`. [...] Maybe try using `wstring` instead of string? Also use the `w` postfix ```d wstring dlang_string = "BBB"w; I can't test because I'm not on my PC and I

Re: Mixin Templates and Operators

2022-04-06 Thread Tejas via Digitalmars-d-learn
On Wednesday, 6 April 2022 at 10:36:04 UTC, francesco.andreetto wrote: I have two structs, point and vec, in which I want to implement some arithmetic operations. The operations are: ``` point - point = vec point + vec = point ``` Using mixin templates the code compiles but calling the

Re: Where I download Digital Mars C Preprocessor sppn.exe?

2022-04-03 Thread Tejas via Digitalmars-d-learn
On Sunday, 3 April 2022 at 08:37:45 UTC, user1234 wrote: On Saturday, 2 April 2022 at 21:57:02 UTC, Marcone wrote: Where I download Digital Mars C Preprocessor sppn.exe? I need it to use ImportC it's part of the [DMC] toolchain. [DMC]:

Re: How to create delegates with an independent scope?

2022-03-30 Thread Tejas via Digitalmars-d-learn
On Wednesday, 30 March 2022 at 12:46:07 UTC, Vijay Nayar wrote: Consider the following code example: ```d import std.stdio; void main() { alias DelegateT = string delegate(); // An array of delegates, each has their own scope. DelegateT[] funcs; foreach (i; ["ham", "cheese"]) { //

Re: Tips on TCP socket to postgresql middleware

2022-02-24 Thread Tejas via Digitalmars-d-learn
On Thursday, 24 February 2022 at 06:54:07 UTC, eugene wrote: On Thursday, 24 February 2022 at 06:30:51 UTC, Tejas wrote: On Wednesday, 23 February 2022 at 09:34:56 UTC, eugene wrote: On Tuesday, 22 February 2022 at 20:19:39 UTC, Chris Piker wrote: [...] As you might have been already noted,

Re: Tips on TCP socket to postgresql middleware

2022-02-23 Thread Tejas via Digitalmars-d-learn
On Wednesday, 23 February 2022 at 09:34:56 UTC, eugene wrote: On Tuesday, 22 February 2022 at 20:19:39 UTC, Chris Piker wrote: [...] As you might have been already noted, the key idea is to implement SM explicitly, i.e we have states, messages, actions, transitions and extremely simple engine

Re: ldc executable crashes with this code

2022-02-02 Thread Tejas via Digitalmars-d-learn
On Wednesday, 2 February 2022 at 23:21:52 UTC, forkit wrote: Any reason why compiling this with ldc would cause the exe to crash? Compiling with DMD (using either declaration of palindrome works just fine though) // module test; import std; void main() { char[] palindrome =

Re: number ranges

2022-01-18 Thread Tejas via Digitalmars-d-learn
On Tuesday, 18 January 2022 at 20:43:08 UTC, forkit wrote: On Tuesday, 18 January 2022 at 16:02:42 UTC, Tejas wrote: Newer languages nowadays use `start..intent, think it's something we should follow? I've decided to avoid using number ranges 'directly', and instead use a wrapper

Re: number ranges

2022-01-18 Thread Tejas via Digitalmars-d-learn
On Tuesday, 18 January 2022 at 17:58:54 UTC, H. S. Teoh wrote: On Tue, Jan 18, 2022 at 04:02:42PM +, Tejas via Digitalmars-d-learn wrote: [...] Newer languages nowadays use `start..intent, think it's something we should follow? I've never seen that before. Which languages use that? T

Re: number ranges

2022-01-18 Thread Tejas via Digitalmars-d-learn
On Monday, 17 January 2022 at 22:48:17 UTC, H. S. Teoh wrote: On Mon, Jan 17, 2022 at 10:35:30PM +, forkit via Digitalmars-d-learn wrote: On Monday, 17 January 2022 at 22:28:10 UTC, H. S. Teoh wrote: > [...] [...] If I were able to write a compiler, my compiler would warn you: "This is

Re: non-constant expression ["foo":5, "bar":10, "baz":2000]

2022-01-06 Thread Tejas via Digitalmars-d-learn
On Thursday, 6 January 2022 at 16:01:09 UTC, Stefan Koch wrote: On Thursday, 6 January 2022 at 12:04:12 UTC, HuskyNator wrote: On Monday, 28 November 2016 at 14:41:44 UTC, Era Scarecrow wrote: On Monday, 28 November 2016 at 09:06:34 UTC, Paolo Invernizzi wrote: The point is that I was trying

Re: Libc functions undefined when linking

2022-01-05 Thread Tejas via Digitalmars-d-learn
On Wednesday, 5 January 2022 at 16:14:02 UTC, Ben Jones wrote: On Wednesday, 5 January 2022 at 03:38:54 UTC, Tejas wrote: On Tuesday, 4 January 2022 at 18:13:56 UTC, Ben Jones wrote: The tricky part is that the lab machines that the students will be using don't have a D compiler installed

Re: Returning value by ref does not create a ref. Is this intentional?

2022-01-05 Thread Tejas via Digitalmars-d-learn
On Wednesday, 5 January 2022 at 08:58:44 UTC, Dennis wrote: On Wednesday, 5 January 2022 at 05:38:45 UTC, Tejas wrote: The entire reason I wanted to get a `ref` was so that I can avoid the `*` :( I don't know what the real code behind the reduced example is, but maybe you can structure your

Re: Returning value by ref does not create a ref. Is this intentional?

2022-01-04 Thread Tejas via Digitalmars-d-learn
On Wednesday, 5 January 2022 at 05:17:10 UTC, Stanislav Blinov wrote: It is returned. But initializing `c` with it makes a copy. Oh... Wish we had real `ref` ;( This will mutate `a`: ``` func(a) = 10; ``` Thank you for your help!

Re: Returning value by ref does not create a ref. Is this intentional?

2022-01-04 Thread Tejas via Digitalmars-d-learn
On Wednesday, 5 January 2022 at 05:15:30 UTC, Paul Backus wrote: On Wednesday, 5 January 2022 at 04:35:12 UTC, Tejas wrote: ```d import std.stdio:writeln; ref int func(return ref int a){ a = 6; // modifies a as expected return a; } void main(){ int a = 5; auto c = func(a); // I

Returning value by ref does not create a ref. Is this intentional?

2022-01-04 Thread Tejas via Digitalmars-d-learn
```d import std.stdio:writeln; ref int func(return ref int a){ a = 6; // modifies a as expected return a; } void main(){ int a = 5; auto c = func(a); // I expected c to alias a here c = 10; // Expected to modify a as well writeln(a); // prints 6 :( } ``` The

Re: Libc functions undefined when linking

2022-01-04 Thread Tejas via Digitalmars-d-learn
On Tuesday, 4 January 2022 at 18:13:56 UTC, Ben Jones wrote: The tricky part is that the lab machines that the students will be using don't have a D compiler installed (they're Fedora machines, and I didn't see a dmd package in their repos, or I would have asked the admins to install it).

Re: function(pointer) as template argument, explicit template instantiation

2021-12-30 Thread Tejas via Digitalmars-d-learn
On Friday, 31 December 2021 at 00:57:26 UTC, kdevel wrote: ```dptr.d class R { } void foo (R r) { } alias fn = void function (R); void lyr (fn F) (R r) { } immutable fn foo_ptr = // line 14 pragma (msg, typeof (foo_ptr)); auto ptr = lyr!(foo_ptr);// line 17 ``` dmd reports: ```

Re: print ubyte[] as (ascii) string

2021-12-30 Thread Tejas via Digitalmars-d-learn
On Thursday, 30 December 2021 at 17:31:27 UTC, eugene wrote: On Thursday, 30 December 2021 at 16:49:17 UTC, Tejas wrote: I _think_ the above code is correct, please verify Self-contained example: ```d import std.stdio; import std.string; void main() { ubyte[8] b = [0x68, 0x65, 0x6C,

Re: print ubyte[] as (ascii) string

2021-12-30 Thread Tejas via Digitalmars-d-learn
On Thursday, 30 December 2021 at 17:07:20 UTC, eugene wrote: On Thursday, 30 December 2021 at 16:49:17 UTC, Tejas wrote: ```d char[] s = cast(char[])ioCtx.buf[0 .. $];// please remember that in `[0 .. $]` last index is automatically `length - 1` but just buf[$] will be an error since there

Re: print ubyte[] as (ascii) string

2021-12-30 Thread Tejas via Digitalmars-d-learn
On Thursday, 30 December 2021 at 09:34:27 UTC, eugene wrote: I suspect the question was asked somewhere before. If so just give a link. Anyway: ```d class IoContext { ... ubyte[] buf; ... this(uint bufSize) { buf = new ubyte[bufSize]; } } ``` ```d class

Re: How are extra copy constructor parameters used?

2021-12-29 Thread Tejas via Digitalmars-d-learn
On Thursday, 30 December 2021 at 04:42:06 UTC, Tejas wrote: On Thursday, 30 December 2021 at 01:04:10 UTC, Ali Çehreli wrote: The second item in the documentation mentions "any number of default parameters" when describing copy constructor syntax:

Re: How are extra copy constructor parameters used?

2021-12-29 Thread Tejas via Digitalmars-d-learn
On Thursday, 30 December 2021 at 01:04:10 UTC, Ali Çehreli wrote: The second item in the documentation mentions "any number of default parameters" when describing copy constructor syntax: https://dlang.org/spec/struct.html#struct-copy-constructor 1) I can't figure out how to use those extra

Re: opCast + dtor error

2021-12-28 Thread Tejas via Digitalmars-d-learn
On Tuesday, 28 December 2021 at 18:27:36 UTC, vit wrote: Hi, why this code doesn't compile? ```d struct Foo{ bool opCast(T : bool)()const{ assert(0); } ~this(){} } struct Bar{ const Foo foo; } void main(){ } ``` Error: template instance `opCast!(Foo)` does not

Re: Starting and managing threads

2021-12-28 Thread Tejas via Digitalmars-d-learn
On Tuesday, 28 December 2021 at 16:29:05 UTC, Bagomot wrote: I can't do it according to your example, my Watcher list fills up at runtime. Yes, it's possible to do it at runtime as well(it already _was_ happening at runtime), although I'll be using a `cast` for convenience now. ```d

Re: Starting and managing threads

2021-12-28 Thread Tejas via Digitalmars-d-learn
On Tuesday, 28 December 2021 at 14:19:46 UTC, Bagomot wrote: On Monday, 27 December 2021 at 10:59:07 UTC, Ali Çehreli wrote: On 12/27/21 1:33 AM, Bagomot wrote: > separate thread, without blocking the main one. I think you can use std.concurrency there. I have a chapter here:

Re: AA and struct with const member

2021-12-27 Thread Tejas via Digitalmars-d-learn
On Tuesday, 28 December 2021 at 01:45:42 UTC, Era Scarecrow wrote: On Monday, 27 December 2021 at 19:38:38 UTC, frame wrote: [...] const/immutable members are to be set/assigned instantiation. Most likely the problem is a bug and sounds like [...] The workaround is okay, but I think we

Re: Good intellisense support IDE/Editor?

2021-12-22 Thread Tejas via Digitalmars-d-learn
On Wednesday, 22 December 2021 at 11:50:06 UTC, evilrat wrote: On Wednesday, 22 December 2021 at 10:37:51 UTC, Michel wrote: Hey, I've tried coding in Visual Studio Code but there isn't any function checking/showing what arguments a function accepts, I can just write

Re: Small structs: interfacing with C++ potentially broken

2021-12-20 Thread Tejas via Digitalmars-d-learn
On Monday, 20 December 2021 at 11:58:03 UTC, Tim wrote: On Monday, 20 December 2021 at 10:24:00 UTC, Jan wrote: Is this a known issue, or is there a way to instruct DMD to use a specific calling convention for a given type? This looks like a bug. It seems to work without constructor in C++,

Re: How to insert code in place with templates/mixins?

2021-12-20 Thread Tejas via Digitalmars-d-learn
On Monday, 20 December 2021 at 11:30:09 UTC, rumbu wrote: On Monday, 20 December 2021 at 10:49:20 UTC, rempas wrote: On Monday, 20 December 2021 at 09:30:30 UTC, rumbu wrote: Thanks a lot for the info. When I try to use this code, I'm getting the following error: ``` Error: expression

Re: dynamic array + copy ctor

2021-12-19 Thread Tejas via Digitalmars-d-learn
On Sunday, 19 December 2021 at 22:29:21 UTC, vit wrote: Hello, Why is copy ctor in this example not called? ```d import std.stdio; struct Foo { int i; this(int i){ this.i = i; writeln("init: ", i); } this(ref typeof(this) rhs){ this.i = rhs.i;

Re: ImportC: Should this compile?

2021-12-18 Thread Tejas via Digitalmars-d-learn
On Sunday, 19 December 2021 at 02:57:35 UTC, Mike Parker wrote: On Saturday, 18 December 2021 at 22:31:38 UTC, bachmeier wrote: I've been trying to get the stb header library to compile. There's a single remaining failure: ``` typedef struct { unsigned char c[4]; } stb_easy_font_color;

Re: This is bug or not? (immutable class containing struct with dtor)

2021-12-18 Thread Tejas via Digitalmars-d-learn
On Saturday, 18 December 2021 at 11:01:53 UTC, Denis Feklushkin wrote: On Friday, 17 December 2021 at 19:03:05 UTC, Tejas wrote: Well, I got completely mislead by my experiment  ```d struct S { ~this() immutable {} } ``` Interesting what discussed behaviour isn't affects method what

Re: This is bug or not? (immutable class containing struct with dtor)

2021-12-17 Thread Tejas via Digitalmars-d-learn
On Friday, 17 December 2021 at 18:51:56 UTC, Ali Çehreli wrote: On 12/17/21 10:01 AM, Tejas wrote: > [...] Storage, There is no such requirement nor guarantee. [...] Well, I got completely mislead by my experiment  ```d struct S { ~this() immutable {} } void main() { immutable S

Re: This is bug or not? (immutable class containing struct with dtor)

2021-12-17 Thread Tejas via Digitalmars-d-learn
On Friday, 17 December 2021 at 18:32:43 UTC, Denis Feklushkin wrote: On Friday, 17 December 2021 at 18:02:52 UTC, Tejas wrote: I improved your sample: ```d immutable struct S { ~this() {} } immutable struct S2 { S sss; ~this() {} } void main() { S2 s = S2(); } ``` ``` Error:

Re: This is bug or not? (immutable class containing struct with dtor)

2021-12-17 Thread Tejas via Digitalmars-d-learn
On Friday, 17 December 2021 at 18:19:34 UTC, Denis Feklushkin wrote: On Friday, 17 December 2021 at 18:01:03 UTC, Tejas wrote: I think since `immutable` objects are kept in Read Only Storage Some of them can be stored in ROM in some cases, but actually "immutable" keyword means "not mutable

Re: This is bug or not? (immutable class containing struct with dtor)

2021-12-17 Thread Tejas via Digitalmars-d-learn
On Friday, 17 December 2021 at 18:01:03 UTC, Tejas wrote: On Friday, 17 December 2021 at 17:34:05 UTC, Denis Feklushkin wrote: On Friday, 17 December 2021 at 17:27:53 UTC, Denis Feklushkin wrote: [...] ("serializer_bug" is just name of my local .d file) I think since `immutable`

Re: This is bug or not? (immutable class containing struct with dtor)

2021-12-17 Thread Tejas via Digitalmars-d-learn
On Friday, 17 December 2021 at 17:34:05 UTC, Denis Feklushkin wrote: On Friday, 17 December 2021 at 17:27:53 UTC, Denis Feklushkin wrote: ~this() {} // Comment out this to fix this compilation error: // Error: `immutable` method `serializer_bug.Imm.~this` is ("serializer_bug" is

Re: Why code failed to compile for foo2?

2021-12-14 Thread Tejas via Digitalmars-d-learn
On Tuesday, 14 December 2021 at 15:14:40 UTC, Steven Schveighoffer wrote: On 12/14/21 12:04 AM, Tejas wrote: Is there anything wrong with the answer I posted? Can you please tell me if there's anything dissatisfactory about it? I feel like it does everything the OP wants. Also, am I wrong

Re: Why code failed to compile for foo2?

2021-12-14 Thread Tejas via Digitalmars-d-learn
On Tuesday, 14 December 2021 at 13:25:04 UTC, apz28 wrote: On Tuesday, 14 December 2021 at 05:04:46 UTC, Tejas wrote: Is there anything wrong with the answer I posted? Can you please tell me if there's anything dissatisfactory about it? I feel like it does everything the OP wants. Also, am

Re: template ctor overload Segmentation fault

2021-12-14 Thread Tejas via Digitalmars-d-learn
On Tuesday, 14 December 2021 at 12:04:36 UTC, RazvanN wrote: On Sunday, 12 December 2021 at 11:57:43 UTC, vit wrote: [...] The problem is that the compiler will try to generate an inout copy constructor for Bar that looks roughly like this: ``` this(ref scope inout(Bar) p) inout {

Re: How to pass a class by (const) reference to C++

2021-12-13 Thread Tejas via Digitalmars-d-learn
On Monday, 13 December 2021 at 12:08:30 UTC, evilrat wrote: On Monday, 13 December 2021 at 11:13:12 UTC, Tejas wrote: On Monday, 13 December 2021 at 09:21:26 UTC, Jan wrote: [...] You'll have to use something called a [shim](https://en.wikipedia.org/wiki/Shim_(computing)), it seems. For

Re: Passing a derived class where base class is defined as ref parameter

2021-12-13 Thread Tejas via Digitalmars-d-learn
On Monday, 13 December 2021 at 22:30:59 UTC, Adam D Ruppe wrote: On Monday, 13 December 2021 at 22:06:45 UTC, chopchop wrote: If I remove the ref, it works as expected, that is to say I can give a derived class as parameter. Why are you using the ref to begin with? What the logic here?

Re: Why code failed to compile for foo2?

2021-12-13 Thread Tejas via Digitalmars-d-learn
On Monday, 13 December 2021 at 20:43:51 UTC, Steven Schveighoffer wrote: On 12/11/21 10:02 PM, apz28 wrote: On Sunday, 12 December 2021 at 00:02:25 UTC, Stanislav Blinov wrote: @apz28, I can't figure out the intent here. To convert result of abs to an unsigned? The function logic works only

Re: How to pass a class by (const) reference to C++

2021-12-13 Thread Tejas via Digitalmars-d-learn
On Monday, 13 December 2021 at 09:21:26 UTC, Jan wrote: On Monday, 13 December 2021 at 07:48:34 UTC, evilrat wrote: On Sunday, 12 December 2021 at 21:24:39 UTC, Jan wrote: In D I have an extern(C++) class: ```cpp extern(C++) class A { ~this(); // other stuff } ``` An a function that

Re: template ctor overload Segmentation fault

2021-12-13 Thread Tejas via Digitalmars-d-learn
On Sunday, 12 December 2021 at 19:17:53 UTC, vit wrote: On Sunday, 12 December 2021 at 18:32:28 UTC, Imperatorn wrote: On Sunday, 12 December 2021 at 11:57:43 UTC, vit wrote: Hello, why does this code fail to compile? ```d struct Foo(T){ this(Rhs, this This)(scope Rhs rhs){ }

Re: Why code failed to compile for foo2?

2021-12-13 Thread Tejas via Digitalmars-d-learn
On Sunday, 12 December 2021 at 03:02:28 UTC, apz28 wrote: On Sunday, 12 December 2021 at 00:02:25 UTC, Stanislav Blinov wrote: @apz28, I can't figure out the intent here. To convert result of abs to an unsigned? The function logic works only for unsigned type and the parameter value can be

  1   2   3   >