Code:
```d
import std.stdio;
struct Field {
void opAssign(int a) {
writefln("Field.opAssign(%s)", a);
}
}
struct Register {
Field clock(int a) {
writefln("Register.clock(%s)", a);
return Field();
}
}
void main() {
Register register;
register.cloc
06.07.2021 13:06, Jack Applegame пишет:
Code:
```d
import std.stdio;
struct Field {
void opAssign(int a) {
writefln("Field.opAssign(%s)", a);
}
}
struct Register {
Field clock(int a) {
writefln("Register.clock(%s)", a);
return Field();
}
}
void m
On Tuesday, 6 July 2021 at 10:06:11 UTC, Jack Applegame wrote:
How to disable `register.clock = 10;` but allow
`register.clock(1) = 10;`?
I want to get a compilation error on `register.clock = 10;`
We're [still awaiting formal assessment on
dip1038](https://forum.dlang.org/thread/sojvxakgruzf
On Tuesday, 6 July 2021 at 10:24:45 UTC, drug wrote:
Something like using different types for arguments in
`Register.clock` and `Field.opAssign`?
I've been thinking about it. Unfortunately, this is not always
convenient.
On Tuesday, 6 July 2021 at 10:25:28 UTC, Dennis wrote:
We're [still awaiting formal assessment on
dip1038](https://forum.dlang.org/thread/sojvxakgruzfvbigz...@forum.dlang.org), but if that gets in, you can mark `clock` or `Field` `@nodicard`. Otherwise I don't know of a way.
Yes, it would help.
On Monday, 5 July 2021 at 19:48:13 UTC, jfondren wrote:
On Monday, 5 July 2021 at 19:34:14 UTC, BoQsc wrote:
But I really don't like how it looks less readable and makes
less sense on first look.
`if (([letter].findAmong(alphabet)).length)`
I'd like to use some method on the `letter` instead
On Tuesday, 6 July 2021 at 11:35:14 UTC, BoQsc wrote:
I tried out .canFind method, and to test it I removed the
letter 'o' from the Alphabet.
Weirdly enough .canFind method still found 'o' letter among the
Alphabet.
https://run.dlang.io/is/2Fvenf
Looks like it has something to do with the a
On Tuesday, 6 July 2021 at 10:06:11 UTC, Jack Applegame wrote:
How to disable `register.clock = 10;`
You don't. The language always allows `a = b;` to be rewritten as
`a(b);`.
Best you can do is use different types for the two arguments.
Maybe clock could take a struct Clock { int x; } or s
On Tuesday, 6 July 2021 at 12:33:20 UTC, Adam D Ruppe wrote:
The language always allows `a = b;` to be rewritten as `a(b);`.
And that's sad. It should happen for properties only.
On Tuesday, 6 July 2021 at 13:27:43 UTC, Jack Applegame wrote:
And that's sad. It should happen for properties only.
Totally disagree. This is one of my favorite D features.
I recently found __traits(compiles, ...) can be used in template
constraints.
(I first used `is(mixin("T.init"~op~"T2.init"))` but this cause
problems related to nanF)
However I'm wondering if there is an easier way to do what I'm
currently doing, especially since using typeof inside the resul
On Tuesday, 6 July 2021 at 14:12:48 UTC, Rekel wrote:
I recently found __traits(compiles, ...) can be used in
template constraints.
(I first used `is(mixin("T.init"~op~"T2.init"))` but this cause
problems related to nanF)
However I'm wondering if there is an easier way to do what I'm
currentl
On Tuesday, 6 July 2021 at 14:27:35 UTC, Paul Backus wrote:
Instead of having the template evaluate to a `bool`, have it
evaluate to the type of the result:
```d
alias ResultType(Lhs, string op, Rhs) =
typeof(((Lhs lhs, Rhs rhs) => mixin("lhs", op, "rhs"))());
static assert(is(ResultType!(
On 7/6/21 9:27 AM, Jack Applegame wrote:
On Tuesday, 6 July 2021 at 12:33:20 UTC, Adam D Ruppe wrote:
The language always allows `a = b;` to be rewritten as `a(b);`.
And that's sad. It should happen for properties only.
Yes, I lament that there is no way to control how people call your
fun
On Tuesday, 6 July 2021 at 14:43:26 UTC, Rekel wrote:
Is there any reason the function call in the alias is
acceptable? I would imagine the () part would actually require
2 parameters.
You're right, it does; that was a mistake on my part. It should
work with `Lhs.init` and `Rhs.init` as argum
On Tuesday, 6 July 2021 at 15:00:24 UTC, Paul Backus wrote:
On Tuesday, 6 July 2021 at 14:43:26 UTC, Rekel wrote:
Is there any reason the function call in the alias is
acceptable? I would imagine the () part would actually require
2 parameters.
You're right, it does; that was a mistake on my
On Tuesday, 6 July 2021 at 10:06:11 UTC, Jack Applegame wrote:
How to disable `register.clock = 10;` but allow
`register.clock(1) = 10;`?
I want to get a compilation error on `register.clock = 10;`
Some options:
1. return a temporary struct with an opIndex
```d
import std.stdio;
struct Fiel
On Tuesday, 6 July 2021 at 15:24:37 UTC, jfondren wrote:
3. https://run.dlang.io/is/AJM6Vg - hybrid where ClockAssign
has an unsafe pointer that the compiler complains about :/
4.
```d
import std.stdio;
struct Field {
void opAssign(int a) {
writefln("Field.opAssign(%s)", a);
}
You can also do:
```d
import std;
void main()
{
// https://dlang.org/phobos/std_ascii.html#.lowercase
"Book.".filter!(c => lowercase.canFind(c))
.each!(c => writeln(c, " found"));
// Output:
// o found
// o found
// k found
}
```
On Tuesday, 6 July 2021 at 15:48:35 UTC, rassoc wrote:
You can also do:
```d
import std;
void main()
{
// https://dlang.org/phobos/std_ascii.html#.lowercase
"Book.".filter!(c => lowercase.canFind(c))
.each!(c => writeln(c, " found"));
// Output:
// o found
//
So I have this situation where I need to split a string, then where the
splits are, insert a string to go between the elements making a new
range, all without allocating (hopefully).
Looking around phobos I found inside the documentation of
[roundRobin](https://dlang.org/phobos/std_range.html#
On Wednesday, 7 July 2021 at 01:44:20 UTC, Steven Schveighoffer
wrote:
This is pretty minimal, but does what I want it to do. Is it
ready for inclusion in Phobos? Not by a longshot! A truly
generic interleave would properly forward everything else that
the range supports (like `length`, `save`,
On Tuesday, 6 July 2021 at 10:06:11 UTC, Jack Applegame wrote:
Here's another way using ``` std.typecons ```
```d
import std.stdio;
import std.typecons;
alias input = Typedef!int; //new code
struct Field {
void opAssign(int a) {
writefln("Field.opAssign(%s)", a);
}
}
struct R
23 matches
Mail list logo