Re: How to invert bool false/true in alias compose?

2019-12-06 Thread Marcone via Digitalmars-d-learn
On Saturday, 7 December 2019 at 04:05:23 UTC, mipri wrote: On Saturday, 7 December 2019 at 04:00:53 UTC, Marcone wrote: import std; alias cmd = compose!(to!bool, wait, spawnShell, to!string); void main(){ writeln(cmd("where notepad.exe")); } Result: C:\Windows\System32\notepad.exe

Re: How to invert bool false/true in alias compose?

2019-12-06 Thread mipri via Digitalmars-d-learn
On Saturday, 7 December 2019 at 04:00:53 UTC, Marcone wrote: import std; alias cmd = compose!(to!bool, wait, spawnShell, to!string); void main(){ writeln(cmd("where notepad.exe")); } Result: C:\Windows\System32\notepad.exe C:\Windows\notepad.exe false The result show "false"

Re: How to invert bool false/true in alias compose?

2019-12-06 Thread Timon Gehr via Digitalmars-d-learn
On 07.12.19 05:00, Marcone wrote: import std; alias cmd = compose!(to!bool, wait, spawnShell, to!string); void main(){ writeln(cmd("where notepad.exe")); } Result: C:\Windows\System32\notepad.exe C:\Windows\notepad.exe false The result show "false" because good spawnshell command

How to invert bool false/true in alias compose?

2019-12-06 Thread Marcone via Digitalmars-d-learn
import std; alias cmd = compose!(to!bool, wait, spawnShell, to!string); void main(){ writeln(cmd("where notepad.exe")); } Result: C:\Windows\System32\notepad.exe C:\Windows\notepad.exe false The result show "false" because good spawnshell command return 0 and 0 to bool is false.

Re: Thin UTF8 string wrapper

