Re: Why is Phobos `Flag` so overthought ?

2024-05-11 Thread cc via Digitalmars-d-learn
On Thursday, 9 May 2024 at 18:48:12 UTC, Nick Treleaven wrote: We have a tool in our box already called `true` and that solves the problem. If we had to type out the full name of every argument passed to every function ever written we may as well just adopt ObjC Cocoa style and call it

Re: Why is Phobos `Flag` so overthought ?

2024-05-09 Thread cc via Digitalmars-d-learn
On Wednesday, 8 May 2024 at 10:24:07 UTC, Nick Treleaven wrote: On Wednesday, 8 May 2024 at 04:27:13 UTC, cc wrote: It doesn't allow a simple boolean to be used as an argument, or any other Flag as they are different instantiations of a template rather than equivalent aliases. It is however

Re: Why is Phobos `Flag` so overthought ?

2024-05-07 Thread cc via Digitalmars-d-learn
On Monday, 6 May 2024 at 17:55:49 UTC, user1234 wrote: I think this just works: ```d enum Flag : bool { no, yes } ``` ... must be a reason but I cant find it RN ;) In "properly" designed Phobos packages, it's unambiguous. Take for example std.datetime.stopwatch: ```d import

Re: Adapting foreign iterators to D ranges

2024-04-24 Thread cc via Digitalmars-d-learn
On Wednesday, 24 April 2024 at 05:08:25 UTC, Salih Dincer wrote: Yes, `opApply()` works! You just need to use `do while()` instead of `while()` because it skips the first item. It depends on the type of structure being consumed, if it provides "next" as a direct pointer then yeah you would

Re: Adapting foreign iterators to D ranges

2024-04-23 Thread cc via Digitalmars-d-learn
On Monday, 22 April 2024 at 11:36:43 UTC, Chloé wrote: I wish to adapt this interface to a forward range for use with foreach and Phobos' range utilities. This amounts to implementing empty, front, and popFront, in terms of next and some state. But there is a choice to be made regarding the

Re: Making one struct work in place of another for function calls.

2024-04-17 Thread cc via Digitalmars-d-learn
On Wednesday, 17 April 2024 at 03:13:46 UTC, Liam McGillivray wrote: On Wednesday, 17 April 2024 at 02:39:25 UTC, Paul Backus wrote: This is called [row polymorphism][1], and it does not exist in D. You could approximate it by making `someFunction` a template, and accepting any type `T` that

Re: Opinions on iterating a struct to absorb the decoding of a CSV?

