Re: UI Library

2022-05-27 Thread Jack via Digitalmars-d-learn
On Friday, 20 May 2022 at 12:32:37 UTC, ryuukk_ wrote: Avoid GTK, it's bloated, GTK4 looks like a toolkit to design mobile apps, and you need runtime dependencies on windows adam's gui library is very nice, 0 dependencies I personally prefer IMGUI, 0 dependencies, you bring the could you se

Re: Execute the Shell command and continue executing the algorithm

2022-05-31 Thread Jack via Digitalmars-d-learn
On Tuesday, 31 May 2022 at 15:29:16 UTC, frame wrote: On Monday, 30 May 2022 at 11:18:42 UTC, Alexander Zhirov wrote: if (here is my condition termination of the program) OT: Wouldn't it be great to have ArnoldC support? ;-) i'm pretty sure the terminattor is more efficient than kill -9

What happened to Circular Studio?

2022-06-06 Thread Jack via Digitalmars-d-learn
I just found out a game using D to develop games but later I see the last updates on the github, web site, twitter etc is from 2015. Does anyone knows what happend to the company?

Re: What happened to Circular Studio?

2022-06-06 Thread Jack via Digitalmars-d-learn
for those that don't know: https://circularstudios.com/

Vibe.d

2020-09-19 Thread Jack via Digitalmars-d-learn
Hi, I am building a webapp using vibe.d which is working well on macOS and Linux. However, when I run it on windows I get: Program exited with code -1073741701 I created a new default project with: dub init test -t vibe.d and get the same error code when running it. Any suggestions what could

Re: Vibe.d

2020-09-19 Thread Jack via Digitalmars-d-learn
On Saturday, 19 September 2020 at 13:13:56 UTC, Jack wrote: Hi, I am building a webapp using vibe.d which is working well on macOS and Linux. However, when I run it on windows I get: Program exited with code -1073741701 I created a new default project with: dub init test -t vibe.d and get the

How do I use translation module in vibe.d?

