Custom separator in array format

2020-01-27 Thread Malte via Digitalmars-d-learn
I want to format an array using the %(...%) syntax. How can I change the separator? I tried to use ? and add it as additional parameter, but that doesn't seem to work on arrays: import std; void main() { writeln("This works:"); writefln("%,2?d", '_', 2000); // 20_00 auto vec = [100

Re: iopipe: Writing output to std.io File

2020-01-27 Thread Jesse Phillips via Digitalmars-d-learn
On Monday, 27 January 2020 at 18:12:40 UTC, Steven Schveighoffer wrote: Before I show you what to do, let me explain what the above actually does. 1. You constructed a buffer of characters. Good, this is the first step. 2. You used encodeText to convert the data to ubyte. Note that for char b

Re: Static fields with shared fields

2020-01-27 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/27/20 5:39 PM, Marcel wrote: Hello! If I declare a static variable inside a struct that contains a shared field, is that new variable also shared? For example, say I have a custom atomic wrapper type, like C++'s std::atomic, that contains only one shared variable: Does it remain shared wh

Re: Class member function with a Callback funtion parameter

2020-01-27 Thread Herbert via Digitalmars-d-learn
On Monday, 27 January 2020 at 22:20:42 UTC, H. S. Teoh wrote: On Mon, Jan 27, 2020 at 10:13:47PM +, Herbert via Digitalmars-d-learn wrote: On Monday, 27 January 2020 at 21:51:35 UTC, Adam D. Ruppe wrote: > On Monday, 27 January 2020 at 21:21:55 UTC, Herbert wrote: > > My project does not al

Static fields with shared fields

2020-01-27 Thread Marcel via Digitalmars-d-learn
Hello! If I declare a static variable inside a struct that contains a shared field, is that new variable also shared? For example, say I have a custom atomic wrapper type, like C++'s std::atomic, that contains only one shared variable: Does it remain shared when I instantiate one or do I have

Re: Class member function with a Callback funtion parameter

2020-01-27 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jan 27, 2020 at 10:13:47PM +, Herbert via Digitalmars-d-learn wrote: > On Monday, 27 January 2020 at 21:51:35 UTC, Adam D. Ruppe wrote: > > On Monday, 27 January 2020 at 21:21:55 UTC, Herbert wrote: > > > My project does not allow dynamic memory. So I can't use > > > delegates. > > > >

Re: Class member function with a Callback funtion parameter

