On Friday, 26 November 2021 at 00:41:34 UTC, Elronnd wrote:
you are right. thanks
static if (...) {
} else static if (...) {
} else {
static assert(0);
}
On Thursday, 25 November 2021 at 22:00:15 UTC, Alexey wrote:
I would want an static 'switch here',
I mean something like
```D
static switch (v.mode)
{
default:
static assert(false, "v.mode" is invalid)
case "gs_w_d":
// etc...
}
```
}
}
}
```
currently it works kind of ok. but what it's missing is check on
what none of [static if]s have worked. Ideally, I would want an
static 'switch here', so I could make `static assert(false)` in
it. and/or I'd like some sort of [compile time variable] to
change it if [static if]s have worked and check such [compile
time variable] later.
On Saturday, 25 June 2016 at 12:35:39 UTC, Lodovico Giaretta
wrote:
On Saturday, 25 June 2016 at 12:30:22 UTC, Lodovico Giaretta
wrote:
If you want this to work, you need your lambdas to take the
casted value as a parameter:
Thanks.
On Saturday, 25 June 2016 at 12:30:22 UTC, Lodovico Giaretta
wrote:
If you want this to work, you need your lambdas to take the
casted value as a parameter:
void test(T)(T value) {
int i;
string s;
match!(value,
int, (val) => i = val,
string, (val) => s = val
On Saturday, 25 June 2016 at 10:39:09 UTC, John wrote:
Thanks for the help, both. This appeared to work, until I
realised the lambda isn't static:
void match(T, cases...)() {
static if (cases.length == 1) cases[0]();
else static if (cases.length > 2) {
static if (is(typeof(cases
On Saturday, 25 June 2016 at 09:12:12 UTC, Lodovico Giaretta
wrote:
On Saturday, 25 June 2016 at 09:07:19 UTC, Lodovico Giaretta
wrote:
Instead of passing functions to match!, pass pairs of
arguments, like this:
match!(T,
int, writeln("Matched int"),
is(T : SomeObject), w
On Saturday, 25 June 2016 at 09:07:19 UTC, Lodovico Giaretta
wrote:
Instead of passing functions to match!, pass pairs of
arguments, like this:
match!(T,
int, writeln("Matched int"),
is(T : SomeObject), writeln("Derives from SomeObject");
);
Now, in the implementation
also, there is a subtle bug in matcher. sorry. ;-)
On Saturday, 25 June 2016 at 08:46:05 UTC, John wrote:
Anyone able to improve on it?
q&d hack:
template tyma(T, Cases...) {
import std.traits;
template GetFunc(size_t idx) {
static if (idx >= Cases.length) {
static assert(0, "no delegate for match");
} else static if (isCalla
On Saturday, 25 June 2016 at 08:46:05 UTC, John wrote:
Writing a long series of "static if ... else" statements can be
tedious and I'm prone to leaving out the crucial "static" after
"else", so I was wondered if it was possible to write a
template that would resemble the switch statement, but f
Writing a long series of "static if ... else" statements can be
tedious and I'm prone to leaving out the crucial "static" after
"else", so I was wondered if it was possible to write a template
that would resemble the switch statement, but for types.
Closest I came up to was this:
void match
On Tuesday, 12 June 2012 at 08:35:44 UTC, Dmitry Olshansky wrote:
It doesn't. It's easy to check anyway.
Not for me :) I just saw that it worked, and wondered if it
worked statically.
Thanks!
cal:
Does a switch statement acting on a template parameter act just
like a chain of static if-else's? That is, does it just
generate the code for the matching case?
See:
http://d.puremagic.com/issues/show_bug.cgi?id=6921
Bye,
bearophile
On 12.06.2012 10:13, cal wrote:
Does a switch statement acting on a template parameter act just like a
chain of static if-else's? That is, does it just generate the code for
the matching case?
enum E { A, B, C }
class Blah(E param) {
void foo() {
switch(param) {
case(E.A) : blah;
case(E.B) : ..
Does a switch statement acting on a template parameter act just
like a chain of static if-else's? That is, does it just generate
the code for the matching case?
enum E { A, B, C }
class Blah(E param) {
void foo() {
switch(param) {
case(E.A) : blah;
case(E.B) :
def
17 matches
Mail list logo