2024-03-31 Thread cc via Digitalmars-d-learn
On Monday, 1 April 2024 at 04:54:46 UTC, cc wrote: I scoured [Traits](https://dlang.org/spec/traits.html) and [std.traits](https://dlang.org/phobos/std_traits.html) looking for a simple method to tell whether a member was declared as enum but couldn't find one, so if anyone knows a proper way

Re: Opinions on iterating a struct to absorb the decoding of a CSV?

2024-03-31 Thread cc via Digitalmars-d-learn
On Thursday, 28 March 2024 at 17:23:39 UTC, Andy Valencia wrote: I wanted a lightweight and simpler CSV decoder. I won't post the whole thing, but basically you instantiate one as: That's pretty much the best way to do it. While `.tupleof` does look kind of hacky, and you could instead

Re: Deriving a struct from another one via template: Easy way to propagate UDAs?

2024-03-15 Thread cc via Digitalmars-d-learn
On Thursday, 14 March 2024 at 23:19:37 UTC, Inkrementator wrote: I am trying to derive a struct from another. I want to modify each field such that type of it goes from some T to Nullable!T, preserving all fieldnames and UDAs. This is trivially easy if your types are visible at module level,

Re: Can a D library have some types determined by the client program?

2024-03-10 Thread cc via Digitalmars-d-learn
On Saturday, 9 March 2024 at 22:03:34 UTC, Liam McGillivray wrote: Secondly, I found out that interfaces can't have variables. What!? That's crazy! Why wouldn't they? They totally should. Doesn't this mean that I will need to use getter and setter functions instead of direct access when using

Re: Can a D library have some types determined by the client program?

2024-03-08 Thread cc via Digitalmars-d-learn
On Friday, 8 March 2024 at 06:03:51 UTC, Liam McGillivray wrote: A problem I have is that the 3 classes Map, Tile, and Unit reference each-other. If I turn Map into a template, than it complains about the member variable of Unit declared as `Map map;` without arguments. I change this line to

Re: Hidden members of Class objects

2024-03-07 Thread cc via Digitalmars-d-learn
On Thursday, 7 March 2024 at 00:38:30 UTC, Richard (Rikki) Andrew Cattermole wrote: On 07/03/2024 1:28 PM, Carl Sturtivant wrote: On Wednesday, 6 March 2024 at 23:45:00 UTC, H. S. Teoh wrote: In D, there's a pointer to the vtable and another pointer to a Monitor object (used for synchronized

Re: Searching for i" in the forum

2024-02-26 Thread cc via Digitalmars-d-learn
On Sunday, 25 February 2024 at 01:19:15 UTC, Lysander wrote: On Friday, 23 February 2024 at 23:18:12 UTC, kdevel wrote: How do I search for i" in the forum? I get the following errors: i" -> Error: malformed MATCH expression: [i"] (1) i\" -> Error: malformed MATCH expression: [i\"]

Re: How can i find my LAN IP Address using std.socket?

2024-02-18 Thread cc via Digitalmars-d-learn
On Tuesday, 4 February 2014 at 13:02:26 UTC, TheFlyingFiddle wrote: I'm trying to find my own ip address using std.socket with little success. How would i go about doing this? (It should be a AddressFamily.INET socket) On Windows, you can use the Win32`GetAdaptersInfo`[1] function to get a

Re: Generating custom toString for structs

2024-01-11 Thread cc via Digitalmars-d-learn
On Thursday, 11 January 2024 at 12:45:45 UTC, cc wrote: I don't use the delegate version personally, but if that's already working for you, may as well stick with it. In retrospect, that delegate version is probably quite a bit better.

Re: Generating custom toString for structs

2024-01-11 Thread cc via Digitalmars-d-learn
On Sunday, 7 January 2024 at 09:49:36 UTC, Renato wrote: Hi, I wanted to customize the toString implementation for my structs. So I wrote a mixin for doing that: Alternative format similar to what you already have: ```d import std.format; mixin template ToStringMixin() { void

Re: Checking path name

2023-12-14 Thread cc via Digitalmars-d-learn
On Thursday, 14 December 2023 at 09:38:30 UTC, Joel wrote: On Thursday, 14 December 2023 at 08:47:49 UTC, Anonymouse wrote: On Thursday, 14 December 2023 at 03:58:37 UTC, Joel wrote: https://dlang.org/phobos/std_path.html#isValidPath https://dlang.org/phobos/std_path.html#.isValidFilename

Re: Safer binary reading (or writing) code

2023-12-13 Thread cc via Digitalmars-d-learn
On Tuesday, 12 December 2023 at 09:43:39 UTC, Joel wrote: I've got this mixin thing, I think it's less typo-prone. I haven't been able to make it show the variable's name, though. Also, it should be optional whether it prints anything, (it's not hard for me to do that though). ```d //

Re: Getting all struct members and values with introspection avoiding string mixins

2023-10-05 Thread cc via Digitalmars-d-learn
On Sunday, 1 May 2016 at 09:42:37 UTC, ParticlePeter wrote: I am logging arbitrary POD struct types with member names and data: void printStructInfo( T )( T info ) { foreach( i, A; typeof( T.tupleof )) { enum attribName = T.tupleof[i].stringof; writefln( "%s : %s", attribName, mixin(

Re: How to get all modules in a package at CT?

2023-10-05 Thread cc via Digitalmars-d-learn
On Thursday, 5 October 2023 at 20:42:26 UTC, mw wrote: On Thursday, 5 October 2023 at 20:07:38 UTC, user1234 wrote: No. Sorry. Generally compile time code cannot interact with the system. To be evaluable at compile time code has to be strongly pure, that is not the case of the function you

Re: Cool pattern or tragic?

2023-09-24 Thread cc via Digitalmars-d-learn
On Friday, 25 August 2023 at 21:00:08 UTC, Guillaume Piolat wrote: The idea is to deliberately mark @system functions that need special scrutiny to use, regardless of their memory-safety. Function that would typically be named `assumeXXX`. ... That way, @safe code will still need to manually

Re: Setting struct as default parameter of a function using struct literal?

2023-09-12 Thread cc via Digitalmars-d-learn
On Monday, 11 September 2023 at 17:51:04 UTC, BoQsc wrote: I would like to set function's default struct for a function in a way that it would be visible for the reader to see what options are set. Something like `Options option = {silenceErrors: false}` If the function's defaults will

Re: Which D compiler is the most maintained and future-proof? [DMD GDC and LDC]

2023-07-24 Thread cc via Digitalmars-d-learn
On Monday, 24 July 2023 at 09:29:09 UTC, Richard (Rikki) Andrew Cattermole wrote: There isn't a huge concern with which one you use. Its quite common to use dmd for development, and ldc for release for example. They all share the same frontend, so they really only differ between them by

Re: How do I generate `setX` methods for all private mutable variables in a class?

2023-06-05 Thread cc via Digitalmars-d-learn
On Monday, 5 June 2023 at 13:57:20 UTC, Ki Rill wrote: How do I generate `setX` methods for all private mutable variables in my class? Do I need to use `__traits`? ```d mixin template GenerateSetters() { static foreach (idx, field; typeof(this).tupleof) static if

Re: Idiomatic D using GC as a library writer

2022-12-05 Thread cc via Digitalmars-d-learn
On Sunday, 4 December 2022 at 09:53:41 UTC, vushu wrote: What are your thoughts about using GC as a library writer? If your program runs, does some stuff, and terminates, use the GC. If your program runs, stays up for a while with user occasionally interacting with it, use the GC. If your

Re: aa.keys, synchronized and shared

2022-11-10 Thread cc via Digitalmars-d-learn
On Friday, 11 November 2022 at 01:09:54 UTC, torhu wrote: On Thursday, 10 November 2022 at 21:55:26 UTC, torhu wrote: I'm trying to make a more thread-safe wrapper for AA's: ``` synchronized final class SyncAA(K, V) /// I chose to fix this by just using `synchronized (this)` inside each

DConf '22: No-Allocated 0-terminated path strings

2022-10-21 Thread cc via Digitalmars-d-learn
Catching up on the DConf '22 videos, really enjoyed the tricks Walter presents here for no-allocation strings: [DConf '22: Strawberries and Cream aka Delightful Emergent Properties of D -- Walter Bright](https://www.youtube.com/watch?v=iuP-AWUyjp8) In the Q segment, the first question asked

Does the GC prioritize same-class when looking for things to free?

2022-09-15 Thread cc via Digitalmars-d-learn
Why is Foo never deallocated here? (`DMD32 D Compiler v2.099.0-dirty` win64) ```d class Foo { string s; static size_t count, alloced, dealloced; this() { "+Foo".writeln; count++; alloced++; } ~this() {

Re: synchronized/shared associative array .require error

2022-09-04 Thread cc via Digitalmars-d-learn
On Saturday, 3 September 2022 at 14:37:16 UTC, Steven Schveighoffer wrote: On 9/2/22 3:15 PM, cc wrote: Tried casting away shared as a workaround but I assume that will cause some kind of TLS catastrophe. I think it will be fine, but you may have an issue. You are returning a non-shared

synchronized/shared associative array .require error

2022-09-02 Thread cc via Digitalmars-d-learn
```d synchronized class SyncTable(KEY, VAL) { private VAL[KEY] table; auto require(KEY key) { return table.require(key); } } auto table = new shared SyncTable!(string, string); table.require("abc"); ``` Fails to compile: ``` // Error: none of the

Re: How to call a function from a dll created with d ?

2022-07-07 Thread cc via Digitalmars-d-learn
On Sunday, 3 July 2022 at 09:43:20 UTC, frame wrote: app.d: ```d module app; import dimedll; import std.stdio; import std.stdio : log = writeln; pragma(lib, "dimedll.lib"); void main() { log("Lets build our own ime"); testFunc(); } ``` You should be able to change contents

getSymbolsByUDA in constructor/member functions

2022-06-15 Thread cc via Digitalmars-d-learn
```d import std.traits; class XML {} class Def { @XML { int x; int y; } int z; this() { static foreach (sym; getSymbolsByUDA!(Def, XML)) { } } } void main() { auto def = new Def; }

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

2022-05-24 Thread cc via Digitalmars-d-learn
On Tuesday, 24 May 2022 at 02:55:06 UTC, Tejas wrote: 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` Interesting, thanks.

How to call destroy() in @nogc?

2022-05-23 Thread cc via Digitalmars-d-learn
```d import core.memory; import core.stdc.stdlib : malloc, free; import core.lifetime : emplace; T NEW(T, Args...)(auto ref Args args) /*@nogc*/ if (is(T == class)) { enum size = __traits(classInstanceSize, T); void* mem = malloc(size); scope(failure) free(mem);

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

2022-05-17 Thread cc via Digitalmars-d-learn
On Monday, 16 May 2022 at 15:08:15 UTC, H. S. Teoh wrote: If you find yourself having to cast to/from immutable, you're using it wrong. I clearly was, which is why I'm not using it anymore. The question was "What are you stuck at? What was the most difficult features to understand? etc.", so

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

2022-05-15 Thread cc via Digitalmars-d-learn
On Wednesday, 11 May 2022 at 05:41:35 UTC, Ali Çehreli wrote: What are you stuck at? What was the most difficult features to understand? etc. To make it more meaningful, what is your experience with other languages? Ali Immutability. Ended up having to do so many hundreds of casts to

Re: How to use destroy and free.

2022-05-04 Thread cc via Digitalmars-d-learn
The MemUtils package offers a `ScopedPool` utility that seems interesting. It isn't well documented however so I have no idea if it actually works like I expect. I presume this would work something akin to a VM memory snapshot/rollback for the GC? It would be pretty handy for some

Re: How to use destroy and free.

2022-05-04 Thread cc via Digitalmars-d-learn
On Wednesday, 4 May 2022 at 05:37:49 UTC, forkit wrote: inscope int[] i = new int[1]; You often see the "here's an array of ints that exists only in one scope to do one thing, should we leave it floating in memory or destroy it immediately?" as examples for these GC discussions.

Re: How to get compatible symbol names and runtime typeid names for templated classes?

2022-05-03 Thread cc via Digitalmars-d-learn
On Tuesday, 3 May 2022 at 17:05:09 UTC, H. S. Teoh wrote: Oops, sorry, I made a mistake. The definition of Serializable should be: class Serializable(Base, Derived = Object) : Base {} There we go, works with this, now I get what it's trying to do: ```d class Serializable(Base,

Re: How to get compatible symbol names and runtime typeid names for templated classes?

2022-05-03 Thread cc via Digitalmars-d-learn
On Tuesday, 3 May 2022 at 16:51:33 UTC, H. S. Teoh wrote: On Tue, May 03, 2022 at 04:38:23PM +, cc via Digitalmars-d-learn wrote: On Tuesday, 3 May 2022 at 15:08:53 UTC, H. S. Teoh wrote: >class Base : Serializable!(Base) { ... } >class Derived : Serializable!(Base, D

Re: How to get compatible symbol names and runtime typeid names for templated classes?

2022-05-03 Thread cc via Digitalmars-d-learn
On Tuesday, 3 May 2022 at 15:08:53 UTC, H. S. Teoh wrote: class Base : Serializable!(Base) { ... } class Derived : Serializable!(Base, Derived) { ... } This is really interesting syntax, I'm surprised that works!

Re: How to get compatible symbol names and runtime typeid names for templated classes?

2022-05-03 Thread cc via Digitalmars-d-learn
On Tuesday, 3 May 2022 at 10:48:53 UTC, bauss wrote: Object.factory calls TypeInfo_Class.find which just loops through ModuleInfo and then looks if any of the entries in localClasses has a name that matches. Afterwards it calls the create function on the TypeInfo_Class which of course isn't

Re: How to get compatible symbol names and runtime typeid names for templated classes?

2022-05-03 Thread cc via Digitalmars-d-learn
On Tuesday, 3 May 2022 at 09:42:45 UTC, cc wrote: Given a runtime typeid, how can I get the equivalent fullyQualifiedName without attempting to mangle the string myself manually? e.g. something I can pass to `Object.factory`. Actually, looking at this further, does Object.factory even

How to get compatible symbol names and runtime typeid names for templated classes?

2022-05-03 Thread cc via Digitalmars-d-learn
This produces compatible strings between symbol and runtime type: ```d class Foo {} void main() { alias Foo F; writeln(fullyQualifiedName!F); auto f = new F; writeln(typeid(f).name); } ``` ``` test.Foo test.Foo ``` But if the class is a template, the strings

Re: Reference counting example

2022-04-26 Thread cc via Digitalmars-d-learn
On Tuesday, 26 April 2022 at 22:16:01 UTC, cc wrote: Test application: I should point out that all this stuff with saving refcounted things to arrays and so on is extremely untested and experimental One problem I'm seeing is the inability for a refcounted class to pass itself to another

Re: A template construct like using()

2022-04-26 Thread cc via Digitalmars-d-learn
On Tuesday, 26 April 2022 at 21:33:43 UTC, Chris Katko wrote: I swear I asked something like this before years ago but it doesn't show up in my previous forum posts. I'm looking for a construct that mimics using(var)/with(var) ```d void draw_with(bitmap* drawb, void delegate() dg) {

Re: Reference counting example

2022-04-26 Thread cc via Digitalmars-d-learn
On Tuesday, 26 April 2022 at 06:55:34 UTC, Alain De Vos wrote: Can someone provide a simple/very simple reference counting or refcounted example i can understand. Thanks. I've been playing around with the automem[1] library's RefCounted feature as we speak, it seems to fit my needs more than

Re: Assigning to array of structs with custom constructor

2022-04-25 Thread cc via Digitalmars-d-learn
On Monday, 25 April 2022 at 15:23:12 UTC, Ali Çehreli wrote: auto arr = iota(10).map!(i => Foo(i.text)).array; On Monday, 25 April 2022 at 16:11:47 UTC, rassoc wrote: Foo[] arr = ["abc", "def", "ghi"].map!Foo.array; Ahh that'll do it alright, thanks

Get UDAs of self's declaration as a member?

2022-04-25 Thread cc via Digitalmars-d-learn
Hard to word this question right, but is it possible to get the UDAs assigned to a class/structure's member variable declaration, within that variable's definition? e.g. ```d import std.stdio; import std.traits; enum SPECIAL; struct Foo { void foo() { static if

Re: Linked list, printing looks destructive.

2022-04-25 Thread cc via Digitalmars-d-learn
On Monday, 25 April 2022 at 01:40:01 UTC, Alain De Vod wrote: Following program is a single linked list. We expect as output 1 2 3 1 2 3 But the output is only 1 2 3 ``` If you don't need List to be treated as a true range, but just want to iterate, a simple way to do this is with opApply:

Re: Assigning to array of structs with custom constructor

2022-04-25 Thread cc via Digitalmars-d-learn
On Monday, 25 April 2022 at 15:13:51 UTC, Stanislav Blinov wrote: Make it explicit: ```d Foo[] foos = [Foo("a")]; ``` There's that too, but I still have to iterate manually. e.g.: ```d string[] ss = loadABunchOfStringsFromSomewhere(); //Foo[] foos = ss; //error Foo[] foos;

Re: Assigning to array of structs with custom constructor

2022-04-25 Thread cc via Digitalmars-d-learn
On Monday, 25 April 2022 at 15:00:13 UTC, Alain De Vos wrote: Not really an answer but this works, ``` void main(){ Foo foo = "a"; Foo[] foos; foos ~=foo; }% ``` Right, I can append individual elements, but can't assign or append a slice of a type that can be individually cast to the struct.

Assigning to array of structs with custom constructor

2022-04-25 Thread cc via Digitalmars-d-learn
```d struct Foo { string s; this(string s) { this.s = s; } } Foo foo = "a"; Foo[] foos = ["a"]; // Error: cannot implicitly convert expression `["a"]` of type `string[]` to `Foo[]` Foo[] foos = cast(Foo[]) ["a"]; // Error: e2ir: cannot cast `"a"` of type `string` to type `Foo`

Re: Static struct initialization syntax behavior & it being disabled upon adding a constructor

2022-04-18 Thread cc via Digitalmars-d-learn
On Monday, 18 April 2022 at 10:26:16 UTC, HuskyNator wrote: On a sidenote, I'm surprised D did not choose 0 as the default floating value. Doesn't almost every language do this? I understand the thinking behind it, but when the type one uses in a template influences the behavior of the code,

Re: Static struct initialization syntax behavior & it being disabled upon adding a constructor

2022-04-18 Thread cc via Digitalmars-d-learn
On Monday, 18 April 2022 at 03:21:30 UTC, H. S. Teoh wrote: Structs in D ought to be treated like "glorified ints", as Andrei puts it. If you need complex ctors and complex methods, that's a sign you should be using a class instead. Unless you're having a nice quiet get-together with friends,

Re: Importing version identifiers from another file?

2022-04-17 Thread cc via Digitalmars-d-learn
Another option for this was suggested here: https://forum.dlang.org/post/qbvgboihhwcuqglyg...@forum.dlang.org On Wednesday, 12 February 2020 at 09:28:15 UTC, Simen Kjærås wrote: So, you could have a file called 'versions' containing this: # Setting 'Compress' version -version=Compress #

Re: Printing a quoted string

2022-03-22 Thread cc via Digitalmars-d-learn
On Tuesday, 22 March 2022 at 07:18:00 UTC, cc wrote: On Sunday, 20 March 2022 at 09:42:44 UTC, Caten wrote: Hi, I also need a function to "unquote" string, like this: ```d assert(unquote(`\n`)=="\n"); ``` Is there a way to do that? I rolled my own for that recently: ```d string dequote(string

Re: Printing a quoted string

2022-03-22 Thread cc via Digitalmars-d-learn
On Sunday, 20 March 2022 at 09:42:44 UTC, Caten wrote: Hi, I also need a function to "unquote" string, like this: ```d assert(unquote(`\n`)=="\n"); ``` Is there a way to do that? I rolled my own for that recently: ```d string dequote(string str) @safe pure { if (str.length < 2)

Determining function template from runtime type: better ideas?

2022-03-22 Thread cc via Digitalmars-d-learn
Sorry for the fairly lengthy post. I'm wondering if there are any suggested good practices in place for calling templated functions using the runtime type of an object, e.g. what `typeid(object)` returns. Consider the following situation: ```d class Person { string name; int

opCast in class prevents destroy

2022-02-28 Thread cc via Digitalmars-d-learn
```d struct A {} class B { A opCast(T : A)() { return A(); } } void main() { auto b = new B(); destroy(b); } ``` fails with ``` dmd2\windows\bin\..\..\src\druntime\import\object.d(4209): Error: template instance `opCast!(void*)` does not match

Re: Can static variables in methods be local for each object?

2021-07-22 Thread cc via Digitalmars-d-learn
On Tuesday, 20 July 2021 at 09:24:07 UTC, Mark Lagodych wrote: Is there a way to make myvar local to each instance of `X` without making it a variable of `X`? Just curious. Sorry if I missed something obvious but is there a specific reason why it isn't just a class member variable? ```d

Re: What exactly gets returned with extern(C) export string func() ?

2021-06-15 Thread cc via Digitalmars-d-learn
On Sunday, 13 June 2021 at 21:13:33 UTC, frame wrote: On Sunday, 13 June 2021 at 10:02:45 UTC, cc wrote: it seems to work as expected with the same C# code. Does D explicitly disallow slices as an extern(C) export parameter type? The spec says that there is no equivalent to type[]. You get

What exactly gets returned with extern(C) export string func() ?

2021-06-13 Thread cc via Digitalmars-d-learn
D under dmd/Win10/64-bit currently seems to store strings (slices) internally like so: ```d static struct DString { size_t length; immutable(char)* ptr; } static assert(DString.sizeof == string.sizeof); string s = "abcde"; DString d; memcpy(, , s.sizeof); assert(d.length ==

Re: cloning array

2021-06-03 Thread cc via Digitalmars-d-learn
On Wednesday, 2 June 2021 at 17:50:13 UTC, Sean wrote: On Wednesday, 2 June 2021 at 15:32:38 UTC, Sean wrote: if so, how can I get the behavior i am searching for? Thank you. My current solution, if anyone wonders : https://github.com/patefacio/d-help/blob/master/d-help/opmix/dup.d You may

Re: wanting to try a GUI toolkit: needing some advice on which one to choose

2021-06-01 Thread cc via Digitalmars-d-learn
On Tuesday, 1 June 2021 at 20:20:34 UTC, Ola Fosheim Grøstad wrote: Web components are becoming a reality, it essentially means that you have code and styling wrapped up as a component, so that you can use it by inserting a custom html-tag in your code. Given the massive amount of web

Re: wanting to try a GUI toolkit: needing some advice on which one to choose

2021-05-30 Thread cc via Digitalmars-d-learn
This is overkill for any reasonable application, but I've always wanted to design a whole UI framework in OpenGL, just for the novelty of it. I always end up having to reinvent the wheel for UI elements in my projects anyway. https://streamable.com/2uvt4h

Re: How long does the context of a delegate exist?

2021-05-30 Thread cc via Digitalmars-d-learn
On Thursday, 27 May 2021 at 20:46:22 UTC, Adam D. Ruppe wrote: On Thursday, 27 May 2021 at 20:44:21 UTC, frame wrote: Did you mean to add the delegate as GC root or the data? The delegate.ptr property. Is there any way to enforce at compile time that we're not accidentally allocating when

Re: Format

2021-05-21 Thread cc via Digitalmars-d-learn
On Saturday, 22 May 2021 at 03:14:35 UTC, cc wrote: Oops, disregard this. I had an error in my imports. It does in fact work in @safe. I should add as an aside then that there is an issue of errors from the body of a toString template not being displayed, and instead the template being

Re: Format

2021-05-21 Thread cc via Digitalmars-d-learn
On Saturday, 22 May 2021 at 03:07:10 UTC, cc wrote: Ahh, in that case it would appear formattedWrite isn't @safe at all. Looks like you have to stick with put()? ```d @safe void toString(W)(ref W writer) if (isOutputRange!(W, char)) { //writer.formattedWrite!("FOO:%s", x); // fails

Re: Format

2021-05-21 Thread cc via Digitalmars-d-learn
On Friday, 21 May 2021 at 16:53:48 UTC, drug wrote: 21.05.2021 18:28, cc пишет: On Friday, 21 May 2021 at 14:19:03 UTC, newbie wrote: Thank you, and formatValue? formattedWrite should handle this. ```d @safe struct Foo { int x = 3; void toString(W)(ref W writer) if

Re: Format

2021-05-21 Thread cc via Digitalmars-d-learn
On Friday, 21 May 2021 at 14:19:03 UTC, newbie wrote: Thank you, and formatValue? formattedWrite should handle this. ```d @safe struct Foo { int x = 3; void toString(W)(ref W writer) if (isOutputRange!(W, char)) { writer.formattedWrite("Foo(%s)", x); }

Re: struct destructor

2021-05-16 Thread cc via Digitalmars-d-learn
On Saturday, 15 May 2021 at 18:24:19 UTC, Alain De Vos wrote: Thanks, good idea but, It does not initiate a GC cycle or free any GC memory. Personally I wish D would re-implement "delete" and make it "just work" like one would assume, but from what I've seen there have been many many debates

What is the difference between these template declaration forms?

2021-05-15 Thread cc via Digitalmars-d-learn
Are these identical? Or is there a different usage for the (T : something) form? ```d auto opCast(T)() if (is(T == bool)) { return _obj !is null; } ``` ```d auto opCast(T : bool)() { return _obj !is null; } ```

Re: Learning D

2021-05-14 Thread cc via Digitalmars-d-learn
On Friday, 14 May 2021 at 15:30:06 UTC, Imperatorn wrote: https://www.amazon.com/Programming-Language-Former-Python-Developers-ebook/dp/B08MD7ZB2X Anyone read it? Haven't read it, the title has me at the first five words though.

Re: String "dequote" in phobos?

2021-05-13 Thread cc via Digitalmars-d-learn
On Thursday, 13 May 2021 at 16:40:29 UTC, Imperatorn wrote: Wouldn't this just this do that? 樂 ```d string dequote(string s) { return s[1..$-1]; } ``` The idea would be for situations where it isn't known in advance whether the string is quoted, if it is quoted properly, and whether

String "dequote" in phobos?

2021-05-13 Thread cc via Digitalmars-d-learn
Does something to dequote (unquote? or what would you call it?) a string exist in the standard library? I didn't see one in std.string, just wondering before reinventing the wheel. Something like: ```d assert(dequote(`"foo"`) == "foo"); assert(dequote(`'foo'`) == "foo");

Re: Question about property & method access scope.

2021-05-11 Thread cc via Digitalmars-d-learn
On Tuesday, 11 May 2021 at 09:10:02 UTC, Vinod K Chandran wrote: Hi all, I am practising D with a win api GUI hobby project. I have a Window class and it resides in module window.d My WndProc function resides in another module named wnd_proc_module.d Inside my WndProc, I get the Window class

Re: OutOfMemoryError in D DLL appending to module-level array

2021-05-02 Thread cc via Digitalmars-d-learn
On Sunday, 2 May 2021 at 02:42:46 UTC, Adam D. Ruppe wrote: On Sunday, 2 May 2021 at 02:34:41 UTC, cc wrote: which seems to fix it, but I'm not entirely sure what's going on, if this is expected behavior, if that's the correct way to handle it, and so on. Oh I've been working on this the

Re: OutOfMemoryError in D DLL appending to module-level array

2021-05-01 Thread cc via Digitalmars-d-learn
On Sunday, 2 May 2021 at 02:34:41 UTC, cc wrote: [...] Just to add, only appending to the array seems to give OutOfMemoryErrors. I can idup strings, call stdc malloc, etc just fine.

OutOfMemoryError in D DLL appending to module-level array

2021-05-01 Thread cc via Digitalmars-d-learn
Ordinarily, it seems legal to append to an array that has been declared at module level (or as a static class member) that hasn't been otherwise initialized, for example: ```d class Foo {} private Foo[] cache; void main() { auto foo = new Foo(); cache ~= foo; } ``` However,

Re: win64 DLL stdout printing after main process completes

2021-04-26 Thread cc via Digitalmars-d-learn
On Monday, 26 April 2021 at 13:44:19 UTC, frame wrote: On Sunday, 25 April 2021 at 15:01:25 UTC, cc wrote: Adding a note in case anyone stumbles across this with a similar problem: Adding `stdout.setvbuf(0, _IONBF);` to both the main and DLL will cause D to autoflush after every write call

Re: win64 DLL stdout printing after main process completes

2021-04-25 Thread cc via Digitalmars-d-learn
On Monday, 19 April 2021 at 18:32:15 UTC, Adam D. Ruppe wrote: On Monday, 19 April 2021 at 18:05:46 UTC, cc wrote: This seems to work if I flush after every printf or write in both main and the dll. I was under the impression they were supposed to share the same IO buffers though, is this not

Re: win64 DLL stdout printing after main process completes

2021-04-19 Thread cc via Digitalmars-d-learn
On Monday, 19 April 2021 at 16:04:28 UTC, Mike Parker wrote: On Monday, 19 April 2021 at 14:55:03 UTC, cc wrote: And upon running, the output I receive is: ``` [Main] Start [Main] x: 5 [Main] Finished [Main] END [dll] DLL_PROCESS_ATTACH [dll] static this for mydll [dll] MyDLL_Test [dll]

Re: win64 DLL stdout printing after main process completes

2021-04-19 Thread cc via Digitalmars-d-learn
On Monday, 19 April 2021 at 16:00:25 UTC, frame wrote: You miss a core.stdc.stdio import in main(). I also omit the def-File, maybe you have an error in it? It shouldn't be necessary to include. It just did: ``` dmd -m64 -ofmydll.dll -L/DLL mydll.d ``` Sorry, here's the def file, taken from

win64 DLL stdout printing after main process completes

2021-04-19 Thread cc via Digitalmars-d-learn
I'm not sure if this is something unique to D or not, but I've having a minor issue where stdout output from a DLL (either via printf or phobos std.stdio write) is not displayed until after the main process has completed. I'm making a project based around the example at

Package import order with extern(C++) classes and std.container.array failure

2021-04-06 Thread cc via Digitalmars-d-learn
Just encountered this compilation failure in DMD winx64 2.096, which previously worked in 2.095 and prior versions. Just wondering if it's a bug, or a new issue to keep in mind when importing modules? Sorry for the complex nature of this scenario but I'll try to keep it as simple as

Re: Problem with templated alias as delegate parameter type

2021-01-12 Thread cc via Digitalmars-d-learn
On Tuesday, 12 January 2021 at 21:32:14 UTC, Ali Çehreli wrote: On 1/12/21 12:58 PM, cc wrote: > void send(T query, void delegate(T.RESPONSE) callback) { That wants a delegate that takes a T.RESPONSE (PingResponse in this case). However, the following lambda is in fact a template: >

Problem with templated alias as delegate parameter type

2021-01-12 Thread cc via Digitalmars-d-learn
Given the following program: struct PingQuery { string msg; } struct PingResponse { string msg; } template send(T) { void send(T query, void delegate(PingResponse) callback) { writefln("Sending: %s", query); if (callback) {

Re: Renamed but non-selective import?

2021-01-12 Thread cc via Digitalmars-d-learn
On Tuesday, 12 January 2021 at 20:19:20 UTC, ag0aep6g wrote: On 12.01.21 21:09, cc wrote: import core.sys.windows.windows; import mymodule; // contains a struct named MSG Error: `core.sys.windows.winuser.MSG` ... conflicts with `mymodule.MSG` vs import core.sys.windows.windows : winMSG =

Renamed but non-selective import?

2021-01-12 Thread cc via Digitalmars-d-learn
Is it possible to import all symbols of a module, while renaming just one of them? It seems like doing an import with renaming automatically makes it selective. In the example below, I'd prefer not to have to use the fully qualified name for mymodule.MSG every time e.g.: import

Re: constructing labels for static foreach inside switch inside foreach

2020-07-08 Thread cc via Digitalmars-d-learn
On Wednesday, 8 July 2020 at 02:06:01 UTC, Steven Schveighoffer wrote: OK, so I have a situation where I'm foreaching over a compile-time list of types. Inside the loop, I'm using a second loop over a set of input. Inside that loop, I'm using a switch on the input, and inside the switch, I'm

Should getSymbolsByUDA work with member variables?

2020-02-28 Thread cc via Digitalmars-d-learn
This compiles: class Foo { int x; @(1) void y() {} this() { static foreach (idx, field; getSymbolsByUDA!(Foo, 1)) { } } } This does not: class Foo { @(1) int x; void y() {} this() { static

Re: Get compilation errors within opDispatch?

2020-02-17 Thread cc via Digitalmars-d-learn
On Monday, 17 February 2020 at 17:01:12 UTC, Adam D. Ruppe wrote: It sometimes helps to write it out log-form foo.opDispatch!"hello"(5); should give the full error. this btw is one of the most annoying missing errors in d... This worked, thank you! On Monday, 17 February 2020 at 16:45:53

Get compilation errors within opDispatch?

2020-02-17 Thread cc via Digitalmars-d-learn
Is there any way to see the compilation errors that occurred within an opDispatch template? struct Foo { void opDispatch(string s, SA...)(SA sargs) { literally anything; } } Foo foo; foo.hello(5); Result: Error: no property `hello` for type `Foo` Desired

Re: How to use labeled break in static foreach?

2020-02-13 Thread cc via Digitalmars-d-learn
Here's a more involved example of what I'm trying to accomplish. Is there an easier/cleaner way to do this? (This is still a bit reduced, what I'm actually trying to do is compare whether a given variadic typetuple passed to opDispatch is implicitly convertible to one of the parameter

How to use labeled break in static foreach?

2020-02-13 Thread cc via Digitalmars-d-learn
import std.meta; enum A = AliasSeq!(1, 2, 3, 4); THREELOOP: static foreach (idx, field; A) { static if (field == 3) { pragma(msg, "Got a 3!"); break THREELOOP; } static if (idx == A.length - 1) { static assert(0, "Got no

Re: Global version/debug statements in file?

2020-02-12 Thread cc via Digitalmars-d-learn
On Wednesday, 12 February 2020 at 09:28:15 UTC, Simen Kjærås wrote: https://dlang.org/dmd-windows.html#switches specifies that DMD may be passed a file on the command line that contains compiler arguments and switches. This may be freely combined with regular command line arguments if you so

Re: Is there a std.zip.ZipArchive isDir or isFile method?

2020-02-12 Thread cc via Digitalmars-d-learn
It looks like 004 (octal) is the flag for directories on linux, but it does seem that std.zip is explicitly returning 0 if the file was created on the opposite platform re: Posix vs Windows, which is... odd. @property @nogc nothrow uint fileAttributes() const { version (Posix) {

Global version/debug statements in file?

2020-02-12 Thread cc via Digitalmars-d-learn
Is there some way to globally declare version= or debug= statements in a file and have them apply to the entire project being compiled? As the documentation says these only apply to the module scope they exist in, and need to be added to the command line otherwise. It would be a bit easier

Re: Is there a std.zip.ZipArchive isDir or isFile method?

2020-02-11 Thread cc via Digitalmars-d-learn
On Monday, 3 February 2020 at 13:26:38 UTC, mark wrote: I'm using std.zip.ZipArchive to read zip files, e.g.: auto zip = new ZipArchive(read(filename)); // ... foreach (name, member; zip.directory) { if (name.endsWith('/')) // skip dirs continue;

  1   2   >