Re: Very confusing error message when calling a class method from an invariant

2021-03-09 Thread Meta via Digitalmars-d-learn
On Wednesday, 10 March 2021 at 04:57:19 UTC, Paul Backus wrote: On Wednesday, 10 March 2021 at 03:39:15 UTC, Meta wrote: class Human { static immutable MAX_AGE = 122; bool alive = true; int age = 0; //Error: mutable method onlineapp.Human.checkAge is not callable using a const

Re: Very confusing error message when calling a class method from an invariant

2021-03-09 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 10 March 2021 at 03:39:15 UTC, Meta wrote: class Human { static immutable MAX_AGE = 122; bool alive = true; int age = 0; //Error: mutable method onlineapp.Human.checkAge is not callable using a const object invariant(checkAge()); [...] What the hell does th

Very confusing error message when calling a class method from an invariant

2021-03-09 Thread Meta via Digitalmars-d-learn
class Human { static immutable MAX_AGE = 122; bool alive = true; int age = 0; //Error: mutable method onlineapp.Human.checkAge is not callable using a const object invariant(checkAge()); void growOlder() in(alive) out(; checkAge()) { age++; i

Re: Does is(f == function) work?

2021-03-09 Thread Andrey Zherikov via Digitalmars-d-learn
On Tuesday, 9 March 2021 at 18:53:06 UTC, Boris Carvajal wrote: On Tuesday, 9 March 2021 at 11:58:45 UTC, Andrey Zherikov wrote: On Tuesday, 9 March 2021 at 02:57:46 UTC, Adam D. Ruppe wrote: try is(typeof(f) == function) it is kinda weird but that's the trick Thanks! Should it work for in

Re: Using YMM registers causes an undefined label error

2021-03-09 Thread z via Digitalmars-d-learn
On Tuesday, 9 March 2021 at 20:23:48 UTC, z wrote: On Friday, 5 March 2021 at 12:57:43 UTC, z wrote: ... Then it seems the only way to get AVX-compatible inline assembly(ldc.llvmasm excluded) is to use an external assembler. For example : ... But i'm not really sure how to integrate that i

Re: Using YMM registers causes an undefined label error

2021-03-09 Thread z via Digitalmars-d-learn
On Friday, 5 March 2021 at 12:57:43 UTC, z wrote: ... Then it seems the only way to get AVX-compatible inline assembly(ldc.llvmasm excluded) is to use an external assembler. For example : import std.stdio; extern(C) void vxorps_d(ubyte[32]*); void main() { ubyte[32] a = 2;

Unary operators for Variants

2021-03-09 Thread Jeff via Digitalmars-d-learn
So, I can't seem to get unary operators to work with variants. For example: Variant x = 10; writeln(-x); // Error: x is not of arithmetic type, it is a VariantN!32LU Obviously binary operators like + work fine. Is there a reason opUnary wasn't implemented as well? Is there a work-around for

Re: Broken examples

2021-03-09 Thread Imperatorn via Digitalmars-d-learn
On Tuesday, 9 March 2021 at 15:44:39 UTC, MoonlightSentinel wrote: On Saturday, 6 March 2021 at 08:15:16 UTC, Imperatorn wrote: Are you sure? 🤔 I tried switching to dmd-beta, dmd-nightly, ldc and ldc-beta and none of them worked. Yes. All of those were stuck at 2.093 due to some issues with

Re: Does is(f == function) work?

2021-03-09 Thread Boris Carvajal via Digitalmars-d-learn
On Tuesday, 9 March 2021 at 11:58:45 UTC, Andrey Zherikov wrote: On Tuesday, 9 March 2021 at 02:57:46 UTC, Adam D. Ruppe wrote: try is(typeof(f) == function) it is kinda weird but that's the trick Thanks! Should it work for in this case as well? alias f = (){}; writeln(typeof(f).stringof);

Re: Does is(f == function) work?

2021-03-09 Thread Kyle Ingraham via Digitalmars-d-learn
On Tuesday, 9 March 2021 at 11:58:45 UTC, Andrey Zherikov wrote: On Tuesday, 9 March 2021 at 02:57:46 UTC, Adam D. Ruppe wrote: try is(typeof(f) == function) it is kinda weird but that's the trick Thanks! Should it work for in this case as well? alias f = (){}; writeln(typeof(f).stringof);

Re: Does is(f == function) work?

2021-03-09 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 9 March 2021 at 11:58:45 UTC, Andrey Zherikov wrote: Should it work for in this case as well? alias f = (){}; I actually don't know. The docs do say that function pointers work differently - they match `is(typeof(f) == return)` but it isn't clear if it would match == function.

Re: How to get number of parameters in lambda?

2021-03-09 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 9 March 2021 at 14:22:44 UTC, Andrey Zherikov wrote: In case of function template this is possible but the original question was about lambdas. There is no way that lambda can change number of parameters during instantiation, am I right? Yes, you're correct. The issue is that the c

Re: Broken examples

2021-03-09 Thread MoonlightSentinel via Digitalmars-d-learn
On Saturday, 6 March 2021 at 09:38:54 UTC, Ali Çehreli wrote: Are you getting the same errors with those dmd versions? My locally installed compiler is dmd 2.094.2, which seems to be too old for parse's new doCount template parameter. (I look inside /usr/include/dmd/phobos/std/conv.d on my Lin

Re: Broken examples

2021-03-09 Thread MoonlightSentinel via Digitalmars-d-learn
On Saturday, 6 March 2021 at 08:15:16 UTC, Imperatorn wrote: Are you sure? 🤔 I tried switching to dmd-beta, dmd-nightly, ldc and ldc-beta and none of them worked. Yes. All of those were stuck at 2.093 due to some issues with Travis. We've resolved those issues over the last few days and au

Re: How to get number of parameters in lambda?

2021-03-09 Thread Andrey Zherikov via Digitalmars-d-learn
On Tuesday, 9 March 2021 at 03:08:14 UTC, Paul Backus wrote: If you know the arguments you want to call the function with, the easiest way to check if you can do it is with __traits(compiles): static if (__traits(compiles, f(1))) f(1); else static if (__traits(compiles, f(1, 2))) f(2);

Re: Does is(f == function) work?

2021-03-09 Thread Andrey Zherikov via Digitalmars-d-learn
On Tuesday, 9 March 2021 at 02:57:46 UTC, Adam D. Ruppe wrote: try is(typeof(f) == function) it is kinda weird but that's the trick Thanks! Should it work for in this case as well? alias f = (){}; writeln(typeof(f).stringof);// prints "void function() pure nothrow @nogc @safe" wr