2019-12-06 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, December 6, 2019 9:48:21 AM MST Joseph Rushton Wakeling via Digitalmars-d-learn wrote: > Hello folks, > > I have a use-case that involves wanting to create a thin struct > wrapper of underlying string data (the idea is to have a type > that guarantees that the string has certain

Re: Unexpectedly nice case of auto return type

2019-12-06 Thread mipri via Digitalmars-d-learn
On Friday, 6 December 2019 at 23:25:30 UTC, Johannes Loher wrote: On Tuesday, 3 December 2019 at 10:06:22 UTC, Mike Parker wrote: On Tuesday, 3 December 2019 at 10:03:22 UTC, Basile B. wrote: That's interesting details of D developement. Since you reply to the first message I think you have

Re: Unexpectedly nice case of auto return type

2019-12-06 Thread Johannes Loher via Digitalmars-d-learn
On Tuesday, 3 December 2019 at 10:06:22 UTC, Mike Parker wrote: On Tuesday, 3 December 2019 at 10:03:22 UTC, Basile B. wrote: That's interesting details of D developement. Since you reply to the first message I think you have not followed but in the last reply I told that maybe we should be

Re: How to create a custom max() function without the ambiguity error.

2019-12-06 Thread Mike Parker via Digitalmars-d-learn
On Friday, 6 December 2019 at 21:02:53 UTC, realhet wrote: Here's my latest attempt on EXTENDING std.algorithm.max's functionality with a max operation on a custom type. The type is the GLSL vec2 type which does the max operation component-wise. The D std implementation uses the < operator,

Re: How to create a custom max() function without the ambiguity error.

2019-12-06 Thread realhet via Digitalmars-d-learn
On Friday, 6 December 2019 at 14:55:18 UTC, Ferhat Kurtulmuş wrote: On Friday, 6 December 2019 at 13:25:24 UTC, realhet wrote: On Friday, 6 December 2019 at 13:04:57 UTC, Ferhat Kurtulmuş wrote: [...] Thx for answering! [...] In d you can also use scoped imports:

Re: Unexpectedly nice case of auto return type

2019-12-06 Thread Basile B. via Digitalmars-d-learn
On Wednesday, 4 December 2019 at 12:54:34 UTC, Basile B. wrote: On Wednesday, 4 December 2019 at 03:17:27 UTC, Adam D. Ruppe wrote: On Wednesday, 4 December 2019 at 01:28:00 UTC, H. S. Teoh wrote: typeof(return) is one of the lesser known cool things about D that make it so cool. Somebody

Re: Thin UTF8 string wrapper

2019-12-06 Thread Jonathan Marler via Digitalmars-d-learn
On Friday, 6 December 2019 at 16:48:21 UTC, Joseph Rushton Wakeling wrote: Hello folks, I have a use-case that involves wanting to create a thin struct wrapper of underlying string data (the idea is to have a type that guarantees that the string has certain desirable properties). The

Thin UTF8 string wrapper

2019-12-06 Thread Joseph Rushton Wakeling via Digitalmars-d-learn
Hello folks, I have a use-case that involves wanting to create a thin struct wrapper of underlying string data (the idea is to have a type that guarantees that the string has certain desirable properties). The string is required to be valid UTF-8. The question is what the most useful API

Re: How to create a custom max() function without the ambiguity error.

2019-12-06 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Friday, 6 December 2019 at 13:25:24 UTC, realhet wrote: On Friday, 6 December 2019 at 13:04:57 UTC, Ferhat Kurtulmuş wrote: [...] Thx for answering! [...] In d you can also use scoped imports: https://dlang.org/spec/module.html#scoped_imports

Re: opCmp with and without const

2019-12-06 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, December 6, 2019 12:03:45 AM MST berni44 via Digitalmars-d-learn wrote: > In std.typecons, in Tuple there are two opCmp functions, that are > almost identical; they only differ by one being const and the > other not: > > int opCmp(R)(R rhs) > if

Re: How to create a custom max() function without the ambiguity error.

2019-12-06 Thread Andrea Fontana via Digitalmars-d-learn
On Friday, 6 December 2019 at 12:34:17 UTC, realhet wrote: Hi, I'm trying to use a popular function name "max", and extend it for my special types: For example: module utils; MyType max(in MyType a, in MyType a){...} //static function struct V3f{ V3f max(in V2f b){...} //member function

Re: How to create a custom max() function without the ambiguity error.

2019-12-06 Thread realhet via Digitalmars-d-learn
On Friday, 6 December 2019 at 13:04:57 UTC, Ferhat Kurtulmuş wrote: On Friday, 6 December 2019 at 12:34:17 UTC, realhet wrote: Hi, I'm trying to use a popular function name "max", and extend it for my special types: For example: module utils; MyType max(in MyType a, in MyType a){...}

Re: How to create a custom max() function without the ambiguity error.

2019-12-06 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Friday, 6 December 2019 at 12:34:17 UTC, realhet wrote: Hi, I'm trying to use a popular function name "max", and extend it for my special types: For example: module utils; MyType max(in MyType a, in MyType a){...} //static function struct V3f{ V3f max(in V2f b){...} //member function

How to create a custom max() function without the ambiguity error.

2019-12-06 Thread realhet via Digitalmars-d-learn
Hi, I'm trying to use a popular function name "max", and extend it for my special types: For example: module utils; MyType max(in MyType a, in MyType a){...} //static function struct V3f{ V3f max(in V2f b){...} //member function } module gl3n; vec3 max(in vec3 a, in vec3 a) //another

Re: Intersection of two sets

2019-12-06 Thread Jan Hönig via Digitalmars-d-learn
On Wednesday, 4 December 2019 at 08:01:59 UTC, Per Nordlöw wrote: On Tuesday, 3 December 2019 at 13:43:26 UTC, Jan Hönig wrote: pseudocode: alias set = bool[] set foo = ... set bar = ... set result; One simple optimization is to set* smallest; set* largest; if (foo.length < bar.length) {

Re: opCmp with and without const

2019-12-06 Thread Basile B. via Digitalmars-d-learn
On Friday, 6 December 2019 at 07:03:45 UTC, berni44 wrote: In std.typecons, in Tuple there are two opCmp functions, that are almost identical; they only differ by one being const and the other not: int opCmp(R)(R rhs) if (areCompatibleTuples!(typeof(this), R, "<")) {