2020-10-09 Thread jack via Digitalmars-d-learn
Documentation[1] tells to use @translationModule!TranslationContext on class, like this: @translationModule!TranslationContext class WebInterface { ... but it return the error: Error: template instance translationModule!(TranslationContext) does not match template declaration translationMo

Re: How do I use translation module in vibe.d?

2020-10-13 Thread Jack via Digitalmars-d-learn
On Tuesday, 13 October 2020 at 08:03:26 UTC, aberba wrote: On Friday, 9 October 2020 at 21:07:28 UTC, jack wrote: [...] Did you do this? [...] Yes, I did exacly that.

Re: How do I use translation module in vibe.d?

2020-10-13 Thread Jack via Digitalmars-d-learn
On Tuesday, 13 October 2020 at 08:07:17 UTC, aberba wrote: On Friday, 9 October 2020 at 21:07:28 UTC, jack wrote: Documentation[1] tells to use @translationModule!TranslationContext on class, like this: @translationModule!TranslationContext class WebInterface { ... but it return the error:

Re: How do I use translation module in vibe.d?

2020-10-13 Thread Jack via Digitalmars-d-learn
On Tuesday, 13 October 2020 at 08:08:54 UTC, aberba wrote: On Friday, 9 October 2020 at 21:07:28 UTC, jack wrote: Documentation[1] tells to use @translationModule!TranslationContext on class, like this: @translationModule!TranslationContext class WebInterface { ... but it return the error:

How do I make this function from module public?

2020-10-13 Thread Jack via Digitalmars-d-learn
I'm playing with wasm, I wrote a small module where I'd like to make the function available but wasm can't find this function. math.d module math; extern(C): int mul(int a, int b) { return a * b;} wasm.d public import math; extern(C): // disable D mangling void doSomething() { ... } // s

Re: How do I make this function from module public?

2020-10-13 Thread Jack via Digitalmars-d-learn
I'm compiling with ldc2 -mtriple=wasm32-unknow-unknow-wasm -betterC wasm.d

Re: How do I make this function from module public?

2020-10-14 Thread Jack via Digitalmars-d-learn
On Wednesday, 14 October 2020 at 01:55:13 UTC, Adam D. Ruppe wrote: On Wednesday, 14 October 2020 at 01:46:11 UTC, Jack wrote: extern(C): int mul(int a, int b) { return a * b;} mark it `export` as well and then be sure you are compiling in this module as well, it must be included on the ldc

malloc(s)[0..s] vs cast(T)malloc(s)

2020-10-14 Thread Jack via Digitalmars-d-learn
What's the difference between: import core.stdc.stdlib : malloc; auto x = malloc(s)[0..s]; and auto x = cast(T)malloc(s); ? I have been using the last but I saw in some code examples, like this[1] the first being used. What's the difference? in the first one bounds checking is performed, g

Why was new(size_t s) { } deprecated in favor of an external allocator?

2020-10-14 Thread Jack via Digitalmars-d-learn
What was the reasoning behind this decision?

Re: malloc(s)[0..s] vs cast(T)malloc(s)

2020-10-15 Thread Jack via Digitalmars-d-learn
On Wednesday, 14 October 2020 at 21:12:13 UTC, Paul Backus wrote: On Wednesday, 14 October 2020 at 20:15:39 UTC, Jack wrote: [...] The difference is that the first version gives you a `void[]`, and the second version gives you a `T`. Neither version does any bounds checking. Generally, you

Re: malloc(s)[0..s] vs cast(T)malloc(s)

2020-10-15 Thread Jack via Digitalmars-d-learn
On Thursday, 15 October 2020 at 01:22:54 UTC, Ali Çehreli wrote: On 10/14/20 1:15 PM, Jack wrote: >> auto x = malloc(s)[0..s]; > https://wiki.dlang.org/Memory_Management#Explicit_Class_Instance_Allocation Note that 'x' is passed to emplace() at that link and emplace() requires a slice. That

How can I use class and wasm?

2020-10-15 Thread Jack via Digitalmars-d-learn
can I make it work? the code (see below) result in link error: lld: error: wasm.o: undefined symbol: _D4wasm1C7__ClassZ lld: error: wasm.o: undefined symbol: _d_allocclass Error: linking with LLD failed command line: ldc2 --d-debug -mtriple=wasm32-unknown-unknown-wasm -betterC wasm.d ldc v

Re: winapi, dll

2020-10-15 Thread Jack via Digitalmars-d-learn
On Thursday, 15 October 2020 at 20:13:37 UTC, Atmosfear wrote: On Thursday, 15 October 2020 at 16:32:06 UTC, Imperatorn wrote: On Thursday, 15 October 2020 at 12:45:42 UTC, Atmosfear wrote: I didn't find how to call the queryperformancecounter function. I tried this. Returns errors, doesn't kno

Re: How can I use class and wasm?

2020-10-15 Thread Jack via Digitalmars-d-learn
On Friday, 16 October 2020 at 02:43:19 UTC, Paul Backus wrote: On Thursday, 15 October 2020 at 22:02:11 UTC, Jack wrote: can I make it work? the code (see below) result in link error: lld: error: wasm.o: undefined symbol: _D4wasm1C7__ClassZ lld: error: wasm.o: undefined symbol: _d_allocclass E

Re: Question about: ("1.1").to!int;

2020-10-24 Thread Jack via Digitalmars-d-learn
On Wednesday, 21 October 2020 at 22:50:27 UTC, matheus wrote: Hi, import std.stdio, std.conv; void main(string[ ] args) { auto a = (1).to!int; // this works auto b = ("1").to!int; // this works auto c = (1.1).to!int; // this works and c = 1 auto d = ("1.1").to!int; // Doe

Re: Can we do compile time reading part of a file using import?

2020-10-25 Thread Jack via Digitalmars-d-learn
On Sunday, 25 October 2020 at 12:16:36 UTC, Jacob Carlborg wrote: On 2020-10-23 18:42, data pulverizer wrote: For me it's not make-or-break, it just something very useful and I think has clear use case. Please let me know if there are aspects or alternatives I am missing. You could always ha

Re: Can we do compile time reading part of a file using import?

2020-10-25 Thread Jack via Digitalmars-d-learn
On Friday, 23 October 2020 at 16:42:00 UTC, data pulverizer wrote: Hi all, the `import` function allows a file to be read at compile time, which opens up great opportunities for (mostly binary) file IO, where data types can be coded into files - the user doesn't need to know data types ahead

Re: How can I use class and wasm?

2020-10-26 Thread Jack via Digitalmars-d-learn
On Friday, 16 October 2020 at 03:42:22 UTC, Adam D. Ruppe wrote: On Friday, 16 October 2020 at 03:04:25 UTC, Jack wrote: How can I allocate memory for this class? It is possible but not easy without druntime. If you are using -betterC, you can use extern(C++) classes with extern(D) members.

Re: How kill executables started with spawnShell or executeShell when program finish?

2020-10-27 Thread Jack via Digitalmars-d-learn
On Tuesday, 27 October 2020 at 15:16:33 UTC, Marcone wrote: Becouse my program use plink.exe running with spawnShell or executeShell. But when my program finish with some crash, or killed with windows task manager by user, Plink still running. How can I stop all process initialized with spawnSh

Re: How kill executables started with spawnShell or executeShell when program finish?

2020-10-27 Thread Jack via Digitalmars-d-learn
On Tuesday, 27 October 2020 at 22:14:53 UTC, Dukc wrote: On Tuesday, 27 October 2020 at 15:16:33 UTC, Marcone wrote: [...] This is a bit heavyweight, but should be doable: have your primary process to start a watchdog process for itself. The watchdog continuosly sends messages to the primary

Re: Regex and manipulating files

2020-11-16 Thread Jack via Digitalmars-d-learn
On Monday, 16 November 2020 at 10:51:51 UTC, Bloris wrote: I've to convert a linux dash script because it is too slow and i decded to do it in D. I'm totally new to this and i think it could be a good exercise to learn this language. The shell script does some simple jobs like: 0) Run the scri

Re: Can't pass [] to extern function object method

2020-11-16 Thread Jack via Digitalmars-d-learn
On Monday, 16 November 2020 at 21:31:44 UTC, frame wrote: I have a DLL in D-code which returns an object and want to pass a struct S[] to a member function of that object. The first element is passed correctly, the rest is just garbage. In fact the next item is just a single byte with value 0x1

Re: betterC question

2020-11-19 Thread Jack via Digitalmars-d-learn
On Thursday, 19 November 2020 at 14:34:38 UTC, Adam D. Ruppe wrote: On Thursday, 19 November 2020 at 00:20:50 UTC, Dibyendu Majumdar wrote: Okay thanks. Bad idea IMO. That's kinda how I see C taking the address of various things implicitly. good example

d++: Error: Could not execute `dmd c.o .\foo.d -offoo.exe`:

2020-11-21 Thread Jack via Digitalmars-d-learn
I'm trying to get d++ to work on Windows 10/64-bit machine but it doesn't work. I'm using the very same code samples c.c, c.h and foo.dpp from here https://github.com/atilaneves/dpp/tree/master/bash but when I went to run: d++ foo.dpp c.o I got the error: Error: Could not execute `dmd c.

Re: d++: Error: Could not execute `dmd c.o .\foo.d -offoo.exe`:

2020-11-21 Thread Jack via Digitalmars-d-learn
On Saturday, 21 November 2020 at 19:34:31 UTC, Ferhat Kurtulmuş wrote: On Saturday, 21 November 2020 at 17:25:46 UTC, Jack wrote: I'm trying to get d++ to work on Windows 10/64-bit machine but it doesn't work. I'm using the very same code samples c.c, c.h and foo.dpp from here https://github.c

Re: d++: Error: Could not execute `dmd c.o .\foo.d -offoo.exe`:

2020-11-22 Thread Jack via Digitalmars-d-learn
On Sunday, 22 November 2020 at 03:05:45 UTC, kinke wrote: On Saturday, 21 November 2020 at 17:25:46 UTC, Jack wrote: I got the error: Error: Could not execute `dmd c.o .\foo.d -offoo.exe`: Error: unrecognized file extension o dmd version: DMD32 D Compiler v2.094.1-dirty gcc version: gcc

list dll from Gtk executable build with dmd not working

2020-11-28 Thread Jack via Digitalmars-d-learn
So I build a Gtk executable with dmd, following this[1] tutorial but no tool ldd, nlldd, listdlls[2], dependencies[3] list the gtk's dlls that the executable, as far I know, depends on to run, hence the need to install the Gtk runtime[4]. What am I missing? all those tools only return the wind

Re: list dll from Gtk executable build with dmd not working

2020-11-29 Thread Jack via Digitalmars-d-learn
On Saturday, 28 November 2020 at 15:58:57 UTC, Jack wrote: So I build a Gtk executable with dmd, following this[1] tutorial but no tool ldd, nlldd, listdlls[2], dependencies[3] list the gtk's dlls that the executable, as far I know, depends on to run, hence the need to install the Gtk runtime[4

Re: How to bundle a GtkD application for Windows

2020-11-29 Thread Jack via Digitalmars-d-learn
On Sunday, 29 November 2020 at 20:08:33 UTC, adnan449 wrote: Hello, I would be greatly thankful if I was given an easy guide on how to produce windows executables for GtkD applications. I do not have an access to a windows machine but I need to be able to produce installers/exe files for the wi

How to build dll?

2020-12-02 Thread Jack via Digitalmars-d-learn
D code: import core.sys.windows.dll; mixin SimpleDllMain; version(Windows) extern(C) export int foo() { return 42; } compiled with: dmd -ofmydll.dll -shared -m32 dll.d called from: typedef int (__cdecl *MYPROC)(void); int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,

Re: How to build dll?

2020-12-02 Thread Jack via Digitalmars-d-learn
On Wednesday, 2 December 2020 at 19:42:37 UTC, Jack wrote: D code: import core.sys.windows.dll; mixin SimpleDllMain; version(Windows) extern(C) export int foo() { return 42; } compiled with: dmd -ofmydll.dll -shared -m32 dll.d called from: typedef int (__cdecl *MYPROC)(void); int WINA

converting D's string to use with C API with unicode

2020-12-05 Thread Jack via Digitalmars-d-learn
So in D I have a struct like this: struct ProcessResult { string[] output; bool ok; } in order to use output from C WINAPI with unicode, I need to convert each string to wchar* so that i can acess it from C with wchar_t*. Is that right or am I missing anything? struct Pro

Re: converting D's string to use with C API with unicode

2020-12-05 Thread Jack via Digitalmars-d-learn
I totally forget to malloc() the strings and array. I don't do C has been a while and totally forget this, thank you so much guys for your answer. my code now look like this, still there's a memory corrupt. Could anyone help point out where is it? struct ProcessResult { string[] out

Re: converting D's string to use with C API with unicode

2020-12-05 Thread Jack via Digitalmars-d-learn
On Saturday, 5 December 2020 at 23:31:31 UTC, tsbockman wrote: On Saturday, 5 December 2020 at 21:55:13 UTC, Jack wrote: my code now look like this, still there's a memory corrupt. Could anyone help point out where is it? ... foreach(i; 0..output.length) { wstring ws; transcode(outpu

Re: converting D's string to use with C API with unicode

2020-12-06 Thread Jack via Digitalmars-d-learn
On Sunday, 6 December 2020 at 04:41:56 UTC, Виталий Фадеев wrote: On Saturday, 5 December 2020 at 19:51:14 UTC, Jack wrote: So in D I have a struct like this: struct ProcessResult { string[] output; bool ok; } in order to use output from C WINAPI with unicode, I need to conv

Re: converting D's string to use with C API with unicode

2020-12-06 Thread Jack via Digitalmars-d-learn
On Sunday, 6 December 2020 at 05:04:35 UTC, tsbockman wrote: On Sunday, 6 December 2020 at 02:07:10 UTC, Jack wrote: On Saturday, 5 December 2020 at 23:31:31 UTC, tsbockman wrote: On Saturday, 5 December 2020 at 21:55:13 UTC, Jack wrote: [...] `ws.length` is the length in `wchar`s, but `

To use or not immutable?

2020-12-09 Thread Jack via Digitalmars-d-learn
I'm coding with visual studio code and now it shows a yellow mark on variables that is never modified and that could be marked as const or immutable. I think that makes sense, so I think I'll be using it. Do you use it in your code base? are there some design flaws, like there's in C++'s const,

where is the memory corruption?

2020-12-09 Thread Jack via Digitalmars-d-learn
I'm on linux/opensuse, trying to pass a wchar_* from C to D but I'm getting only the first letter of that string. Could someone help figure out why? this is the piece of D code: extern(C) export void sayHello(const (wchar) *s) { import std.stdio : writeln; import std.conv : to;

Re: CMD && comand not work

2020-12-10 Thread Jack via Digitalmars-d-learn
On Thursday, 10 December 2020 at 21:01:30 UTC, Marcone wrote: In this very generic example && not work to finalize the instruct and start a new instruct. Yes, I know dmd can build and run without it, but this is only a example. execute(["cmd", "/c", "dmd test.d", "&&", "start test.exe"]); How

MonoTimeImpl!(ClockType.normal) failed to get the frequency of the system's monotonic clock.

2020-12-13 Thread Jack via Digitalmars-d-learn
I have this D code base that when I compile to executable, it ran fine, but when I call the very same function from C, I get this error: Aborting from src/core/time.d(2113) MonoTimeImpl!(ClockType.normal) failed to get the frequency of the system's monotonic clock. from source code[1] I see

Re: MonoTimeImpl!(ClockType.normal) failed to get the frequency of the system's monotonic clock.

2020-12-13 Thread Jack via Digitalmars-d-learn
On Sunday, 13 December 2020 at 17:34:26 UTC, rikki cattermole wrote: Did you initialize the D runtime before you called the D code? (assuming C main). wow, thanks for such quck response. That's exactly what I missing in this function: version(Posix) {

Can I use dub to generate docs?

2020-12-13 Thread Jack via Digitalmars-d-learn
like dmd's -D flag?

Re: Can I use dub to generate docs?

2020-12-14 Thread Jack via Digitalmars-d-learn
Thank you guys, worked like a charm

Can ddocs link functions automatically?

2020-12-14 Thread Jack via Digitalmars-d-learn
let's say I have a comment like this: / call foo.baa() to validate operation / where foo is the module and baa the function, can ddocs generate a link to the html file where is this defined automatically or do I have to hard-code those links like this? / call [foo.baa()](foo.html

Re: D string to C struct fixed-size array

2021-01-04 Thread Jack via Digitalmars-d-learn
On Sunday, 3 January 2021 at 08:43:34 UTC, bdh wrote: Hi, I'm trying to create bindings to the GraphcicsMagick C library which has the following struct defined: [...] Do you mean fill .filename member from a D string? something like this? import std.stdio; [...] struct Image {

Are there an equivalent to C#'s List in D's stdlib?

2021-01-07 Thread Jack via Digitalmars-d-learn
I coduln't find an equivalent in the documentation, I could see appender, Array, container etc but none of has a Remove(T item) method like C#'s [1]. Are there not such implementation and I do have to write one myself or I just couldn't find? [1]: https://docs.microsoft.com/en-us/dotnet/api/s

Re: Are there an equivalent to C#'s List in D's stdlib?

2021-01-07 Thread Jack via Digitalmars-d-learn
On Friday, 8 January 2021 at 03:06:24 UTC, James Blachly wrote: On 1/7/21 9:53 PM, Jack wrote: I coduln't find an equivalent in the documentation, I could see appender, Array, container etc but none of has a Remove(T item) method like C#'s [1]. Are there not such implementation and I do have t

Re: Are there an equivalent to C#'s List in D's stdlib?

2021-01-07 Thread Jack via Digitalmars-d-learn
On Friday, 8 January 2021 at 03:14:34 UTC, Mike Parker wrote: On Friday, 8 January 2021 at 02:53:47 UTC, Jack wrote: I coduln't find an equivalent in the documentation, I could see appender, Array, container etc but none of has a Remove(T item) method like C#'s [1]. Are there not such implement

How can I do lazy variable initialization?

2021-01-09 Thread Jack via Digitalmars-d-learn
In c# we can do something like this: static Lazy lazy = new Lazy (() => heavyLoadOperation()); static T value { get { return lazy.Value; } } and heavyLoadOperation() is only called when variable "value" is actually used. How can I do something like this in D? I've tried

Re: How can I do lazy variable initialization?

2021-01-09 Thread Jack via Digitalmars-d-learn
On Saturday, 9 January 2021 at 20:39:26 UTC, Ali Çehreli wrote: On 1/9/21 12:35 PM, Ali Çehreli wrote: > alias lightLoadOperation = memoize!heavyLoadOperation; > >const l = lightLoadOperation(); Well, that doesn't work the way you want but this does: if (args.length == 1) { writefln!

Easy way to accept X and immutable X in parameters without overloading?

2021-01-11 Thread Jack via Digitalmars-d-learn
let's say a I have this: void f(X foo) { } but I'd like to make f() accept immutable X too so instead of cast away everywhere in the code where immutable(X) is passed to f() or make a overload for this, are there any way to accept both in same function? those function are callback-like functi

Re: Easy way to accept X and immutable X in parameters without overloading?

2021-01-11 Thread Jack via Digitalmars-d-learn
On Monday, 11 January 2021 at 16:56:05 UTC, ag0aep6g wrote: On Monday, 11 January 2021 at 16:40:01 UTC, Jack wrote: let's say a I have this: void f(X foo) { } but I'd like to make f() accept immutable X too so instead of cast away everywhere in the code where immutable(X) is passed to f() or

Re: Easy way to accept X and immutable X in parameters without overloading?

2021-01-11 Thread Jack via Digitalmars-d-learn
On Monday, 11 January 2021 at 18:37:58 UTC, ag0aep6g wrote: On Monday, 11 January 2021 at 18:12:17 UTC, Jack wrote: thanks! now, how would I add const here? import std.container : SList; auto l = SList!Callabck(); doesn't work: auto l = SList!(const(Callabck())); auto l = SList!(const Callabc

Anything in D to avoid check for null everywhere?

2021-01-12 Thread Jack via Digitalmars-d-learn
I was looking for a way to avoid null checks everywhere. I was checking the Null object pattern, or use something like enforce pattern, or even if I could make a new operator and implement something like C#'s .? operator, that Java was going to have one but they refused[1] (doesn't behave exact

Re: Anything in D to avoid check for null everywhere?

2021-01-12 Thread Jack via Digitalmars-d-learn
Currently I'm with this: auto ref ifNotNull(T, T2)(T lhs, lazy T2 rhs) { if(lhs) { rhs(); } return lhs; } far from good. I wish there was a way to create a new operator so I would make .? similar to C#'s but would evaluate the left-handed side only if it's null and do noth

Why doesn't this work when the function is a static method?

2021-01-13 Thread Jack via Digitalmars-d-learn
works fine (this is defined at global scope, g and baa are same as static) int f(HWND hwnd, int n) { return n*10; } void baa() { HWND foo; writeln(foo.f(10)); } but if I wrap this within a class: class Foo { static int f(HWND hwnd, int n)

Re: Why doesn't this work when the function is a static method?

2021-01-13 Thread Jack via Digitalmars-d-learn
On Wednesday, 13 January 2021 at 17:21:23 UTC, Paul Backus wrote: On Wednesday, 13 January 2021 at 17:14:04 UTC, Jack wrote: but if I wrap this within a class: class Foo { static int f(HWND hwnd, int n) { return n*10; } static void baa() { HWND foo;

Re: Why doesn't this work when the function is a static method?

2021-01-14 Thread Jack via Digitalmars-d-learn
On Thursday, 14 January 2021 at 09:13:27 UTC, evilrat wrote: On Thursday, 14 January 2021 at 05:44:43 UTC, Jack wrote: On Wednesday, 13 January 2021 at 17:21:23 UTC, Paul Backus wrote: Member functions (including static ones) can't be called with UFCS. is this documented somewhere? Is thi

How can I specify flags for the compiler when --build=release in dub?

2021-01-15 Thread Jack via Digitalmars-d-learn
is this possible? if so, how?

native way to tell if output binary is library or executable?

2021-01-17 Thread Jack via Digitalmars-d-learn
I know I can set version but I'd looking for a native way, if any, to do that. Is possible to tell if output binary is library or executable at compile time? then I'd call different version of a function.

Re: native way to tell if output binary is library or executable?

2021-01-18 Thread Jack via Digitalmars-d-learn
On Monday, 18 January 2021 at 03:30:56 UTC, Paul Backus wrote: On Monday, 18 January 2021 at 02:24:59 UTC, Jack wrote: I know I can set version but I'd looking for a native way, if any, to do that. Is possible to tell if output binary is library or executable at compile time? then I'd call diff

How do I make a template function that only accepts instances of a specific class?

2021-01-18 Thread Jack via Digitalmars-d-learn
isInstanceOf from std.traits seems to not work with class the way I need to. I'd like to make a template function accepts only class of a specified class type class A { } class B : A { } class C : A { } import std.traits : isInstanceOf; int f(T)(in A[int] arr) if(isInstanceOf!(A, T)) // does

Re: How do I make a template function that only accepts instances of a specific class?

2021-01-18 Thread Jack via Digitalmars-d-learn
On Monday, 18 January 2021 at 19:02:10 UTC, Adam D. Ruppe wrote: On Monday, 18 January 2021 at 18:40:37 UTC, Jack wrote: isInstanceOf from std.traits seems to not work with class the way I need to. I'd like to make a template function accepts only class of a specified class type class A { } c

How do I enable visual styles?

2021-01-18 Thread Jack via Digitalmars-d-learn
Currently I'm using dmd but the release binaries I'll be usind ldc. Is this how I can enable visual styles on dmd? and how is this done on ldc? pragma(linkerDirective, "\"/manifestdependency:type='win32' " ~ "name='Microsoft.Windows.Common-Controls' version='6.0

Re: How do I enable visual styles?

2021-01-18 Thread Jack via Digitalmars-d-learn
On Monday, 18 January 2021 at 19:50:18 UTC, Adam D. Ruppe wrote: I haven't played with the pragma yet but I've done it before both with the file.exe.manifest XML file sitting alongside it and with the resource compiler before (you can use the same resource compilers for D as you use for C btw)

Re: How do I make a template function that only accepts instances of a specific class?

2021-01-18 Thread Jack via Digitalmars-d-learn
On Monday, 18 January 2021 at 19:54:04 UTC, Adam D. Ruppe wrote: On Monday, 18 January 2021 at 19:34:52 UTC, Jack wrote: is that sytax derived from there? sort of. it is the type pattern matching "is expression" described here: https://dlang.org/spec/expression.html#IsExpression I read st

Re: Struggling with wchar[] to string conversion

2021-01-19 Thread Jack via Digitalmars-d-learn
On Tuesday, 19 January 2021 at 15:32:12 UTC, Stefan wrote: Hi, I am using dmd2.081.1 on windows building a 32 bit executable. I am trying to find out how many instances of the same program are running. Therefor I use the core.sys.windows.tlhelp32 module. With the CreateToolhelp32Snapshot(TH

Re: How can I create a Standalone Bundle Portable file application using Dlang?

2021-01-23 Thread Jack via Digitalmars-d-learn
On Monday, 18 January 2021 at 19:42:22 UTC, Marcone wrote: How can I create a Standalone Bundle Portable file application using Dlang? What are the dependencies that you would like to merge into executable? dlls? resources?

How do I overload += operator?

2021-01-25 Thread Jack via Digitalmars-d-learn
I'd like to make this work s += 10 where s is a struct. How can I do that? this isn't working: auto ref opAssign(string op, T)(T value) if(op == "+") { m += value; return this; } the compiler didn't consider that overload and return: d.d(34): Error: s is not a s

Re: How do I overload += operator?

2021-01-25 Thread Jack via Digitalmars-d-learn
On Monday, 25 January 2021 at 17:11:41 UTC, Adam D. Ruppe wrote: On Monday, 25 January 2021 at 17:09:22 UTC, Jack wrote: auto ref opAssign(string op, T)(T value) try opOpAssign instead opAssign is for = opOpAssign is for +=, -=, etc. It might be some variation but I think it works if y

Re: How do I overload += operator?

2021-01-25 Thread Jack via Digitalmars-d-learn
On Monday, 25 January 2021 at 17:12:47 UTC, Paul Backus wrote: On Monday, 25 January 2021 at 17:09:22 UTC, Jack wrote: I'd like to make this work s += 10 where s is a struct. How can I do that? +=, -=, *=, and other compound assignment operators can be overloaded by defining `opOpAssign`: h

Can I set the base class like this?

2021-01-25 Thread Jack via Digitalmars-d-learn
Can I pass the base class type thought template parameter? something like this: class MyType { } class A(T) { void doSomething() { } } class B(T) { void doSomething() { } } // this class shared stuff to deal with A and B class C(T) : T!MyType { void doSOmethingElse() { } over

Re: Can I set the base class like this?

2021-01-26 Thread Jack via Digitalmars-d-learn
On Tuesday, 26 January 2021 at 14:12:21 UTC, vitamin wrote: On Tuesday, 26 January 2021 at 04:39:07 UTC, Jack wrote: Can I pass the base class type thought template parameter? something like this: [...] You have it almost right: class C(alias T) // Template is not type but symbol. Th

Re: Can I set the base class like this?

2021-01-26 Thread Jack via Digitalmars-d-learn
On Tuesday, 26 January 2021 at 14:15:25 UTC, frame wrote: On Tuesday, 26 January 2021 at 04:39:07 UTC, Jack wrote: note the body is the same, what changes is the base class. I'd like to avoid repeating myself when the body is the same and only the base class changes. You would have to call it

Is there a generic type such as void* or C#'s object?

2021-02-05 Thread Jack via Digitalmars-d-learn
in C/C++ you have void* and C#'s object, to create a variable to hold a genetic type. So in C# you can do: class A { object foo; } and var a = new A(); a.foo = any class...; does D have something like this or template parameters are used instead of?

Re: Is there a generic type such as void* or C#'s object?

2021-02-07 Thread Jack via Digitalmars-d-learn
Thanks for your answers guys!

How can I clean array and prevent further reallocation if there's enough space already?

2021-02-07 Thread Jack via Digitalmars-d-learn
How can I do that? I though something like this: auto arr = [1, 2, 3, 4]; arr = arr[0 .. 0]; arr ~= 6; // does this cause reallocation? assumeSafeAppend() wouldn't work in this case because I don't know the number of items that is going to be added to the array. I thought into setting the leng

Re: How can I clean array and prevent further reallocation if there's enough space already?

2021-02-07 Thread Jack via Digitalmars-d-learn
On Sunday, 7 February 2021 at 21:34:22 UTC, Adam D. Ruppe wrote: On Sunday, 7 February 2021 at 21:31:11 UTC, Jack wrote: assumeSafeAppend() wouldn't work in this case because I don't know the number of items that is going to be added to the array. I don't think that matters. assumeSafeAppend

Re: How can I clean array and prevent further reallocation if there's enough space already?

2021-02-07 Thread Jack via Digitalmars-d-learn
On Sunday, 7 February 2021 at 21:55:34 UTC, Adam D. Ruppe wrote: On Sunday, 7 February 2021 at 21:40:12 UTC, Jack wrote: I think it would be fine except it assumes the number of items of the array to doesn't grow, it rather overwritten new elements from docs: "Use this only when it is certai

how to properly compare this type?

2021-02-09 Thread Jack via Digitalmars-d-learn
I have a class like this: struct S { } class A { @(S) { int a; string b() { return ib; } string b(string s) { return ib = s;} } int x; int y; string ib = "lol"; } where I want to list the members t

Re: how to properly compare this type?

2021-02-12 Thread Jack via Digitalmars-d-learn
helpful always,thank you guys

Is this the proper way to do it?

2021-02-12 Thread Jack via Digitalmars-d-learn
I have a base class A, where I make specific operator depending on the derived class type. Currently I'm using something like this: c is a class derived from A bool shouldDoX = (cast(X)c) !is null || (cast(Y)c) !is null || (cast(K)c) !is null ... ; as the number of cast(C) !is null is growin

Is there other way to do that?

2021-02-14 Thread Jack via Digitalmars-d-learn
I need to check if an instance is of a specific type derived from my base class but this class has template parameter and this type isn't available at time I'm checking it. Something like: class B { } class A(T) : B { } class X : B { } class Z : B { } auto c = can be any derived class from B b

how to make this function nothrow?

2021-02-15 Thread Jack via Digitalmars-d-learn
I have to make my function nothrow because the function that calls it (not written by me) is nothrow. So I need to wrap my code in a try-catch() but how will I report the error message, if the toString() from Throwable isn't nothrow? how do I get out this circular dependence? void f() nothro

Re: How do I enable visual styles?

2021-02-18 Thread Jack via Digitalmars-d-learn
if someone happens to be looking to do that in the future: I didn't find a way to do this with a linker but managed to find a way to do this with code only. The code goes like this: // source: https://stackoverflow.com/a/10444161/800123 #include // NOTE: It is recommended that you delay-load

How can I get this UDA at compile time?

2021-02-20 Thread Jack via Digitalmars-d-learn
I've had a struct like this: struct Attr { string value; } struct Foo { @(Attr("a attr")) enum a = Foo(10); @(Attr("b attr")) enum b = Foo(11); int x; int y; bool doY = true; int value() {

Re: How can I get this UDA at compile time?

2021-02-21 Thread Jack via Digitalmars-d-learn
On Sunday, 21 February 2021 at 09:30:14 UTC, Jacob Carlborg wrote: On 2021-02-21 07:12, Jack wrote: I've had a struct like this: struct Attr { string value; } struct Foo { @(Attr("a attr")) enum a = Foo(10); @(Attr("b attr")) enum b = Foo(11); int x; int y

Re: Foo Foo = new Foo();

2021-02-21 Thread Jack via Digitalmars-d-learn
Why doesn't this compiles? class Baa { Foo Foo = new Foo(); }

Re: how to make this function nothrow?

2021-02-22 Thread Jack via Digitalmars-d-learn
On Tuesday, 16 February 2021 at 00:39:33 UTC, Steven Schveighoffer wrote: On 2/15/21 4:04 PM, Jack wrote: I have to make my function nothrow because the function that calls it (not written by me) is nothrow. So I need to wrap my code in a try-catch() but how will I report the error message, if

Re: Is this the proper way to do it?

2021-02-22 Thread Jack via Digitalmars-d-learn
On Saturday, 13 February 2021 at 09:54:28 UTC, Rumbu wrote: On Saturday, 13 February 2021 at 05:52:34 UTC, Jack wrote: I have a base class A, where I make specific operator depending on the derived class type. Currently I'm using something like this: c is a class derived from A bool shouldDoX

Re: Is this the proper way to do it?

2021-02-22 Thread Jack via Digitalmars-d-learn
On Saturday, 13 February 2021 at 07:08:58 UTC, mw wrote: On Saturday, 13 February 2021 at 05:52:34 UTC, Jack wrote: I have a base class A, where I make specific operator depending on the derived class type. Currently I'm using something like this: c is a class derived from A bool shouldDoX =

Re: Is this the proper way to do it?

2021-02-22 Thread Jack via Digitalmars-d-learn
On Saturday, 13 February 2021 at 19:40:43 UTC, frame wrote: On Saturday, 13 February 2021 at 05:52:34 UTC, Jack wrote: I have a base class A, where I make specific operator depending on the derived class type. Currently I'm using something like this: c is a class derived from A bool shouldDoX

Is this a good way to do lazy evaluation?

2021-02-22 Thread Jack via Digitalmars-d-learn
I have a base class that loads a value and if it isn't net, load a default value. Since the value can be set, I'd like to do lazy evaluation of this default value until it's really needed. So rather have a C defValue = xxx, that makes xxx to be loaded even if defValue doesn't get used. So I tho

How do I check if a type is assignable to null at compile time?

2021-02-25 Thread Jack via Digitalmars-d-learn
I started with: enum isAssignableNull(T) = is(T : Object) || isPointer(T); but how do I cover all cases?

  1   2   3   >