What's best practice to use compound literals with structs and C-APIs?

2019-05-01 Thread Robert M. Münch via Digitalmars-d-learn
I use some C library that uses structs and many functions that use pointer to structs as arguments: struct A {...}; myfunc(A *myA); In C you can do this to get a lvalue: myfunc(&(A){...}); In D this doesn't work and I get an "is not an lvalue and cannot be modified". What's the correct

Re: What's best practice to use compound literals with structs and C-APIs?

2019-05-01 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-05-01 14:23:37 +, Alex said: On Wednesday, 1 May 2019 at 12:47:22 UTC, Robert M. Münch wrote: I use some C library that uses structs and many functions that use pointer to structs as arguments: struct A {...}; myfunc(A *myA); In C you can do this to get a lvalue:

Re: What's best practice to use compound literals with structs and C-APIs?

2019-05-02 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-05-01 19:13:54 +, Alex said: Doesn't work because this seems to kick in some D releated run-time stuff which lead to unresolved externals during linking: error LNK2001: Nicht aufgelöstes externes Symbol "...__initZ". error LNK2001: Nicht aufgelöstes externes Symbol

Re: Framework design, initialization and framework usage

2019-05-06 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-05-06 17:04:47 +, Adam D. Ruppe said: I'd make that thing's constructor private, and then offer a helper template function that actually creates it and the user passes a type. Any reason why makeing things private? The struct is more like an application state to avoid globals.

Re: Framework design, initialization and framework usage

