Re: Generically call a function on Variant's payload?

2018-08-20 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, August 20, 2018 8:29:30 PM MDT Nick Sabalausky (Abscissa) via Digitalmars-d-learn wrote: > On 08/20/2018 04:34 PM, Jonathan M Davis wrote: > > foreach(T; TypesThatVariantHolds) > > Yea, that's what I would've just done, but I wanted to support > user-created types not already

Re: Generically call a function on Variant's payload?

2018-08-20 Thread Nick Sabalausky (Abscissa) via Digitalmars-d-learn
On 08/20/2018 04:34 PM, Jonathan M Davis wrote: foreach(T; TypesThatVariantHolds) Yea, that's what I would've just done, but I wanted to support user-created types not already known to my library. You can't just call functions on completely unknown types, because the compiler

Re: D need an ORM library!

2018-08-20 Thread binghoo dang via Digitalmars-d-learn
On Monday, 20 August 2018 at 23:24:04 UTC, Matthias Klumpp wrote: On Monday, 20 August 2018 at 15:58:37 UTC, Jesse Phillips wrote: [...] There are a number of things out there, but personally don't know there state or simplicity. 2016 there was a talk: http://dconf.org/2016/talks/nowak.html

Re: Auto keyword and when to use it

2018-08-20 Thread Mike Parker via Digitalmars-d-learn
On Monday, 20 August 2018 at 17:24:19 UTC, QueenSvetlana wrote: I'm struggling to understand what the auto keyword is for and it's appropriate uses. From research, it seems to share the same capabilities as the var keyword in C#. auto is one of the most misunderstood understood features in

Re: D need an ORM library!

2018-08-20 Thread Matthias Klumpp via Digitalmars-d-learn
On Monday, 20 August 2018 at 15:58:37 UTC, Jesse Phillips wrote: [...] There are a number of things out there, but personally don't know there state or simplicity. 2016 there was a talk: http://dconf.org/2016/talks/nowak.html But personally I preferred this one:

Re: Pure opEquals in a class

2018-08-20 Thread ag0aep6g via Digitalmars-d-learn
On Monday, 20 August 2018 at 19:36:15 UTC, werter wrote: The code below doesn't work. Is it possible to make a pure opEquals in a class? [...] pure bool opEquals(const A rhs) const { return b == rhs.b; } It doesn't

Re: Generically call a function on Variant's payload?

2018-08-20 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, August 20, 2018 1:38:13 PM MDT Nick Sabalausky (Abscissa) via Digitalmars-d-learn wrote: > There are a bunch of discriminated union types available for D, but the > only one I'm aware of that *doesn't* require a finite-sized list of > types known ahead-of-time is Phobos's Variant. The

Re: Trouble with LDC2 and definition file to hide console?

2018-08-20 Thread kinke via Digitalmars-d-learn
For LDC, just rename your main() to WinMain(). Or alternatively, `-L/SUBSYSTEM:WINDOWS -L/ENTRY:mainCRTStartup` in the LDC cmdline.

Re: Generically call a function on Variant's payload?

2018-08-20 Thread Nick Sabalausky (Abscissa) via Digitalmars-d-learn
On 08/19/2018 11:31 PM, Paul Backus wrote: You are basically reinventing OOP here. Yes, I am. Deliberately, in fact. Class inheritance is my backup plan, though. My use-case is actually very, very similar to std.digest: There are various benefits to using a template-and-constraint based

Pure opEquals in a class

2018-08-20 Thread werter via Digitalmars-d-learn
The code below doesn't work. Is it possible to make a pure opEquals in a class? void main() { class A { bool a; int b; this(bool g, int h) { a = g; b

Re: Trouble with LDC2 and definition file to hide console?

2018-08-20 Thread kinke via Digitalmars-d-learn
On Monday, 20 August 2018 at 13:49:19 UTC, rikki cattermole wrote: That is for Optlink not for MSVC link which ldc uses. Exactly. For LDC, just rename your main() to WinMain().

Dub and it's build directory

2018-08-20 Thread Russel Winder via Digitalmars-d-learn
Hi, Given a package X, let us assume it's a library such that X = unit- threaded, we find that in the ~/.dub/packages directory there is: .dub/packages/unit-threaded-0.7.51/unit-threaded/gen_ut_main* .dub/packages/unit-threaded-0.7.51/unit-threaded/libunit-threaded.a These are the compilation

