Re: How to translate this C macro to D mixin/template mixin?

2021-06-16 Thread Tejas via Digitalmars-d-learn
On Wednesday, 16 June 2021 at 05:48:21 UTC, VitaliiY wrote: On Tuesday, 15 June 2021 at 12:39:40 UTC, Dennis wrote: On Tuesday, 15 June 2021 at 12:18:26 UTC, VitaliiY wrote: [...] ```D enum string ADDBITS(string a, string b) = ` { bitbuffer = (bitbuffer<<(`~a~`))|((`~b~`)&((1<<`~a~`)-1));

Why can't we transpile C++ to D?

2021-06-10 Thread Tejas via Digitalmars-d-learn
Sorry, I'm rather ignorant when it comes to this, but why can't we use [pegged](https://github.com/PhilippeSigaud/Pegged) to transpile C++ code to D? Then we won't need a nogc compatible std library and so many other things could get easier, like getting legacy code to use Dlang. It might not

Re: Why can't we transpile C++ to D?

2021-06-10 Thread Tejas via Digitalmars-d-learn
On Thursday, 10 June 2021 at 16:49:59 UTC, Dukc wrote: On Thursday, 10 June 2021 at 15:09:02 UTC, Tejas wrote: Sorry, I'm rather ignorant when it comes to this, but why can't we use [pegged](https://github.com/PhilippeSigaud/Pegged) to transpile C++ code to D? Then we won't need a nogc

Re: Why can't we transpile C++ to D?

2021-06-10 Thread Tejas via Digitalmars-d-learn
On Thursday, 10 June 2021 at 16:50:41 UTC, evilrat wrote: On Thursday, 10 June 2021 at 15:09:02 UTC, Tejas wrote: Sorry, I'm rather ignorant when it comes to this, but why can't we use [pegged](https://github.com/PhilippeSigaud/Pegged) to transpile C++ code to D? Then we won't need a nogc

Re: String front, back return code point/unit

2021-06-23 Thread Tejas via Digitalmars-d-learn
On Wednesday, 23 June 2021 at 15:31:04 UTC, vit wrote: Hello, I am implementing @nogc string struct similar to c++ std::basic_string (link https://code.dlang.org/packages/basic_string). C++ string has methods front, back and pop_back returning/deleting code units. D strings has functions

Re: Template arg deduction

2021-07-07 Thread Tejas via Digitalmars-d-learn
On Wednesday, 7 July 2021 at 19:14:52 UTC, Kevin Bailey wrote: I'm trying to use some fairly simple template argument deduction, but maybe I'm not getting the syntax correct. C++ doesn't event blink at something like this, but D is giving me: temptest.d(18): Error: template temptest.func

Re: What is the D equivalent of C++'s method pointers?

2021-07-08 Thread Tejas via Digitalmars-d-learn
On Thursday, 8 July 2021 at 12:04:01 UTC, Paul Backus wrote: https://digitalmars.com/articles/b68.html Thank you very much :D

What is the D equivalent of C++'s method pointers?

2021-07-08 Thread Tejas via Digitalmars-d-learn
Given a class ```Employee``` , if I have the following code ``` int (Employee::*methodPtr) () const { ::getSalary }; Employee employee { "John", "Doe" }; cout << (employee.*methodPtr)() << endl; ``` What is the equivalent D code? Ditto for pointer to class instances: ``` int

Re: What is the D equivalent of C++'s method pointers?

2021-07-08 Thread Tejas via Digitalmars-d-learn
On Thursday, 8 July 2021 at 11:53:42 UTC, Tejas wrote: Given a class ```Employee``` , if I have the following code ``` int (Employee::*methodPtr) () const { ::getSalary }; Employee employee { "John", "Doe" }; cout << (employee.*methodPtr)() << endl; ``` What is the equivalent D code? Ditto

Re: How to disable assigning a value to a property?

2021-07-06 Thread Tejas via Digitalmars-d-learn
On Tuesday, 6 July 2021 at 10:06:11 UTC, Jack Applegame wrote: Here's another way using ``` std.typecons ``` ```d import std.stdio; import std.typecons; alias input = Typedef!int; //new code struct Field { void opAssign(int a) { writefln("Field.opAssign(%s)", a); } } struct

Re: implimenting interface function by inheriting from other class

2021-08-21 Thread Tejas via Digitalmars-d-learn
On Sunday, 22 August 2021 at 01:14:08 UTC, Alexey wrote: On Saturday, 21 August 2021 at 20:35:43 UTC, Alexey wrote: Hello ```D interface Int { void coolFunc(); } class C1 { void coolFunc() { return; } } class C2 : C1, Int { } void main() { auto c = new C2; } ```

Re: D equivalent of C++ explicit

2021-08-20 Thread Tejas via Digitalmars-d-learn
On Friday, 20 August 2021 at 05:43:49 UTC, evilrat wrote: On Thursday, 19 August 2021 at 18:04:58 UTC, Tejas wrote: On Thursday, 19 August 2021 at 17:43:59 UTC, Paul Backus wrote: On Thursday, 19 August 2021 at 17:38:14 UTC, Tejas wrote: As the topic says: Is there an equivalent to C++'s

Re: Drawbacks of exceptions being globally allocated

2021-08-15 Thread Tejas via Digitalmars-d-learn
On Sunday, 15 August 2021 at 16:23:25 UTC, Ali Çehreli wrote: On 8/15/21 2:10 AM, Alexandru Ermicioi wrote: >> This may be useful in some cases but in general, these colatteral >> exceptions don't carry much information and I don't think anybody >> looks at them. Usually, the first one is the

Re: Anyway to achieve the following

2021-08-13 Thread Tejas via Digitalmars-d-learn
On Friday, 13 August 2021 at 08:25:33 UTC, JG wrote: Suppose one has a pointer p of type T*. Can on declare variable a of type T which is stored in the location pointed to by p? As an example if we have: struct S { int x = 1234; } void main() { S s;

Re: Getting a working example of opIndexAssign using opSlice ... have troubles ...

2021-08-16 Thread Tejas via Digitalmars-d-learn
On Monday, 16 August 2021 at 06:36:02 UTC, james.p.leblanc wrote: On Monday, 16 August 2021 at 06:20:11 UTC, Tejas wrote: Maybe just write `T[]` in code rather than making it happen via the colon? I also have similar troubles, removing the default value always helped me. Can you show the

Re: Drawbacks of exceptions being globally allocated

2021-08-16 Thread Tejas via Digitalmars-d-learn
On Monday, 16 August 2021 at 05:47:10 UTC, Mathias LANG wrote: On Monday, 16 August 2021 at 05:36:07 UTC, Tejas wrote: That is why I was using heapAllocate, because using `new` on scope allocates exception on stack, and if you exit, then the exception is basically freed before it even gets

Re: Drawbacks of exceptions being globally allocated

2021-08-16 Thread Tejas via Digitalmars-d-learn
On Monday, 16 August 2021 at 06:17:22 UTC, Alexandru Ermicioi wrote: On Monday, 16 August 2021 at 06:12:14 UTC, Tejas wrote: ... Fyi, check out std.exeprimental.allocator package. You can use allocators from there to do allocation of exceptions, on the heap or any other region. Yes, I

Re: Getting a working example of opIndexAssign using opSlice ... have troubles ...

2021-08-16 Thread Tejas via Digitalmars-d-learn
On Monday, 16 August 2021 at 06:49:08 UTC, james.p.leblanc wrote: On Monday, 16 August 2021 at 06:42:48 UTC, Tejas wrote: If the code works, what's the problem? Hej Again, I was able to construct the working code shown above from help I obtained here in the forum and other resources. My

Re: Drawbacks of exceptions being globally allocated

2021-08-15 Thread Tejas via Digitalmars-d-learn
On Sunday, 15 August 2021 at 20:23:03 UTC, Paul Backus wrote: On Sunday, 15 August 2021 at 18:47:27 UTC, Tejas wrote: Do you see anything wrong with the following `emplace`-allocated, RAII following exceptions: [...] Is this good enough for general use now? Any other drawbacks? It only

Re: Drawbacks of exceptions being globally allocated

2021-08-15 Thread Tejas via Digitalmars-d-learn
On Sunday, 15 August 2021 at 20:23:03 UTC, Paul Backus wrote: On Sunday, 15 August 2021 at 18:47:27 UTC, Tejas wrote: Do you see anything wrong with the following `emplace`-allocated, RAII following exceptions: [...] Is this good enough for general use now? Any other drawbacks? It only

Re: Getting a working example of opIndexAssign using opSlice ... have troubles ...

2021-08-16 Thread Tejas via Digitalmars-d-learn
On Monday, 16 August 2021 at 06:12:42 UTC, james.p.leblanc wrote: On Monday, 16 August 2021 at 05:26:00 UTC, Tejas wrote: If you're finding the spec too hard, please try Ali's book. I'm sharing the part on operator overloading below: http://ddili.org/ders/d.en/operator_overloading.html

Re: Getting a working example of opIndexAssign using opSlice ... have troubles ...

2021-08-15 Thread Tejas via Digitalmars-d-learn
On Sunday, 15 August 2021 at 20:41:51 UTC, james.p.leblanc wrote: Greetings, I have been trying to get a working example of slice assignment operator overloading ... and am befuddled. From the spec (section 20.6.2), the code below appears: struct A { int opIndexAssign(int

Re: simple (I think) eponymous template question ... what is proper idimatic way ?

2021-08-18 Thread Tejas via Digitalmars-d-learn
On Wednesday, 18 August 2021 at 05:33:13 UTC, james.p.leblanc wrote: On Tuesday, 17 August 2021 at 20:28:20 UTC, Alexandru Ermicioi wrote: On Tuesday, 17 August 2021 at 19:53:52 UTC, james.p.leblanc wrote: Wow! That is absolutely beautiful ... I had never seen (or even imagined) a recursive

Re: partial initialization of fixed size ("static") arrays

2021-08-14 Thread Tejas via Digitalmars-d-learn
On Saturday, 14 August 2021 at 09:40:54 UTC, kdevel wrote: Today I stumbled across three issues with partial initialization of "static" arrays: ~~~i1.d void main () { char [7] b = [ 1: 'x' ]; // okay char [7] a = [ 0: 'x' ]; // i1.d(4): Error: mismatched array lengths, 7 and 1 } ~~~

Re: Drawbacks of exceptions being globally allocated

2021-08-14 Thread Tejas via Digitalmars-d-learn
On Saturday, 14 August 2021 at 11:41:36 UTC, Tejas wrote: What is the drawback of the following "simple" ```@nogc``` exception creation technique? ```d import std; void main()@nogc { try{ __gshared a = new Exception("help"); scope b = a; throw b; }

Re: partial initialization of fixed size ("static") arrays

2021-08-14 Thread Tejas via Digitalmars-d-learn
On Saturday, 14 August 2021 at 14:04:47 UTC, kdevel wrote: On Saturday, 14 August 2021 at 13:01:13 UTC, frame wrote: I would say case [...] 3 is not [a bug]. It's just the element type conversion and mismatched lengths of the ranges. ~~~ char [7] d7 = "x"; // okay string s = "x";

Re: Create alias of same name in inner scope, bug or feature?

2021-08-14 Thread Tejas via Digitalmars-d-learn
On Saturday, 14 August 2021 at 08:23:20 UTC, user1234 wrote: On Saturday, 14 August 2021 at 04:09:34 UTC, Tejas wrote: [...] Oh right, the ```.``` operator will reference variable in the _module_ scope, not just the _immediate outer scope_, you can use the module name to disambiguate as

Drawbacks of exceptions being globally allocated

2021-08-14 Thread Tejas via Digitalmars-d-learn
What is the drawback of the following "simple" ```@nogc``` exception creation technique? ```d import std; void main()@nogc { try{ __gshared a = new Exception("help"); scope b = a; throw b; } catch(Exception e){ printf("caught"); } } ```

Re: partial initialization of fixed size ("static") arrays

2021-08-14 Thread Tejas via Digitalmars-d-learn
On Saturday, 14 August 2021 at 13:01:13 UTC, frame wrote: On Saturday, 14 August 2021 at 09:40:54 UTC, kdevel wrote: Shall I file them to bugzilla? I would say case 2 and 3 are not bugs. It's just the element type conversion and mismatched lengths of the ranges. Not sure about the first

Re: partial initialization of fixed size ("static") arrays

2021-08-14 Thread Tejas via Digitalmars-d-learn
On Saturday, 14 August 2021 at 14:33:42 UTC, kdevel wrote: On Saturday, 14 August 2021 at 14:18:57 UTC, Tejas wrote: On Saturday, 14 August 2021 at 14:04:47 UTC, kdevel wrote: On Saturday, 14 August 2021 at 13:01:13 UTC, frame wrote: I would say case [...] 3 is not [a bug]. It's just the

Re: Create alias of same name in inner scope, bug or feature?

2021-08-13 Thread Tejas via Digitalmars-d-learn
On Saturday, 14 August 2021 at 04:01:31 UTC, Mike Parker wrote: On Saturday, 14 August 2021 at 03:47:05 UTC, Tejas wrote: ```d import std; auto abc(T)(auto ref T a, auto ref T b){ return a+b; } auto def(T)(auto ref T a, auto ref T b){ return a*b; } alias macro_1 = abc; void main()

Create alias of same name in inner scope, bug or feature?

2021-08-13 Thread Tejas via Digitalmars-d-learn
```d import std; auto abc(T)(auto ref T a, auto ref T b){ return a+b; } auto def(T)(auto ref T a, auto ref T b){ return a*b; } alias macro_1 = abc; void main() { writeln(macro_1(15, 20)); alias macro_1 = def;// is this NOT considered variable shadowing?

Re: Drawbacks of exceptions being globally allocated

2021-08-14 Thread Tejas via Digitalmars-d-learn
On Saturday, 14 August 2021 at 15:28:36 UTC, Alexandru Ermicioi wrote: On Saturday, 14 August 2021 at 13:24:22 UTC, Tejas wrote: ... I don't think there are any gotchas here. The problem with this technique, is when your exceptions aren't just simple labels but also carry some additional

Re: Lexicographical object comparison by selected members of a struct

2021-08-21 Thread Tejas via Digitalmars-d-learn
On Saturday, 21 August 2021 at 06:58:47 UTC, Ali Çehreli wrote: On 8/20/21 11:19 PM, Tejas wrote: [...] Yes. 'static foreach' does not introduce scope, which can be pretty useful. For example, one can define functions at module scope. The subtle differences between 'static foreach' and

Re: Lexicographical object comparison by selected members of a struct

2021-08-21 Thread Tejas via Digitalmars-d-learn
On Saturday, 21 August 2021 at 06:03:33 UTC, Ali Çehreli wrote: On 8/20/21 10:37 PM, Alexandru Ermicioi wrote: [...] Cool! Much better. :) I could not do [...] Did you use that double curly bracket in `static foreach` so that you don't get error for declaring stuff inside `static

Re: How to call destructor before free without dropping @nogc?

2021-08-19 Thread Tejas via Digitalmars-d-learn
On Thursday, 19 August 2021 at 09:39:26 UTC, evilrat wrote: On Thursday, 19 August 2021 at 08:25:23 UTC, Bienlein wrote: Oops, I just realized that you can also not call emplace when @nogc is present. Well that is at least consistent with not either being able to call destroy ;-). So, I

Re: Lexicographical object comparison by selected members of a struct

2021-08-21 Thread Tejas via Digitalmars-d-learn
On Saturday, 21 August 2021 at 13:45:59 UTC, Ali Çehreli wrote: On 8/21/21 1:31 AM, Tejas wrote: > I was more impressed that you found that hack in the first place I can't take credit. :) 'static foreach' had that difference since its inception. The spec says "If a new scope is desired for

Re: What exactly are the String literrals in D and how they work?

2021-08-15 Thread Tejas via Digitalmars-d-learn
On Sunday, 15 August 2021 at 08:51:19 UTC, rempas wrote: On Sunday, 15 August 2021 at 08:47:39 UTC, jfondren wrote: dup() isn't aware of the NUL since that's outside the slice of the string. It only copies the chars in "John". You can use toStringz to ensure NUL termination:

Re: D equivalent of C++ explicit

2021-08-19 Thread Tejas via Digitalmars-d-learn
On Thursday, 19 August 2021 at 18:11:20 UTC, Paul Backus wrote: On Thursday, 19 August 2021 at 18:04:58 UTC, Tejas wrote: On Thursday, 19 August 2021 at 17:43:59 UTC, Paul Backus wrote: On Thursday, 19 August 2021 at 17:38:14 UTC, Tejas wrote: As the topic says: Is there an equivalent to

D equivalent of C++ explicit

2021-08-19 Thread Tejas via Digitalmars-d-learn
As the topic says: Is there an equivalent to C++'s `explicit` keyword in D?

Re: D equivalent of C++ explicit

2021-08-19 Thread Tejas via Digitalmars-d-learn
On Thursday, 19 August 2021 at 17:43:59 UTC, Paul Backus wrote: On Thursday, 19 August 2021 at 17:38:14 UTC, Tejas wrote: As the topic says: Is there an equivalent to C++'s `explicit` keyword in D? No, because all constructors are explicit in D. Oh... then I guess I'll have to manually

Re: Drawbacks of exceptions being globally allocated

2021-08-14 Thread Tejas via Digitalmars-d-learn
On Sunday, 15 August 2021 at 00:15:32 UTC, Ali Çehreli wrote: On 8/14/21 4:41 AM, Tejas wrote: > [...] exception > [...] So, there would be many exception objects one for each place that an exception can be thrown. Functions like enforce() would have to take a reference to the exception

Re: Drawbacks of exceptions being globally allocated

2021-08-14 Thread Tejas via Digitalmars-d-learn
On Sunday, 15 August 2021 at 03:45:07 UTC, Mathias LANG wrote: On Sunday, 15 August 2021 at 02:09:08 UTC, Tejas wrote: [...] You can't really have `@nogc` allocated Exception without circumventing the type system. Personally I gave up on `@nogc` just because of how inconvenient it is.

Re: Drawbacks of exceptions being globally allocated

2021-08-14 Thread Tejas via Digitalmars-d-learn
On Saturday, 14 August 2021 at 23:14:51 UTC, Paul Backus wrote: On Saturday, 14 August 2021 at 15:58:17 UTC, Tejas wrote: If you're willing to help further, would you please tell me why there is a GC allocation in the code below that uses ```emplace```? Will such code truly work if GC is never

Re: Drawbacks of exceptions being globally allocated

2021-08-14 Thread Tejas via Digitalmars-d-learn
On Sunday, 15 August 2021 at 02:09:08 UTC, Tejas wrote: On Sunday, 15 August 2021 at 00:15:32 UTC, Ali Çehreli wrote: On 8/14/21 4:41 AM, Tejas wrote: > [...] exception > [...] So, there would be many exception objects one for each place that an exception can be thrown. Functions like

Re: Curious effect with traits, meta, and a foreach loop ... mystifies me.

2021-09-08 Thread Tejas via Digitalmars-d-learn
On Thursday, 9 September 2021 at 05:32:29 UTC, Tejas wrote: On Tuesday, 7 September 2021 at 17:47:15 UTC, james.p.leblanc wrote: [...] from what I understand you want to change the aligned data that you're referring to at runtime. ```d void main() { import

Re: Curious effect with traits, meta, and a foreach loop ... mystifies me.

2021-09-08 Thread Tejas via Digitalmars-d-learn
On Tuesday, 7 September 2021 at 17:47:15 UTC, james.p.leblanc wrote: On Tuesday, 7 September 2021 at 17:33:31 UTC, Adam D Ruppe wrote: On Tuesday, 7 September 2021 at 17:24:34 UTC, james.p.leblanc wrote: If you want to do a runtime lookup, you need to separate the two pieces. This pattern

Re: Program crash: GC destroys an object unexpectedly

2021-09-13 Thread Tejas via Digitalmars-d-learn
On Monday, 13 September 2021 at 18:42:47 UTC, Steven Schveighoffer wrote: On 9/13/21 1:54 PM, eugene wrote: [...] The GC only scans things that it knows about. Inside your EventQueue you have this code: [...] Umm is it okay that he declared variables `init` and `idle` of type `Stage`

Re: How can we view source code that has been generated (say via "static foreach") ?

2021-09-15 Thread Tejas via Digitalmars-d-learn
On Wednesday, 15 September 2021 at 19:59:43 UTC, james.p.leblanc wrote: Dear All, In attempting to learn and use code generation, it would be useful to be able to view the source code that gets generated. However, with various combinations of templates, UDAs, and mixins it has not been easy.

Re: Can we rely on LDC respecting "align" (for avx) ??

2021-09-07 Thread Tejas via Digitalmars-d-learn
On Wednesday, 8 September 2021 at 04:32:50 UTC, james.p.leblanc wrote: Dear All, In searching through the forum archives (going back to 2013, 2016 etc), and experiments, it **appears to me** that LDC does indeed respect the standard "align" properties. (Meaning: proper alignment for using

Re: Can we rely on LDC respecting "align" (for avx) ??

2021-09-07 Thread Tejas via Digitalmars-d-learn
On Wednesday, 8 September 2021 at 04:43:31 UTC, Tejas wrote: On Wednesday, 8 September 2021 at 04:32:50 UTC, james.p.leblanc wrote: [...] Yes you are correct (to my understanding) DMD only respects `align` keyword upto the value 16,ie, until `align(16)`, the code behaves the way you expect

Re: Reference Counted Class

2021-07-14 Thread Tejas via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 17:52:16 UTC, sclytrack wrote: Would reference counted classes by default be too much of a change? Is it a bad idea? Currently there a changes in the language where you can avoid the reference count, right? This isn't happening until DIP 1000 passes

Re: opIndexUnary post in-/decrement how to ?

2021-07-14 Thread Tejas via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 15:23:05 UTC, vit wrote: On Wednesday, 14 July 2021 at 15:19:03 UTC, vit wrote: ```d import std.stdio; struct abc{ int[100] a; struct Proxy{ abc* ptr; const int index; int opUnary(string op : "++")(){ return

Re: opIndexUnary post in-/decrement how to ?

2021-07-14 Thread Tejas via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 15:08:56 UTC, wjoe wrote: On Wednesday, 14 July 2021 at 14:50:01 UTC, Mike Parker wrote: On Wednesday, 14 July 2021 at 12:35:07 UTC, wjoe wrote: [...] It's how the contract of post-inc/dec work---pre-inc/dec return the modified value, post-inc/dec return the

Re: opIndexUnary post in-/decrement how to ?

2021-07-14 Thread Tejas via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 14:39:03 UTC, vit wrote: On Wednesday, 14 July 2021 at 13:16:49 UTC, Tejas wrote: On Wednesday, 14 July 2021 at 13:09:56 UTC, vit wrote: On Wednesday, 14 July 2021 at 12:49:58 UTC, Tejas wrote: [...] From doc: https://dlang.org/spec/operatoroverloading.html

Re: Reference Counted Class

2021-07-14 Thread Tejas via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 18:04:59 UTC, IGotD- wrote: On Wednesday, 14 July 2021 at 17:52:16 UTC, sclytrack wrote: Would reference counted classes by default be too much of a change? Is it a bad idea? Currently there a changes in the language where you can avoid the reference count, right?

Re: opIndexUnary post in-/decrement how to ?

2021-07-14 Thread Tejas via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 15:23:05 UTC, vit wrote: On Wednesday, 14 July 2021 at 15:19:03 UTC, vit wrote: ```d import std.stdio; struct abc{ int[100] a; struct Proxy{ abc* ptr; const int index; int opUnary(string op : "++")(){ return

Re: opIndexUnary post in-/decrement how to ?

2021-07-14 Thread Tejas via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 17:42:03 UTC, Ali Çehreli wrote: On 7/14/21 9:13 AM, Tejas wrote: > ref/*notice this ref*/ int opIndex(int index)return/*NOTICE THE > RETURN*/ { Indeed... I cover that 'ref' here:

Re: opIndexUnary post in-/decrement how to ?

2021-07-14 Thread Tejas via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 20:55:32 UTC, wjoe wrote: On Wednesday, 14 July 2021 at 16:13:35 UTC, Tejas wrote: [...] Congratulations:) Unfortunately I haven't got anything I could return by ref so I can't take advantage of a low hanging fruit. In my book overloading operators is no fun -

Re: opIndexUnary post in-/decrement how to ?

2021-07-14 Thread Tejas via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 20:55:32 UTC, wjoe wrote: In my particular case the compiler can rule out ```opIndex``` so why does it abort instead of trying ```opIndexUnary``` ? Or was it trying and it didn't work ? If that's the case I'd like to know the reason why it discarded

Re: opIndexUnary post in-/decrement how to ?

2021-07-15 Thread Tejas via Digitalmars-d-learn
On Thursday, 15 July 2021 at 11:02:17 UTC, wjoe wrote: On Thursday, 15 July 2021 at 04:07:49 UTC, Tejas wrote: Your code ```d auto x = i[1]++; ``` Expands to: ```d auto x = (auto e = i[1]/*notice opIndex*/, ++i[1]/* notice opIndexUnary*/, return e;); ``` This doesn't happen with pre

Re: cast to pure function stop work after upgrade

2021-08-02 Thread Tejas via Digitalmars-d-learn
On Monday, 2 August 2021 at 15:10:06 UTC, vit wrote: On Monday, 2 August 2021 at 11:28:46 UTC, Tejas wrote: [...] Try this: ```d void main(){ fp = cast(typeof(fp)) //fails } ``` Agh, stupid me. You the man!!

Re: cast to pure function stop work after upgrade

2021-08-02 Thread Tejas via Digitalmars-d-learn
On Monday, 14 June 2021 at 13:31:51 UTC, baby_tiger wrote: this used work for me, after upgrade I get this error. how to fix it ? import std.traits; enum LogLevel : ubyte { INFO = 0, WARN, ERROR,

Re: Find struct not passed by reference

2021-08-03 Thread Tejas via Digitalmars-d-learn
On Tuesday, 3 August 2021 at 12:23:38 UTC, frame wrote: On Tuesday, 3 August 2021 at 11:55:51 UTC, Paul Backus wrote: You can't assign a `ref` to a variable; if you try, a copy is created. What you can do instead is use a pointer: ```d Unique!myType* rs = (); ``` Thanks. I feared that. So

Re: writef, compile-checked format, pointer

2021-08-10 Thread Tejas via Digitalmars-d-learn
On Tuesday, 10 August 2021 at 05:03:12 UTC, nov wrote: every time i try to use templates, i have problems :( That is why C++ introduced concepts. Wonder when D will be getting them :(

D has the same memory model as C++

2021-08-10 Thread Tejas via Digitalmars-d-learn
What exactly does the above statement mean? Also, I have read here a principle that **If it looks like C, it behaves like C** How true is that for C++? Does code that look like C++(minus obvious syntax differences) behave like C++? Does having the same memory model help? Thanks for

Re: Generating C Headers From D Code

2021-08-05 Thread Tejas via Digitalmars-d-learn
On Thursday, 5 August 2021 at 17:02:33 UTC, Tejas wrote: On Thursday, 5 August 2021 at 16:28:35 UTC, Jack Stouffer wrote: [...] I also can't find anything... until someone else comes with a better answer, maybe you can do this: Use the ```-H``` compiler flag to generate ```.di``` files.

Re: Generating C Headers From D Code

2021-08-05 Thread Tejas via Digitalmars-d-learn
On Thursday, 5 August 2021 at 16:28:35 UTC, Jack Stouffer wrote: I need to generate plain C99 .h files from a D module's extern(C) declarations, so that I can link a DMD generated .o file with a C code base. Are there any automated tools which do this? I know the compiler has C++ header

Re: Setting a hard limit on slice size, is this possible?

2021-08-07 Thread Tejas via Digitalmars-d-learn
On Friday, 6 August 2021 at 22:15:00 UTC, Paul Backus wrote: On Friday, 6 August 2021 at 19:03:53 UTC, Tejas wrote: Stealing Paul's answer now: ```d import std; enum your_max_length = 1000; enum your_align = 256; struct MySlice(T/*, size_t maxLength*/) { private align(your_align)T

Re: Setting a hard limit on slice size, is this possible?

2021-08-07 Thread Tejas via Digitalmars-d-learn
On Saturday, 7 August 2021 at 13:36:52 UTC, james.p.leblanc wrote: On Saturday, 7 August 2021 at 12:08:00 UTC, Paul Backus wrote: [...] **First, thanks all for helping with this question!** The simple desire to arbitrarily align an array is certainly looking non-trivial. Below is a simple

Re: Setting a hard limit on slice size, is this possible?

2021-08-07 Thread Tejas via Digitalmars-d-learn
On Saturday, 7 August 2021 at 13:36:52 UTC, james.p.leblanc wrote: On Saturday, 7 August 2021 at 12:08:00 UTC, Paul Backus wrote: [...] **First, thanks all for helping with this question!** The simple desire to arbitrarily align an array is certainly looking non-trivial. Below is a simple

Re: Setting a hard limit on slice size, is this possible?

2021-08-07 Thread Tejas via Digitalmars-d-learn
On Saturday, 7 August 2021 at 15:21:01 UTC, Paul Backus wrote: On Saturday, 7 August 2021 at 14:34:49 UTC, Tejas wrote: [...] For the array as a whole to be aligned, not only must the spacing between the elements respect the alignment, but starting address of the array itself must be a

Re: Setting a hard limit on slice size, is this possible?

2021-08-07 Thread Tejas via Digitalmars-d-learn
On Saturday, 7 August 2021 at 19:07:04 UTC, Paul Backus wrote: On Saturday, 7 August 2021 at 15:41:24 UTC, Tejas wrote: On Saturday, 7 August 2021 at 15:21:01 UTC, Paul Backus wrote: [...] Oh wow, and here I thought I was being smart :( So, how can we work around this without assembly

Re: D has the same memory model as C++

2021-08-10 Thread Tejas via Digitalmars-d-learn
On Tuesday, 10 August 2021 at 13:18:24 UTC, Paul Backus wrote: On Tuesday, 10 August 2021 at 11:05:53 UTC, Tejas wrote: Also, I have read here a principle that **If it looks like C, it behaves like C** How true is that for C++? Does code that look like C++(minus obvious syntax differences)

Re: D has the same memory model as C++

2021-08-10 Thread Tejas via Digitalmars-d-learn
On Tuesday, 10 August 2021 at 18:07:35 UTC, Bastiaan Veelo wrote: On Tuesday, 10 August 2021 at 16:00:37 UTC, Tejas wrote: there's casting away const, a clearly seperate language feature which has no equivalent in D; You *can* cast away `const` in D: https://run.dlang.io/is/sWa5Mf —

No compile time bounds checking for static arrays?

2021-08-11 Thread Tejas via Digitalmars-d-learn
```d import std; void main() { int[40] staticA; auto c = staticA[0..50];//mistake }``` results in: ```d core.exception.RangeError@onlineapp.d(5): Range violation ??:? _d_arrayboundsp [0x55db29a0b645] ./onlineapp.d:5 _Dmain [0x55db29a0ae8c] ``` Is there a way to make

Re: D has the same memory model as C++

2021-08-10 Thread Tejas via Digitalmars-d-learn
On Tuesday, 10 August 2021 at 21:19:39 UTC, Bastiaan Veelo wrote: On Tuesday, 10 August 2021 at 16:00:37 UTC, Tejas wrote: Basically, what are the subtle gotcha's in the differences between C++ and D code that looks similar The only gotcha that comes to my mind is that `private` means

Re: No compile time bounds checking for static arrays?

2021-08-11 Thread Tejas via Digitalmars-d-learn
On Wednesday, 11 August 2021 at 06:46:34 UTC, Stefan Koch wrote: On Wednesday, 11 August 2021 at 06:29:40 UTC, Tejas wrote: ```d import std; void main() { int[40] staticA; auto c = staticA[0..50];//mistake }``` results in: ```d core.exception.RangeError@onlineapp.d(5): Range violation

Re: I do not understand copy constructors

2021-08-12 Thread Tejas via Digitalmars-d-learn
On Thursday, 12 August 2021 at 11:54:22 UTC, Learner wrote: On Thursday, 12 August 2021 at 10:10:17 UTC, rikki cattermole wrote: On 12/08/2021 9:36 PM, Learner wrote: It seems that there is no easy way to transition from a postblit to a copy constructor, no? struct Foo { this(ref

Re: I do not understand copy constructors

2021-08-12 Thread Tejas via Digitalmars-d-learn
On Thursday, 12 August 2021 at 15:39:40 UTC, Learner wrote: On Thursday, 12 August 2021 at 14:57:16 UTC, Steven Schveighoffer wrote: [...] It is not clear to me why the inout generated copy constructor of the B structure is not able to copy the A structure. [...] Why will copy

Re: I do not understand copy constructors

2021-08-12 Thread Tejas via Digitalmars-d-learn
On Thursday, 12 August 2021 at 12:28:32 UTC, Learner wrote: On Thursday, 12 August 2021 at 12:22:22 UTC, Tejas wrote: On Thursday, 12 August 2021 at 12:19:56 UTC, Tejas wrote: [...] Works with ```@safe``` as well Paul was just trying to make that other answer work, you don't have to make

Re: I do not understand copy constructors

2021-08-12 Thread Tejas via Digitalmars-d-learn
On Thursday, 12 August 2021 at 12:19:56 UTC, Tejas wrote: On Thursday, 12 August 2021 at 11:54:22 UTC, Learner wrote: [...] Just add ```inout``` inside ```this(ref inout/*notice the inout*/ Foo other) inout/*notice the inout*/``` Example code: ```d struct Foo { this(ref inout Foo

Re: Unnable to join Discord

2021-08-12 Thread Tejas via Digitalmars-d-learn
On Thursday, 12 August 2021 at 18:11:20 UTC, nayy wrote: Hi I cannot seems to be able to join the discord server It gives me the following error: "unable to accept invit" Is the invitation link expired? https://dlang.org/community.html https://discord.gg/bMZk9Q4 I joined last week with the

Re: Why are class methods not allowed to call cons/destructors?

2021-07-31 Thread Tejas via Digitalmars-d-learn
On Saturday, 31 July 2021 at 13:57:40 UTC, kinke wrote: This is possible via: ``` __dtor(); super.__dtor(); ``` WHOO YEAH!!! THANK YOU SO MUCH :D

Why are class methods not allowed to call cons/destructors?

2021-07-31 Thread Tejas via Digitalmars-d-learn
```d class A{ ~this(){} destructA(){ ~this() } } class B:A{ ~this(){} destructB(){ ~this(); ~super(); } } ``` This could allow ```@nogc``` crowd to run destructors without calling ```destroy```. Yes, derived to base conversion is still a thing and

Re: Why are class methods not allowed to call cons/destructors?

2021-07-31 Thread Tejas via Digitalmars-d-learn
On Saturday, 31 July 2021 at 13:34:25 UTC, user1234 wrote: On Saturday, 31 July 2021 at 13:12:21 UTC, Tejas wrote: ```d class A{ ~this(){} destructA(){ ~this() } } class B:A{ ~this(){} destructB(){ ~this(); ~super(); } } ``` This could allow

Re: Routing of AssertError messages

2021-07-31 Thread Tejas via Digitalmars-d-learn
On Saturday, 31 July 2021 at 12:03:49 UTC, DLearner wrote: Hi This may be due to Windows, not DMD. Please see code below (held in test.d): ``` void main() { import std.stdio; writeln("Test"); assert(false, "TestAssert"); } ``` ` dmd -i -run test.d ` results in both "Test" and the

Re: Why are class methods not allowed to call cons/destructors?

2021-07-31 Thread Tejas via Digitalmars-d-learn
On Saturday, 31 July 2021 at 13:34:25 UTC, user1234 wrote: On Saturday, 31 July 2021 at 13:12:21 UTC, Tejas wrote: ```d class A{ ~this(){} destructA(){ ~this() } } class B:A{ ~this(){} destructB(){ ~this(); ~super(); } } ``` This could allow

Re: translate C struct char array into D

2021-07-30 Thread Tejas via Digitalmars-d-learn
On Friday, 30 July 2021 at 14:40:17 UTC, Paul Backus wrote: On Friday, 30 July 2021 at 14:05:58 UTC, workman wrote: [...] `char data[]` in the C struct is not a pointer, but actually a [C99 flexible array member][1], and does not count towards the struct's `sizeof`. D does not have

Re: translate C struct char array into D

2021-07-30 Thread Tejas via Digitalmars-d-learn
On Friday, 30 July 2021 at 14:40:17 UTC, Paul Backus wrote: On Friday, 30 July 2021 at 14:05:58 UTC, workman wrote: [...] `char data[]` in the C struct is not a pointer, but actually a [C99 flexible array member][1], and does not count towards the struct's `sizeof`. D does not have

Re: Setting a hard limit on slice size, is this possible?

2021-08-06 Thread Tejas via Digitalmars-d-learn
On Friday, 6 August 2021 at 10:50:19 UTC, james.p.leblanc wrote: I am aware of the "capacity" concept with slices. But, I would like to know if it is possible to set a hard limit on a slice size. I prefer it to error and crash instead of a doing an extension or reallocation. I understand my

Re: Setting a hard limit on slice size, is this possible?

2021-08-06 Thread Tejas via Digitalmars-d-learn
On Friday, 6 August 2021 at 16:32:59 UTC, james.p.leblanc wrote: On Friday, 6 August 2021 at 11:58:59 UTC, Paul Backus wrote: struct MySlice(T, size_t maxLength) { private T[] payload; invariant(payload.length <= maxLength); this(T[] slice) { payload = slice; } T opIndex(size_t

Re: Setting a hard limit on slice size, is this possible?

2021-08-06 Thread Tejas via Digitalmars-d-learn
On Friday, 6 August 2021 at 17:16:28 UTC, Tejas wrote: On Friday, 6 August 2021 at 16:32:59 UTC, james.p.leblanc wrote: On Friday, 6 August 2021 at 11:58:59 UTC, Paul Backus wrote: [...] ``` Paul, Thanks very much for your reply. I understand only a fraction of the suggested solution. I

Re: Setting a hard limit on slice size, is this possible?

2021-08-06 Thread Tejas via Digitalmars-d-learn
On Friday, 6 August 2021 at 18:02:01 UTC, james.p.leblanc wrote: mes On Friday, 6 August 2021 at 17:25:24 UTC, Tejas wrote: Okay we were overthinking the solution. Just use a static array ```d int[your_max_length]/*or whatever type*/ var; ``` You're good to go! I almost feel stupid now lol

Re: D has the same memory model as C++

2021-08-11 Thread Tejas via Digitalmars-d-learn
On Wednesday, 11 August 2021 at 19:04:50 UTC, Ali Çehreli wrote: This is an interesting thread but "memory model" does not cover or mean all of the points discussed here. I can't define it precisely, so I'm leaving it to interested parties to search for themselves. :) Ali A little bit of

Re: D has the same memory model as C++

2021-08-11 Thread Tejas via Digitalmars-d-learn
On Wednesday, 11 August 2021 at 19:27:34 UTC, Ali Çehreli wrote: On 8/11/21 12:19 PM, Tejas wrote: Atleast leave some pointers on where to start :( I DuckDuckGo'ed it for you. :) https://en.cppreference.com/w/cpp/language/memory_model Then looked it up at Wikipedia too:

Re: Why dtor are not executed when removing a struct from associative arrays?

2021-09-20 Thread Tejas via Digitalmars-d-learn
On Monday, 20 September 2021 at 13:48:01 UTC, Tejas wrote: On Monday, 20 September 2021 at 12:23:00 UTC, Learner wrote: [...] I think it *is* being called: ```d import std.stdio; struct S { int a; this(int param){ a = param; } ~this() {

Re: Why dtor are not executed when removing a struct from associative arrays?

2021-09-20 Thread Tejas via Digitalmars-d-learn
On Monday, 20 September 2021 at 12:23:00 UTC, Learner wrote: I was expecting something like going out of scope for that ```(D) import std.stdio; struct S { ~this() { writeln("S is being destructed"); } } void main() { S[int] aa; aa[1] = S(); aa.remove(1);

Re: Why dtor are not executed when removing a struct from associative arrays?

2021-09-20 Thread Tejas via Digitalmars-d-learn
On Monday, 20 September 2021 at 14:03:09 UTC, Tejas wrote: On Monday, 20 September 2021 at 13:48:01 UTC, Tejas wrote: On Monday, 20 September 2021 at 12:23:00 UTC, Learner wrote: [...] I think it *is* being called: ```d import std.stdio; struct S { int a; this(int param){

Re: automatic NaN propogation detection?

2021-09-25 Thread Tejas via Digitalmars-d-learn
On Saturday, 25 September 2021 at 08:18:49 UTC, Elronnd wrote: (Not saying @live isn't useless, just that this doesn't indicate that.) Must we continue hurting Walter's feelings :(

  1   2   3   >