2019-05-07 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-05-07 09:06:03 +, Kagamin said: struct myFramework { myFrameworkAccessor myFWApp; } interface myFrameworkApp { void init(); } main(){ myFramework mf = new myFramework; mf.myFWApp.init(); // this bombs because myFWApp is NULL } struct

Re: Framework design, initialization and framework usage

2019-05-07 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-05-06 18:21:27 +, Adam D. Ruppe said: Just the constructor. It is so they don't try to skip a step calling the constructor themselves. But, of course, it doesn't have to be private. Ok, that makes sense. What I want to avoid is that explicit init line in main(). I did things

Re: Framework design, initialization and framework usage

2019-05-07 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-05-07 09:06:03 +, Kagamin said: struct myFramework { myFrameworkAccessor myFWApp; } interface myFrameworkApp { void init(); } main(){ myFramework mf = new myFramework; mf.myFWApp.init(); // this bombs because myFWApp is NULL } struct

Re: Framework design, initialization and framework usage

2019-05-07 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-05-07 09:06:03 +, Kagamin said: struct myFramework { myFrameworkAccessor myFWApp; } interface myFrameworkApp { void init(); } main(){ myFramework mf = new myFramework; mf.myFWApp.init(); // this bombs because myFWApp is NULL } struct

Re: Framework design, initialization and framework usage

2019-05-08 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-05-07 17:43:57 +, H. S. Teoh said: Note: it's a very bad idea to call a member function 'init'. It conflicts with the built-in .init property of all types, and can lead to strange bugs / confusing behaviours. Call it something else, like 'initialize'. Yes, thanks. I'm currently

Re: Framework design, initialization and framework usage

2019-05-08 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-05-07 18:02:16 +, Ron Tarrant said: I'm curious. What's the ultimate aim of the framework you're working on? An aid to building web apps? Desktop apps? The goal is to have a generic framework for desktop apps where you can directly start to work on the app and don't have to care

Framework design, initialization and framework usage

2019-05-06 Thread Robert M. Münch via Digitalmars-d-learn
I want to build a framework which gives some structure to the app using it. To create this structure I would like to use interfaces. The application then uses these interfaces and implements the required functions. I want to provide a clear initialization sequence for the app through the

Packages / imports & references between modules

2019-04-27 Thread Robert M. Münch via Digitalmars-d-learn
A/a.d has module A.a; A/b.d has module A.b; A/package.d import A.a; import A.b; A.b needs to access something from A.a I assumed if I do import package.d that A.b sees the content of A.a now and doens't need an explicit line with a/b.d import A.a; But this

Re: Packages / imports & references between modules

2019-04-27 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-04-27 15:06:01 +, Adam D. Ruppe said: On Saturday, 27 April 2019 at 14:58:01 UTC, Robert M. Münch wrote: import A.a; `import` by itself is a private import, meaning it cannot be seen from outside the module. Make it `public import` and it can be seen from the outside;

Re: OSX DStep / Standard Includes

2019-04-27 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-04-27 09:40:46 +, Jacob Carlborg said: I created an enhancement request for this. Hopefully it's possible to fix without having the user installing the SDK in /usr/include. https://github.com/jacob-carlborg/dstep/issues/227 Thanks! Your tip worked and yes, OSX out of the box

Re: Packages / imports & references between modules

2019-04-28 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-04-28 11:44:03 +, Mike Parker said: They're different symbols because they're in different modules. The module and package name is part of the symbol name. Ok, that's what I assumed too. Just import A.b in A.a. Won't help. I just commented the lines DStep generated for

Re: Packages / imports & references between modules

2019-04-28 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-04-27 16:30:48 +, Adam D. Ruppe said: There is no "same level" really (except for the `package` protection level); it is just inside the module or outside the module for imports. Hi Adamn, ok, got it. The docs are indicating that the "public import" is only working along the

Re: Packages / imports & references between modules

2019-04-28 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-04-27 16:30:48 +, Adam D. Ruppe said: This will never work in D. The module needs to work by itself. It can see public imports from another module it itself imports: module A.c; import A; // thanks to this, it can see a `public import A.a;` from the A package.. But without

Re: Packages / imports & references between modules

2019-04-28 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-04-28 16:18:59 +, kdevel said: This compiles with dmd v2.085.1: $ cat A/a.d module A.a; import A.b; $ cat A/b.d module A.b; struct myStruct { int i; } $ cat A/c.d module A.c; import A.a; import A.b; struct myOtherStruct { myStruct ms; } void main () { import

Re: Framework design, initialization and framework usage

2019-05-08 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-05-08 09:15:41 +, Ron Tarrant said: This sounds like a complete replacement for either QT, MFC, or GTK as well as Glade/QT Designer all rolled into one. Let's say it's an alternative ;-) All the ones you listed are either too big, too complicated, bring too much stuff that we

Associative Array & different template types

2019-07-03 Thread Robert M. Münch via Digitalmars-d-learn
I have something like: template myStruct(T){ auto makeMyStruct(T,E)(T context, void delegate(E) myFunc){ static struct myObject { this(T context, void delegate(E) myFunc){ _context = context;

Re: Associative Array & different template types

2019-07-04 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-07-03 19:07:10 +, ag0aep6g said: On 03.07.19 20:20, Robert M. Münch wrote: So, I need to carry around the object from which a delegate was created from because it's not possible to query the delegate for the object later somewhere else in the code. It is possible to get the

Transparent cast from class to member pointer?

2019-04-14 Thread Robert M. Münch via Digitalmars-d-learn
struct IM; struct C { IM *impl; }; int cInit(C* self); class I { C handler; this(){cInit();} } Is there a simple way that I can use handler without the address-of operator and automatically get *impl? Something like: class I { C handler;

OSX DStep / Standard Includes

2019-04-26 Thread Robert M. Münch via Digitalmars-d-learn
I'm trying the new DStep version but have some problems with standard include files: => dstep --output ./d -v -I/opt/local/libexec/llvm-5.0/include/c++/v1 myinclude.h clang version 5.0.2 (tags/RELEASE_502/final) Target: x86_64-apple-darwin18.5.0 Thread model: posix InstalledDir: ignoring

Re: assert in unittest has access to private member?

2019-07-01 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-06-30 17:47:27 +, a11e99z said: Private means that only members of the enclosing class can access the member, or vvv members and functions in the same module as the enclosing class.

vibe / self contained standalone executable?

2019-07-28 Thread Robert M. Münch via Digitalmars-d-learn
Is it possible to pack a complete "web-app" (serving web-pages and providing REST API) into a single executable so that no other files need to be accessed and everything is servered from something like a "virtual filesystem" which is in memory only? -- Robert M. Münch http://www.saphirion.com

Re: vibe / self contained standalone executable?

2019-07-28 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-07-28 14:14:06 +, Sebastiaan Koppe said: I am using https://dlang.org/spec/expression.html#import_expressions for text files. Don't know if it works on binary files as well. And this works than good together with the vibe framework? So, it's not requiring or forcing one to use

assert in unittest has access to private member?

2019-06-30 Thread Robert M. Münch via Digitalmars-d-learn
I have a case, with templates, where an assert in a unittest can access a private memember and I don't know how this can happen. Before trying to creat an equivalent case, I want to cross-check, if assert has special semantics in a unittest so that it can access private memembers? -- Robert

Re: Elegant way to test if members of array A are present in array B?

2019-06-14 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-06-12 13:58:49 +, Meta said: There are two versions of find that can find a range within another: https://dlang.org/phobos/std_algorithm_searching.html#.find https://dlang.org/phobos/std_algorithm_searching.html#.find.3 Thanks, that looks good. I read the find docs, but somehow

How does this template work?

2019-06-16 Thread Robert M. Münch via Digitalmars-d-learn
How does the observerObject Template and function work? I'm struggling because both use the same name and how is the template parameter R deduced/where is it coming from? Looks like it's somehow implicitly deduced. class ObserverObject(R, E...){...} template observerObject(E) {

Re: Accuracy of floating point calculations

2019-10-30 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-10-29 17:43:47 +, H. S. Teoh said: On Tue, Oct 29, 2019 at 04:54:23PM +, ixid via Digitalmars-d-learn wrote: On Tuesday, 29 October 2019 at 16:11:45 UTC, Daniel Kozak wrote: On Tue, Oct 29, 2019 at 5:09 PM Daniel Kozak wrote: AFAIK dmd use real for floating point operations

Re: Accuracy of floating point calculations

2019-10-31 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-10-31 16:07:07 +, H. S. Teoh said: Maybe you might be interested in this: https://stackoverflow.com/questions/6769881/emulate-double-using-2-floats Thanks, I know the 2nd mentioned paper. Maybe switch to PPC? :-D Well, our customers don't use PPC Laptops ;-)

Re: csvReader & specifying separator problems...

2019-11-14 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-11-14 13:08:10 +, Mike Parker said: Contents, ErrorLevel, Range, and Separator are template (i.e. compile-time) parameters. Input, delimiter, and quote are function (i.e. runtime) parameters. Mike, thanks a lot... I feel like an idiot. As casual D programmer the template-syntax

std.json / nested key/value access?

2019-11-15 Thread Robert M. Münch via Digitalmars-d-learn
I have: JSONValue j = parseJSON(json_string).object; writeln(j);// works writeln(j["a"]); // works writeln(j["a"].object["b"]); // bombs Runtime error: std.json.JSONException@std/json.d(276):

Re: std.json / nested key/value access?

2019-11-15 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-11-15 17:23:38 +, Steven Schveighoffer said: On 11/15/19 12:05 PM, Robert M. Münch wrote: JSONValue j = parseJSON(json_string).object;  writeln(j); // works  writeln(j["a"]); // works  writeln(j["a"].object["b"]); // bombs

Re: Read Once then reset/init value?

2019-11-03 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-10-29 23:28:35 +, Simen Kjærås said: On Tuesday, 29 October 2019 at 22:24:20 UTC, Robert M. Münch wrote: I quite often have the pattern where a value should be read just once and after this reset itself. The idea is to avoid that others read the value by accident and get an older

Re: Strange casting error when using lamdas

2019-12-04 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-12-03 16:34:43 +, Robert M. Münch said: I have very strange casting error I don't understand: alias typeof(windows_message_streams[WM_MOUSEMOVE].filter!(win => (win.wParam & MK_LBUTTON))) WM_MOUSEMOVE_LBUTTON_TYPE; WM_MOUSEMOVE_LBUTTON_TYPE WM_MOUSEMOVE_LBUTTON_STREAM;

Strange casting error when using lamdas

2019-12-03 Thread Robert M. Münch via Digitalmars-d-learn
I have very strange casting error I don't understand: alias typeof(windows_message_streams[WM_MOUSEMOVE].filter!(win => (win.wParam & MK_LBUTTON))) WM_MOUSEMOVE_LBUTTON_TYPE; WM_MOUSEMOVE_LBUTTON_TYPE WM_MOUSEMOVE_LBUTTON_STREAM; pragma(msg,typeof(WM_MOUSEMOVE_LBUTTON_STREAM));

Re: Strange casting error when using lamdas

2019-12-03 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-12-03 16:34:43 +, Robert M. Münch said: I have very strange casting error I don't understand: alias typeof(windows_message_streams[WM_MOUSEMOVE].filter!(win => (win.wParam & MK_LBUTTON))) WM_MOUSEMOVE_LBUTTON_TYPE; WM_MOUSEMOVE_LBUTTON_TYPE WM_MOUSEMOVE_LBUTTON_STREAM;

Re: Strange casting error when using lamdas

2019-12-05 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-12-04 19:23:07 +, Steven Schveighoffer said: Is one a delegate and one a function pointer? This can easily happen for untyped lambdas. Not sure if the code-snippets already give an explanation but the differences I have are: 1. Working case template filter(alias pred) {

Re: Strange casting error when using lamdas

2019-12-05 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-12-04 19:23:07 +, Steven Schveighoffer said: Is one a delegate and one a function pointer? This can easily happen for untyped lambdas. That's a very good point and hint. A function pointer will be 8LU and a delegate 16LU, right? This is a strong argument that this is really the

... use of ... is hidden by ...; use alias ... to introduce base class overload set ??

2019-10-20 Thread Robert M. Münch via Digitalmars-d-learn
I get this error message, which doesn't tell me a lot: rx_filter_subject.d(38,8): Error: class rx_filter_subject.FilterSubject use of rx.subject.SubjectObject!(message).SubjectObject.subscribe(Observer!(message) observer) is hidden by FilterSubject; use alias subscribe =

Re: ... use of ... is hidden by ...; use alias ... to introduce base class overload set ??

2019-10-25 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-10-24 19:45:42 +, Ali ‡ehreli said: One practical reason is, the number of their instances cannot be known when the interface (or base class) is compiled. ... Ali, first, thanks a lot for your answers. If the compiler is a 1-pass one I see the problem, otherwise one could

Re: ... use of ... is hidden by ...; use alias ... to introduce base class overload set ??

2019-10-21 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-10-21 07:04:33 +, John Chapman said: This should work: class FilterSubject : SubjectObject!message { alias subscribe = typeof(super).subscribe; Disposable subscribe(myWidget observer){...} } This now gives: rx_filter_subject.d(66,23): Error:

Re: ... use of ... is hidden by ...; use alias ... to introduce base class overload set ??

2019-10-24 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-10-23 17:22:38 +, Ali ‡ehreli said: On 10/23/2019 02:43 AM, Robert M. Münch wrote: >> Unfortunately, member function template instances are never virtual >> functions, so you can't override them. > > What I don't understand is: > > 1. The RX lib has a member function

Read Once then reset/init value?

2019-10-29 Thread Robert M. Münch via Digitalmars-d-learn
I quite often have the pattern where a value should be read just once and after this reset itself. The idea is to avoid that others read the value by accident and get an older state, instead they get an "invalid/reset" value. Is there a library function that can mimic such a behaviour? --

Re: ... use of ... is hidden by ...; use alias ... to introduce base class overload set ??

2019-10-22 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-10-21 18:02:06 +, Robert M. Münch said: This now gives: rx_filter_subject.d(66,23): Error: rx_filter_subject.FilterSubject.subscribe called with argument types (myWidget) matches both: /Users/robby/.dub/packages/rx-0.13.0/rx/source/rx/subject.d(72,16):

Re: ... use of ... is hidden by ...; use alias ... to introduce base class overload set ??

2019-10-26 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-10-25 15:20:21 +, Ali ‡ehreli said: On 10/25/2019 07:34 AM, Robert M. Münch wrote: > If the compiler is a 1-pass one I see the problem, otherwise one could > first get a "total overview" and create the necessary vtbl entries after > everything is known. Maybe this is not "how a

Re: Good way let low-skill people edit CSV files with predefined row names?

2019-10-26 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-10-24 16:03:26 +, Dukc said: We're planning to have our product preview program to calculate and suggest a price for the product displayed. There are a lot of variables to take into account, so it's essential the users can edit the price variables themselves. Hi, maybe you want

Re: ... use of ... is hidden by ...; use alias ... to introduce base class overload set ??

2019-10-23 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-10-22 20:59:41 +, Ali ‡ehreli said: That says "private paste" for me. Ups, sorry and thanks for letting me know. But I think you have a member function template in the base class. This the lib I use: https://github.com/lempiji/rx/blob/dev/source/rx/subject.d and which

static assert(version(x)) ?

2019-11-26 Thread Robert M. Münch via Digitalmars-d-learn
How can I write something like this to check if any of a set of specific versions is used? static assert(!(version(a) | version(b) | version(c)): The problem is that I can use version(a) like a test, and the symbol a is not accessbile from assert (different, non-accessible namespace). --

Re: Template mixin / unresolved external / scope problem?

2019-11-29 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-11-28 16:36:36 +, Jacob Carlborg said: Are you using the latest version, 2.089.0? It might be fixed in that version [1]. [1] https://dlang.org/changelog/2.089.0.html#mixin_template_mangling Ha! Thanks Jacob, that looks like the root-cause. Didn't expect to use a feature which

Re: static assert(version(x)) ?

2019-11-28 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-11-27 18:50:07 +, Johan Engelen said: On Tuesday, 26 November 2019 at 12:53:02 UTC, Jonathan M Davis wrote: On Tuesday, November 26, 2019 4:29:18 AM MST S.G via Digitalmars-d-learn wrote: On Tuesday, 26 November 2019 at 10:24:00 UTC, Robert M. Münch wrote: How can I write

Re: Accuracy of floating point calculations

2019-10-31 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-10-30 15:12:29 +, H. S. Teoh said: It wasn't a wrong *decision* per se, but a wrong *prediction* of where the industry would be headed. Fair point... Walter was expecting that people would move towards higher precision, but what with SSE2 and other such trends, and the general

csvReader & specifying separator problems...

2019-11-14 Thread Robert M. Münch via Digitalmars-d-learn
Just trying a very simple thing and it's pretty hard: "Read a CSV file (raw_data) that has a ; separator so that I can iterate over the lines and access the fields." csv_data = raw_data.byLine.joiner("\n") From the docs, which I find extremly hard to understand: auto 

Template mixin / unresolved external / scope problem?

2019-11-28 Thread Robert M. Münch via Digitalmars-d-learn
I have: a.d: extern (C) void myFuncA(); void myFuncB() { myFuncA(); } b.d: public import a; mixin template MYFUNCA() { extern (C) void myFuncA() {...} } c.d: import b; mixin MYFUNCA; ...further code... Compiling such a structure gives me an unresolved external in

Undefined symbol: _dyld_enumerate_tlv_storage (OSX)

2019-10-10 Thread Robert M. Münch via Digitalmars-d-learn
I have two project I want to compile and both times get this error: Undefined symbols for architecture x86_64: "_dyld_enumerate_tlv_storage", referenced from: __d_dyld_getTLSRange in libphobos2.a(osx_tls.o) I'm wondering where this comes from as I didn't see it in the past. Any idea? --

Re: Undefined symbol: _dyld_enumerate_tlv_storage (OSX)

2019-10-11 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-10-10 18:31:25 +, Daniel Kozak said: What dmd version? I think I had an older one like 2.085 or so. I updated to 2.088 and it now seems to work. https://issues.dlang.org/show_bug.cgi?id=20019 I'm on OSX 10.14.6, so this might not be directly related to Catalina but maybe

Re: Undefined symbol: _dyld_enumerate_tlv_storage (OSX)

2019-10-14 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-10-11 18:09:01 +, Jacob Carlborg said: No, I don't think that's the problem. I have the same setup and I don't have this problem. Interesting... but the update seems to have solved the problem. Maybe some old DMD compiler stuff lying around got in the way. What result do you

D-ish way to work with strings?

2019-12-22 Thread Robert M. Münch via Digitalmars-d-learn
I want to do all the basics mutating things with strings: append, insert, replace What is the D-ish way to do that since string is aliased to immutable(char)[]? Using arrays, using ~ operator, always copying, changing, combining my strings into a new one? Does it make sense to think about

Re: D-ish way to work with strings?

2019-12-22 Thread Robert M. Münch via Digitalmars-d-learn
Want to add I'm talking about unicode strings. Wouldn't it make sense to handle everything as UTF-32 so that iteration is simple because code-point = code-unit? And later on, convert to UTF-16 or UTF-8 on demand? -- Robert M. Münch http://www.saphirion.com smarter | better | faster

How to explicitly state the expression in with(...)?

2020-02-01 Thread Robert M. Münch via Digitalmars-d-learn
I have quite often this pattern: with(x.y.z){ xyzFunc(); // = x.y.z.xyzFunc() myFunc(x.y.z, ...); } and it would be cool to write: with(t = x.y.z){ // work like an implicit alias xyzFunc(); // = x.y.z.xyzFunc() myFunc(t, ...); } Is there anything

dub / use git branch

2020-02-16 Thread Robert M. Münch via Digitalmars-d-learn
I want to use a specific branch version if a package. I specified the branch version in a dub.selections.json file. But it seems that dub requires a ZIP file that can be downloaded from code.dlang.org, which of course fails because the branch is only available on github. Fetching rtree

Dynamic array of Cycle buffers of size 2 which use a struct?

2020-02-22 Thread Robert M. Münch via Digitalmars-d-learn
I don't get how I can create a dynamic array of Cycle buffers of size 2 which use a struct. struct ms { int a; int b; } ms[2] msBuffer; alias circularStructBuffersT = typeof(cycle(msBuffer)); circularStructBuffersT[int] circularStructBuffers; int i = 2; auto x =

How to use -profile when I initialize D-runtime myself?

2020-01-15 Thread Robert M. Münch via Digitalmars-d-learn
Hi, I had a related question in the "Does -profile need the D runtime?" thread. Since D runtime is required for profile to work, the question is how can I use profile when initializing it myself? -- Robert M. Münch http://www.saphirion.com smarter | better | faster

Re: What type does byGrapheme() return?

2019-12-29 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-12-27 19:44:59 +, H. S. Teoh said: Since graphemes are variable-length in terms of code points, you can't exactly *edit* a range of graphemes -- you can't replace a 1-codepoint grapheme with a 6-codepoint grapheme, for example, since there's no space in the underlying string to

Re: What type does byGrapheme() return?

2019-12-29 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-12-27 17:54:28 +, Steven Schveighoffer said: This is the rub with ranges. You need to use typeof. There's no other way to do it, because the type returned by byGrapheme depends on the type of Range. Hi, ok, thanks a lot and IMO these are the fundamental important information for

What type does byGrapheme() return?

2019-12-27 Thread Robert M. Münch via Digitalmars-d-learn
I love these documentation lines in the D docs: auto byGrapheme(Range)(Range range) How should I know what auto is? Why not write the explicit type so that I know what to expect? When declaring a variable as class/struct member I can't use auto but need the explicit type... I used

decodeGrapheme & static array

2020-01-04 Thread Robert M. Münch via Digitalmars-d-learn
I have: Grapheme[] gr; dchar[1] buf; encode(buf, cast(dchar)myData); gr =~ decodeGrapheme(buf[]); Which gives: Error: template std.uni.decodeGrapheme cannot deduce function from argument types !()(dchar[]), candidates are: C:\D\dmd2\windows\bin\..\..\src\phobos\std\uni.d(7164,10):

Re: What type does byGrapheme() return?

2020-01-04 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-12-31 21:36:56 +, Steven Schveighoffer said: The fact that a Grapheme's return requires you keep the grapheme in scope for operations seems completely incorrect and dangerous IMO (note that operators are going to always have a ref this, even when called on an rvalue). So even

Re: What type does byGrapheme() return?

2020-01-06 Thread Robert M. Münch via Digitalmars-d-learn
On 2020-01-05 04:18:34 +, H. S. Teoh said: At a minimum, I think we should file a bug report to investigate whether Grapheme.opSlice can be implemented differently, such that we avoid this obscure referential behaviour that makes it hard to work with in complex code. I'm not sure if this is

What is the difference between a[x][y] and a[x,y]?

2020-01-07 Thread Robert M. Münch via Digitalmars-d-learn
I read all the docs but I'm not toally sure. Is it that [x][y] is a 2D array-index, where as [x,y] is a slice? But the example in docs for opIndexAssign uses the [x,y] syntax, which is confusing: ``` struct A { int opIndexAssign(int value, size_t i1, size_t i2); } void test() { A a;

Re: What is the difference between a[x][y] and a[x,y]?

2020-01-07 Thread Robert M. Münch via Digitalmars-d-learn
On 2020-01-07 17:42:48 +, Adam D. Ruppe said: So [x][y] indexes an array of arrays. Yes, that's what I understand. And both can be dynamic, so that I can have a "flattering" layout where not all arrays have the same length. [x,y] indexes a single array that has two dimensions. Does

Re: D-ish way to work with strings?

2019-12-27 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-12-22 18:45:52 +, Steven Schveighoffer said: switch to using char[]. Unfortunately, there's a lot of code out there that accepts string instead of const(char)[], which is more usable. I think many people don't realize the purpose of the string type. It's meant to be something that

Re: D-ish way to work with strings?

2019-12-27 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-12-23 15:05:20 +, H. S. Teoh said: On Sun, Dec 22, 2019 at 06:27:03PM +0100, Robert M. Münch via Digitalmars-d-learn wrote: Want to add I'm talking about unicode strings. Wouldn't it make sense to handle everything as UTF-32 so that iteration is simple because code-point = code

Re: What is the difference between a[x][y] and a[x,y]?

2020-01-08 Thread Robert M. Münch via Digitalmars-d-learn
On 2020-01-07 19:06:09 +, H. S. Teoh said: It's up to you how to implement all of this, of course. The language itself doesn't ship a built-in type that implements this, but it does provide the scaffolding for you to build a custom multi-dimensional array type. Hi, thanks for your

Re: std.datetime & timzone specifier: 2018-11-06T16:52:03+01:00

2020-03-08 Thread Robert M. Münch via Digitalmars-d-learn
On 2020-03-07 12:10:27 +, Jonathan M Davis said: I take it that you're asking why you don't get the time zone as part of the string when you call one of the to*String functions? The problem is, the from* functions give an error, that this is not an ISO date. I get this in an XML

std.datetime & timzone specifier: 2018-11-06T16:52:03+01:00

2020-03-07 Thread Robert M. Münch via Digitalmars-d-learn
It looks like std.datetime is not anticipating the +1:00 part of a date like: "2018-11-06T16:52:03+01:00" Those dates are used all over on the internet and I'mm wondering why it's not supported. Any reason? Is this +01:00 not ISO conforming? -- Robert M. Münch http://www.saphirion.com

Re: static foreach / How to construct concatenated string?

2020-03-08 Thread Robert M. Münch via Digitalmars-d-learn
On 2020-03-07 16:41:47 +, MoonlightSentinel said: You can use an anonymous lambda to build the string in CTFE: -- struct S { int a; bool b; } import std; enum string sql = { string s = "CREATE TABLE data("; static foreach(f;

Re: static foreach / How to construct concatenated string?

2020-03-08 Thread Robert M. Münch via Digitalmars-d-learn
On 2020-03-07 16:41:47 +, MoonlightSentinel said: On Saturday, 7 March 2020 at 16:30:59 UTC, Robert M. Münch wrote: Is this possible at all? You can use an anonymous lambda to build the string in CTFE: -- struct S { int a; bool b; }

static foreach / How to construct concatenated string?

2020-03-07 Thread Robert M. Münch via Digitalmars-d-learn
I want to create a "CREATE TABLE data (...)" where the columns are derived from struct member names. Something like: string s = "CREATE TABLE data("; static foreach(f; FieldNameTuple!myStruct) { s ~= f ~ ","; } s ~= ");"; Which of course doesn't work... I didn't find any reference how to

__init unresolved external when using C library structs converted with dstep

2020-04-14 Thread Robert M. Münch via Digitalmars-d-learn
I use a C libary and created D imports with dstep. It translates the C structs to D structs. When I now use them, everything compiles fine but I get an unresolved external error: WindowsApp1.obj : error LNK2019: unresolved external symbol "myCstruct.__init" (_D7myCStruct6__initZ) referenced

Re: __init unresolved external when using C library structs converted with dstep

2020-04-14 Thread Robert M. Münch via Digitalmars-d-learn
On 2020-04-14 18:23:05 +, Steven Schveighoffer said: On 4/14/20 1:51 PM, Robert M. Münch wrote: I use a C libary and created D imports with dstep. It translates the C structs to D structs. When I now use them, everything compiles fine but I get an unresolved external error:

Wich: opIndex overloading by return type

2020-04-19 Thread Robert M. Münch via Digitalmars-d-learn
Wouldn't it make a lot of sense to allow different opIndex implementations based on return type? class myC { myT1 opIndex(int x) myT2 opIndex(int x) } Depending on the types involved myC[1] woudl return myT1 or myT2. Use-case: I have a geomentry object and in one case I get

Re: __init unresolved external when using C library structs converted with dstep

2020-04-15 Thread Robert M. Münch via Digitalmars-d-learn
On 2020-04-14 18:44:55 +, Steven Schveighoffer said: On 4/14/20 2:29 PM, Robert M. Münch wrote: Ah, ok. That's why the problem went (temporarly) away when I did a: myCstruct a = {0,0}; for example? I don't know what causes it to be emitted when. Sometimes it doesn't make a whole lot of

Re: __init unresolved external when using C library structs converted with dstep

2020-04-17 Thread Robert M. Münch via Digitalmars-d-learn
On 2020-04-17 09:06:44 +, Dominikus Dittes Scherkl said: On Friday, 17 April 2020 at 08:59:41 UTC, Robert M. Münch wrote: How would that look like? myStruct ms = void; // ??? Exactly. Cool... never saw this / thought about it... will remember it, hopefully. -- Robert M. Münch

Re: __init unresolved external when using C library structs converted with dstep

2020-04-17 Thread Robert M. Münch via Digitalmars-d-learn
On 2020-04-16 18:33:51 +, Basile B. said: On Tuesday, 14 April 2020 at 17:51:58 UTC, Robert M. Münch wrote: I use a C libary and created D imports with dstep. It translates the C structs to D structs. When I now use them, everything compiles fine but I get an unresolved external error:

Re: __init unresolved external when using C library structs converted with dstep

2020-04-16 Thread Robert M. Münch via Digitalmars-d-learn
On 2020-04-15 15:18:43 +, Steven Schveighoffer said: The difference is you are telling the compiler that it should generate any symbols for those types. If you just import them, then it's expecting something else to build those symbols. Maybe I'm a bit confused, but that's quite

Re: No implicit opOpAssign for structs with basic types?

2020-04-04 Thread Robert M. Münch via Digitalmars-d-learn
On 2020-04-04 10:32:32 +, Ferhat Kurtulmuş said: Probably I didn't understand what you mean. Sorry if this is not the case, but this one is easy. ... struct S { float a; float b; S opOpAssign(string op)(ref S rhs) if (op == "+"){ this.a += rhs.a; this.b +=

Re: No implicit opOpAssign for structs with basic types?

2020-04-04 Thread Robert M. Münch via Digitalmars-d-learn
On 2020-04-04 10:32:32 +, Ferhat Kurtulmuş said: struct S { float a; float b; S opOpAssign(string op)(ref S rhs) if (op == "+"){ this.a += rhs.a; this.b += rhs.b; return this; } } If the struct is from some 3rd party source, how can I add

No implicit opOpAssign for structs with basic types?

2020-04-04 Thread Robert M. Münch via Digitalmars-d-learn
D doesn't have implicit operators for structs? struct S {float a, float b}; S a = {1, 5}; S b = {2, 5); a += b; Error: a is not a scalar, it is a S So I really have to write an overloaded operator for such cases? -- Robert M. Münch http://www.saphirion.com smarter | better | faster

Dynamically init a struct with values calculated from other values in the struct?

2020-04-04 Thread Robert M. Münch via Digitalmars-d-learn
I need to dynamically initialize a fixed number of entries of the form: (start, length) and iterate over them. Hence, I think a struct makes sense: struct S { s1, l1 , s2, l2 , s3, l3 } Now I need to initialize the values like this: S myS = {s1:0, l1:10, s2:(2*s1), ...}; So I somehow

Idomatic way to guarantee to run destructor?

2020-04-30 Thread Robert M. Münch via Digitalmars-d-learn
For ressource management I mostly use this pattern, to ensure the destructor is run: void myfunc(){ MyClass X = new MyClass(); scope(exit) X.destroy; } I somewhere read, this would work too: void myfunc(){ auto MyClass X = new MyClass(); } What does this "auto" does here? Wouldn't void

Re: Idomatic way to guarantee to run destructor?

2020-05-02 Thread Robert M. Münch via Digitalmars-d-learn
On 2020-04-30 17:04:43 +, Ben Jones said: I think you want to use scope rather than auto which will put the class on the stack and call its destructor: https://dlang.org/spec/attribute.html#scope Yes, thanks. -- Robert M. Münch http://www.saphirion.com smarter | better | faster

Re: Idomatic way to guarantee to run destructor?

2020-05-02 Thread Robert M. Münch via Digitalmars-d-learn
On 2020-04-30 17:45:24 +, Steven Schveighoffer said: No, auto is declaring that there's about to be a variable here. In actuality, auto does nothing in the first case, it just means local variable. But without the type name, the type is inferred (i.e. your second example). This does not

Re: Idomatic way to guarantee to run destructor?

2020-05-02 Thread Robert M. Münch via Digitalmars-d-learn
On 2020-05-02 18:18:44 +, Steven Schveighoffer said: On 5/2/20 4:44 AM, Robert M. Münch wrote: How would that help, because the class instance is now unusable anyway. So I have it around like a zombie and others might think: "Hey you look normal, let's get in contact" and then you are

countUntil with negated pre-defined predicate?

2020-05-02 Thread Robert M. Münch via Digitalmars-d-learn
This works: countUntil!(std.uni.isWhite)("hello world")) How can I switch this to (not working); countUntil!(!std.uni.isWhite)("hello world")) without having to write my own predicate? Or is there an even better way to search for all "drawable unicode characters"? -- Robert

Re: countUntil with negated pre-defined predicate?

2020-05-04 Thread Robert M. Münch via Digitalmars-d-learn
On 2020-05-03 21:59:54 +, Harry Gillanders said: I'm unsure as to which part is unclear, Well, I was trapped by this formatting/syntax: size_t drawableCharacterCount (CodePoints) (auto ref CodePoints codePoints) if (isInputRange!CodePoints && is(ElementType!CodePoints :

Are compile time generated, stable and unique IDs possible?

2020-05-08 Thread Robert M. Münch via Digitalmars-d-learn
Let's assume I have an GUI application and I want to record some user-actions which can be replayed. And this replay should be possible even if the application layout changes. Hence, I somehow need to identify the run-time objects in a way that this identification stays the same while the app

Re: static foreach / How to construct concatenated string?

2020-03-07 Thread Robert M. Münch via Digitalmars-d-learn
On 2020-03-07 16:40:15 +, Adam D. Ruppe said: Use regular foreach with a regular string. Put that inside a function. Then simply use that function to initialize your other thing and enjoy the magic of CTFE! Perfect! This implicit CTFE is a tricky thing to see/remember/... Feeling a bit

Re: Idomatic way to guarantee to run destructor?

2020-05-03 Thread Robert M. Münch via Digitalmars-d-learn
On 2020-05-02 20:43:16 +, Steven Schveighoffer said: destroy sets all the values to the .init value. And it nulls the vtable pointer. Ok, that makes sense. Thanks for all the deep internal details. There is always a lot to learn. -- Robert M. Münch http://www.saphirion.com smarter |

<    1   2   3   4   >