Re: D need an ORM library!

2018-08-20 Thread Russel Winder via Digitalmars-d-learn
On Mon, 2018-08-20 at 15:58 +, Jesse Phillips via Digitalmars-d- learn wrote: > On Monday, 20 August 2018 at 02:30:16 UTC, binghoo dang wrote: > > hi, > > > > I thinks D need an ORM library for Sqlite/Mysql/PostgreSQL, > > entity currently support all the three targets, but entity's > > API

Re: Auto keyword and when to use it

2018-08-20 Thread JN via Digitalmars-d-learn
On Monday, 20 August 2018 at 17:52:17 UTC, QueenSvetlana wrote: Great! So I can't declare class level variables with auto, correct? only local method variables? You can, globals, class members: class Foo { auto bar = "hi"; } Foo.bar will be of string type here, because "hi" is a

Re: Auto keyword and when to use it

2018-08-20 Thread Colin via Digitalmars-d-learn
On Monday, 20 August 2018 at 17:52:17 UTC, QueenSvetlana wrote: Great! So I can't declare class level variables with auto, correct? only local method variables? You can use auto if you're setting the class level variable to a default. class X { auto i = 42; // i will be an int }

Re: Auto keyword and when to use it

2018-08-20 Thread QueenSvetlana via Digitalmars-d-learn
Great! So I can't declare class level variables with auto, correct? only local method variables?

Re: Deduce type of struct in function arguments

2018-08-20 Thread Seb via Digitalmars-d-learn
On Monday, 20 August 2018 at 12:33:34 UTC, Andrey wrote: On Monday, 20 August 2018 at 11:38:39 UTC, Paul Backus wrote: Create an overload of foo that takes two arguments and combines them into a `Data` struct internally: void foo(int a, string text) { Data data = {a, text}; foo(data);

Re: Auto keyword and when to use it

2018-08-20 Thread JN via Digitalmars-d-learn
On Monday, 20 August 2018 at 17:24:19 UTC, QueenSvetlana wrote: I'm new to D programming, but have I have a background with Python. I'm struggling to understand what the auto keyword is for and it's appropriate uses. From research, it seems to share the same capabilities as the var keyword

Auto keyword and when to use it

2018-08-20 Thread QueenSvetlana via Digitalmars-d-learn
I'm new to D programming, but have I have a background with Python. I'm struggling to understand what the auto keyword is for and it's appropriate uses. From research, it seems to share the same capabilities as the var keyword in C#. From the C# documentation, it states:

Re: UDA on double nested struct

2018-08-20 Thread Sebastiaan Koppe via Digitalmars-d-learn
On Monday, 20 August 2018 at 16:27:55 UTC, Basile B. wrote: Hello, it works fine here. Maybe there was another error that you removed when you have minimized the example. See https://run.dlang.io/is/ZrW7kI, that says that the example works since 2.068.2. Although that are are possibility that

Re: Make function alias

2018-08-20 Thread Basile B. via Digitalmars-d-learn
On Monday, 20 August 2018 at 13:14:14 UTC, Andrey wrote: Hello, I want to make an alias to function "std.stdio.writeln" and "std.stdio.write" and use it like: static void log(bool newline = true)(string text) { alias print(T...) = newline ? : _file.print(); text.print(); }

Re: UDA on double nested struct

2018-08-20 Thread Basile B. via Digitalmars-d-learn
On Monday, 20 August 2018 at 16:16:04 UTC, Sebastiaan Koppe wrote: Hey, I am trying to get UDAs from a doubly nested struct, to no avail: code --- import std.traits : hasUDA; enum hover; struct Style { struct Root { auto margin = "10px"; auto backgroundColor = "white"; @hover

UDA on double nested struct

2018-08-20 Thread Sebastiaan Koppe via Digitalmars-d-learn
Hey, I am trying to get UDAs from a doubly nested struct, to no avail: code --- import std.traits : hasUDA; enum hover; struct Style { struct Root { auto margin = "10px"; auto backgroundColor = "white"; @hover struct Hover { auto backgroundColor = "gray"; } } }

Re: Make function alias

2018-08-20 Thread Andrey via Digitalmars-d-learn
On Monday, 20 August 2018 at 13:35:07 UTC, ag0aep6g wrote: On 08/20/2018 03:14 PM, Andrey wrote: Thanks everybody for your answers.

Re: D need an ORM library!

2018-08-20 Thread Jesse Phillips via Digitalmars-d-learn
On Monday, 20 August 2018 at 02:30:16 UTC, binghoo dang wrote: hi, I thinks D need an ORM library for Sqlite/Mysql/PostgreSQL, entity currently support all the three targets, but entity's API is too complex and cumbersome for using. Is there a more light-weight and simpler implementation

Re: Trouble with LDC2 and definition file to hide console?

2018-08-20 Thread rikki cattermole via Digitalmars-d-learn
On 21/08/2018 1:42 AM, spikespaz wrote: I am trying to add a *.def file to my program to hide the console window on launch, as it doesn't need to display anything to function. It is a Windows only application. I saw at this post (https://forum.dlang.org/post/ilj5vn$ef4$1...@digitalmars.com)

Re: Trouble with LDC2 and definition file to hide console?

2018-08-20 Thread spikespaz via Digitalmars-d-learn
On Monday, 20 August 2018 at 13:42:58 UTC, spikespaz wrote: I am trying to add a *.def file to my program to hide the console window on launch, as it doesn't need to display anything to function. It is a Windows only application. [...] Also adding that the linker flag I have stated above

Trouble with LDC2 and definition file to hide console?

2018-08-20 Thread spikespaz via Digitalmars-d-learn
I am trying to add a *.def file to my program to hide the console window on launch, as it doesn't need to display anything to function. It is a Windows only application. I saw at this post (https://forum.dlang.org/post/ilj5vn$ef4$1...@digitalmars.com) that I could either use a linker flag,

Re: Make function alias

2018-08-20 Thread ag0aep6g via Digitalmars-d-learn
On 08/20/2018 03:14 PM, Andrey wrote: Hello, I want to make an alias to function "std.stdio.writeln" and "std.stdio.write" and use it like: static void log(bool newline = true)(string text) {    alias print(T...) = newline ? :    _file.print();    text.print(); } Unfortunately, it

Re: Make function alias

2018-08-20 Thread Paul Backus via Digitalmars-d-learn
On Monday, 20 August 2018 at 13:14:14 UTC, Andrey wrote: Hello, I want to make an alias to function "std.stdio.writeln" and "std.stdio.write" and use it like: static void log(bool newline = true)(string text) { alias print(T...) = newline ? : _file.print(); text.print(); }

Re: Make function alias

2018-08-20 Thread vit via Digitalmars-d-learn
On Monday, 20 August 2018 at 13:22:02 UTC, Andrey wrote: On Monday, 20 August 2018 at 13:14:14 UTC, Andrey wrote: Mistake... this is: static void log(bool newline = true)(string text) { alias print(T...) = newline ? : _file.print(text); text.print(); } static void log(bool newline

Re: Make function alias

2018-08-20 Thread Andrey via Digitalmars-d-learn
On Monday, 20 August 2018 at 13:14:14 UTC, Andrey wrote: Mistake... this is: static void log(bool newline = true)(string text) { alias print(T...) = newline ? : _file.print(text); text.print(); }

Re: Deduce type of struct in function arguments

2018-08-20 Thread Paul Backus via Digitalmars-d-learn
On Monday, 20 August 2018 at 12:33:34 UTC, Andrey wrote: On Monday, 20 August 2018 at 11:38:39 UTC, Paul Backus wrote: Create an overload of foo that takes two arguments and combines them into a `Data` struct internally: void foo(int a, string text) { Data data = {a, text}; foo(data);

Make function alias

2018-08-20 Thread Andrey via Digitalmars-d-learn
Hello, I want to make an alias to function "std.stdio.writeln" and "std.stdio.write" and use it like: static void log(bool newline = true)(string text) { alias print(T...) = newline ? : _file.print(); text.print(); } Unfortunately, it doesn't work... Also tried with "enum print

Re: Deduce type of struct in function arguments

2018-08-20 Thread Andrey via Digitalmars-d-learn
On Monday, 20 August 2018 at 11:38:39 UTC, Paul Backus wrote: Create an overload of foo that takes two arguments and combines them into a `Data` struct internally: void foo(int a, string text) { Data data = {a, text}; foo(data); } Hmm, not very good solution. In C++ you can not to

Re: Deduce type of struct in function arguments

2018-08-20 Thread Paul Backus via Digitalmars-d-learn
On Monday, 20 August 2018 at 09:23:27 UTC, Andrey wrote: Hello, I have a function and a struct: void foo(ref Data data) { ... } struct Data { int a; string text; } How to pass struct into function without naming its type? This doesn't work: foo({1234, "Hello!"}); Create an

Re: ushort + ushort = int?

2018-08-20 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, August 20, 2018 4:29:56 AM MDT Andrey via Digitalmars-d-learn wrote: > On Monday, 20 August 2018 at 09:56:13 UTC, Jonathan M Davis wrote: > > It's a combination of keeping the C semantics (in general, C > > code is valid D code with the same semantics, or it won't > > compile) and the

Re: ushort + ushort = int?

2018-08-20 Thread Andrey via Digitalmars-d-learn
On Monday, 20 August 2018 at 09:56:13 UTC, Jonathan M Davis wrote: It's a combination of keeping the C semantics (in general, C code is valid D code with the same semantics, or it won't compile) and the fact that D requires casts for narrowing conversions. When you add two shorts in C/C++, it

Re: ushort + ushort = int?

2018-08-20 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, August 20, 2018 3:19:04 AM MDT Andrey via Digitalmars-d-learn wrote: > On Monday, 20 August 2018 at 08:49:00 UTC, rikki cattermole wrote: > > Yes. On x86 int's will be faster just an FYI so it does make > > sense to use them for computation. > > Inconveniently always use casts. Why in

Re: ushort + ushort = int?

2018-08-20 Thread rikki cattermole via Digitalmars-d-learn
On 20/08/2018 9:19 PM, Andrey wrote: On Monday, 20 August 2018 at 08:49:00 UTC, rikki cattermole wrote: Yes. On x86 int's will be faster just an FYI so it does make sense to use them for computation. Inconveniently always use casts. Why in D one decided to do in such way? C.

Deduce type of struct in function arguments

2018-08-20 Thread Andrey via Digitalmars-d-learn
Hello, I have a function and a struct: void foo(ref Data data) { ... } struct Data { int a; string text; } How to pass struct into function without naming its type? This doesn't work: foo({1234, "Hello!"});

Re: ushort + ushort = int?

2018-08-20 Thread Andrey via Digitalmars-d-learn
On Monday, 20 August 2018 at 08:49:00 UTC, rikki cattermole wrote: Yes. On x86 int's will be faster just an FYI so it does make sense to use them for computation. Inconveniently always use casts. Why in D one decided to do in such way?

Re: ushort + ushort = int?

2018-08-20 Thread rikki cattermole via Digitalmars-d-learn
On 20/08/2018 8:48 PM, Andrey wrote: On Monday, 20 August 2018 at 08:42:20 UTC, rikki cattermole wrote: It's called integer promotion and it originates from C. And yes C++ does have such support in some variant (I really don't feel like comparing the two). And I should do? Always use "cast"

Re: ushort + ushort = int?

2018-08-20 Thread Andrey via Digitalmars-d-learn
On Monday, 20 August 2018 at 08:42:20 UTC, rikki cattermole wrote: It's called integer promotion and it originates from C. And yes C++ does have such support in some variant (I really don't feel like comparing the two). And I should do? Always use "cast" operator when I operate not with

Re: ushort + ushort = int?

2018-08-20 Thread rikki cattermole via Digitalmars-d-learn
On 20/08/2018 8:34 PM, Andrey wrote: Hello, Here is a code that you can execute using online compiler https://run.dlang.io/: import std.stdio; void main() {    ushort first = 5;    ushort second = 1000;    ushort result = first + second;    writeln(result); } I hae this error:

ushort + ushort = int?

2018-08-20 Thread Andrey via Digitalmars-d-learn
Hello, Here is a code that you can execute using online compiler https://run.dlang.io/: import std.stdio; void main() { ushort first = 5; ushort second = 1000; ushort result = first + second; writeln(result); } I hae this error: onlineapp.d(7): Error: cannot implicitly convert