2020-01-27 Thread Herbert via Digitalmars-d-learn
On Monday, 27 January 2020 at 21:51:35 UTC, Adam D. Ruppe wrote: On Monday, 27 January 2020 at 21:21:55 UTC, Herbert wrote: My project does not allow dynamic memory. So I can't use delegates. delegates do not require dynamic memory. &obj.member doesn't allocate any new memory (it just points

Re: Subrange type

2020-01-27 Thread Ali Çehreli via Digitalmars-d-learn
On 1/27/20 1:15 PM, Herbert wrote: On Monday, 27 January 2020 at 20:15:33 UTC, Steven Schveighoffer wrote: On 1/27/20 3:06 PM, Herbert wrote: How can I create a subrange type, for example ushort DiceValue {1 ... 6}? D doesn't have a "Range" type like this. But you can use ranges of different

Re: Subrange type

2020-01-27 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jan 27, 2020 at 09:15:58PM +, Herbert via Digitalmars-d-learn wrote: [...] > How can I have a function parameter with this type (DiceValue)? Just take an integer type and add a contract that enforces range. For example: auto myFunc(int diceValue) in (diceValue

Re: Class member function with a Callback funtion parameter

2020-01-27 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 27 January 2020 at 21:21:55 UTC, Herbert wrote: My project does not allow dynamic memory. So I can't use delegates. delegates do not require dynamic memory. &obj.member doesn't allocate any new memory (it just points to the existing object) yet yields a delegate.

Class member function with a Callback funtion parameter

2020-01-27 Thread Herbert via Digitalmars-d-learn
My project does not allow dynamic memory. So I can't use delegates. How can I declare a class member function with a callback function pointer?

Re: Subrange type

2020-01-27 Thread Herbert via Digitalmars-d-learn
On Monday, 27 January 2020 at 20:15:33 UTC, Steven Schveighoffer wrote: On 1/27/20 3:06 PM, Herbert wrote: How can I create a subrange type, for example ushort DiceValue {1 ... 6}? D doesn't have a "Range" type like this. But you can use ranges of different types by typing the literals. Note

Re: Subrange type

2020-01-27 Thread Paul Backus via Digitalmars-d-learn
On Monday, 27 January 2020 at 20:06:14 UTC, Herbert wrote: How can I create a subrange type, for example ushort DiceValue {1 .. 6}? Probably the closest you can get is a struct with an invariant: import std.traits: isOrderingComparable; struct Subrange(T, T min, T max) if (isOrderingCompa

Re: Subrange type

2020-01-27 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/27/20 3:06 PM, Herbert wrote: How can I create a subrange type, for example ushort DiceValue {1 ... 6}? D doesn't have a "Range" type like this. But you can use ranges of different types by typing the literals. Note that D numeric ranges are always exclusive at the upper end. e.g.: us

Re: Public constants and types in class

2020-01-27 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/27/20 3:05 PM, Herbert wrote: How can a class provide it's users with named constants, enums, types, structs and not just member functions? Just declare them inside the class. They then go inside the class namespace, but are not strictly part of the class instance itself. e.g.: class C

Subrange type

2020-01-27 Thread Herbert via Digitalmars-d-learn
How can I create a subrange type, for example ushort DiceValue {1 .. 6}?

Public constants and types in class

2020-01-27 Thread Herbert via Digitalmars-d-learn
How can a class provide it's users with named constants, enums, types, structs and not just member functions?

Re: iopipe: Writing output to std.io File

2020-01-27 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/27/20 1:12 PM, Steven Schveighoffer wrote: void writeln(Pipe)(ref Pipe sink, string text) {    enforce(sink.ensureElems(text.size) >= text.length); // make sure there's enough buffer space to hold the text    sink[0 .. text.length] = text; // write to the buffer    sink.release(text.le

Re: iopipe: Writing output to std.io File

2020-01-27 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/26/20 11:59 PM, Jesse Phillips wrote: On Monday, 27 January 2020 at 01:50:00 UTC, Jesse Phillips wrote: Just as I'm hitting send the part I'm missing clicked: I needed to add the text encoding because my buffer is `char` but File writes `ubyte` ```dlang     auto output() {     retur

Re: bindbc-opengl: Now drawing triangle

2020-01-27 Thread Luhrel via Digitalmars-d-learn
On Saturday, 25 January 2020 at 21:33:09 UTC, JN wrote: I assume it's working now? Yup it works. For future, learn to use RenderDoc: https://renderdoc.org/ it allows you to debug your OpenGL application and see what kind of data is sent by your app. Wow that's what I need. Thanks for sh

Re: How to convert this C++ code to Dlang? Please send me Dlang version of this C++ code

2020-01-27 Thread Marcone via Digitalmars-d-learn
On Monday, 27 January 2020 at 13:41:13 UTC, Ferhat Kurtulmuş wrote: On Monday, 27 January 2020 at 13:24:03 UTC, Marcone wrote: On Monday, 27 January 2020 at 13:07:20 UTC, rumbu wrote: [...] Thank you very much! But I have this error when I try to compile: Error 42: Symbol Undefined _InitCo

Re: How to convert this C++ code to Dlang? Please send me Dlang version of this C++ code

2020-01-27 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Monday, 27 January 2020 at 13:24:03 UTC, Marcone wrote: On Monday, 27 January 2020 at 13:07:20 UTC, rumbu wrote: [...] Thank you very much! But I have this error when I try to compile: Error 42: Symbol Undefined _InitCommonControls@0 Error: linker exited with status 1 I am using Resedit

Re: How to convert this C++ code to Dlang? Please send me Dlang version of this C++ code

2020-01-27 Thread Marcone via Digitalmars-d-learn
On Monday, 27 January 2020 at 13:07:20 UTC, rumbu wrote: On Monday, 27 January 2020 at 11:34:47 UTC, Marcone wrote: [...] Translated (including errors & comments): import core.sys.windows.windows; import core.sys.windows.commctrl; import std.stdio; HINSTANCE hInst; extern(Windows): BOOL D

Re: How to convert this C++ code to Dlang? Please send me Dlang version of this C++ code

2020-01-27 Thread rumbu via Digitalmars-d-learn
On Monday, 27 January 2020 at 11:34:47 UTC, Marcone wrote: #include #include #include #include "resource.h" #include HINSTANCE hInst; BOOL CALLBACK DlgMain(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch(uMsg) { case WM_INITDIALOG: { } return TRUE;

How to convert this C++ code to Dlang? Please send me Dlang version of this C++ code

2020-01-27 Thread Marcone via Digitalmars-d-learn
#include #include #include #include "resource.h" #include HINSTANCE hInst; BOOL CALLBACK DlgMain(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch(uMsg) { case WM_INITDIALOG: { } return TRUE; case WM_CLOSE: { EndDialog(hwndDlg, 0);