Re: Can Enums be integral types?
On Sunday, 17 April 2022 at 18:25:32 UTC, Bastiaan Veelo wrote: The reason is in [17.1.5](https://dlang.org/spec/enum.html): “EnumBaseType types cannot be implicitly cast to an enum type.” Thy. That's the anchor in the specs preventing Enums to be integral types.
Can Enums be integral types?
In the specs(17) about enums the word "integral" has no match. But because the default basetype is `int`, which is an integral type, enums might be integral types whenever their basetype is an integral type. On the other hand the specs(7.6.5.3) about types say | A bool value can be implicitly converted to any integral type, | with false becoming 0 and true becoming 1. This seems senseless, when the enum has no names defined for one of these values.
Re: How to define property type to Array!struct?
On Tuesday, 14 December 2021 at 08:28:01 UTC, WebFreak001 wrote: [...] Alternatively, remove the template `()` from your `struct Header` What is the semantic sense of a template having no parameters? Although the documentation declares such a template to be syntactically correct, not a single example suggests a meaning.
Re: Rules for Symbol Name Lookup seem contradictory
On Monday, 22 June 2020 at 02:16:52 UTC, user1234 wrote: [...] Maybe that the spec is a bit vague as it doesn't mention that [...] A vague place in a spec is usually called "Dark Corner" and the functionality then marked as "Implementation defined". But this mark is missing here. And restricting the validity of the contradictory seeming sentences to overloadables only, puts all others into an unregulated state. Therefore the stated problem stays unexplained.
Rules for Symbol Name Lookup seem contradictory
https://dlang.org/spec/module.html#name_lookup contains under 4.3.4 only two sentences. While the first sentence explains, that the search ends "as soon as a matching symbol is found", the second sentence implies that the search may continue until it is sure, that no other symbol "with the same name" can be found in the current phase. This means, that under sentence one the following code is free of errors and under sentence two the following code has to be rejected, because an ambiguity exists. De facto the code compiles without error under dmd v2.092.1: class C{ } class D{ C c; this(){ auto c= new C; } } void main(){ auto d= new D; }
Re: Is it possible to store different subclasses in one array?
On Monday, 13 April 2020 at 05:54:52 UTC, evilrat wrote: if (auto weapon = cast(Weapon) gi) weapon.Attack(); Does the parlor (currently illegal in Dlang) if (Weapon w := gi) w.Attack(); look nicer or even (currently legal): if (Weapon w ._= gi) w.Attack();
Re: Docs 6.9.4: Implicit Conversion to bool
On Monday, 9 March 2020 at 16:44:55 UTC, Steven Schveighoffer wrote: You're not the first person to ask. Accepted.
Docs 6.9.4: Implicit Conversion to bool
Having a function `f' overloaded for argument types `bool' and `ulong', the specs guarantee, that for `f( 1uL)' the boolean overload of `f' is called. What is this good for?
Re: changing the output of `std.stdio.write'
On Thursday, 3 January 2019 at 18:11:43 UTC, Paul Backus wrote: [...] functions [...] default to `%s`. thx. I should have rtfm instead of looking for an example. -manfred
changing the output of `std.stdio.write'
According to this tutorial https://wiki.dlang.org/Defining_custom_print_format_specifiers it seems easy to change the format of the output for `std.stdio.writef'. But why is there no example for changing the output when there are no format specifiers? -manfred
Re: Distinguish recursive Templates
Timon Gehr wrote: template getDepth(T){ static if(is(T==Set!S,S)) enum getDepth=1+getDepth!S; else enum getDepth=0; } Thx. Seems that I have to relearn a lot. -manfred
Re: Distinguish recursive Templates
Matt Kline wrote: isn't making any use of the template argument T Correct. I do not know how to use `T' to determine the recursion depth of the template---and I want no further parameter. -manfred
Distinguish recursive Templates
How can one determine the recursion depth for templated types? Example code: import std.stdio; class Set(T){ override string toString(){ return Set; } } void main(){ auto s0= new Set!uint; writeln( s0); // writes Set auto s1= new Set!(Set!uint); writeln( s1); // should write SetSet }
Re: Dual conditions in D and Python
Dennis Ritchie wrote: if (4 = 5 = 6): print (OK) - I would rather write: if( isSorted![4,5,6]) -manfred
Assertion failure without line
core.exception.AssertError@stackext.d(0): Assertion failure how to handle this? -manfred
Re: Assertion failure without line
Adam D. Ruppe wrote: assert inside a mixed in string. None praesent: private import star, stack; class StackExtended( T): Stack!T{ Star!T stacked; this(){ stacked= new Star!T;} auto opOpAssign( string op, T)( T node){ stacked+= node; return super+= node; } auto opUnary( string op)(){ stacked -= super.max; return super--; } bool opBinaryRight( string op, Tquote)( Tquote elem) if( is( Tquote:T) ( in==op )) { return elem in stacked; } } -manfred
Re: Assertion failure without line
Adam D. Ruppe wrote: My first gut idea Turns out: it is the usage of a variable - not newed, and - of a type declared in the file. -manfred
Re: UFCS
Jonathan M Davis wrote: UFCS is only ever used with the . syntax The docs say so. Thx. -manfred
Deprecation
Deprecation: super is not an lvalue 1) How to know when this will indeed be deprecated? 2) What does it mean, when `super++' is signalled as depracation, but `super+=' is not signalled? -manfred
Re: Deprecation
Steven Schveighoffer wrote: That seems like a bug. https://issues.dlang.org/show_bug.cgi?id=14589 -manfred
UFCS
The following gives: Error: 'a += b' is not a scalar, it is a C although UFCS should engage. -manfred class C{} int main(){ void opOpAssign( string op)( C a, C b){ } C a, b; a+= b; }
Error Compiling DMD
std.process.ProcessException@std\process.d(560): Failed to spawn new process This is the error-message from the D-script from http://wiki.dlang.org/Building_DMD -manfred
Re: Bug or feature?
Jack Applegame wrote: test(10); // error One can import the declaration by using an alias: class A { void test(int) {} } class B : A { alias test= super.test; void test() { super.test(1); // compiles test(10); // compiles } } -manfred
Re: Lambda functions in D
Dennis Ritchie wrote: auto fact = function (int x) = x * { if (x) fact(x - 1); }; int fact (int x) { return x * ( x1 ? fact(x - 1): 1); }; -manfred
Re: opEquals optimized away?
On Tuesday, 5 May 2015 at 05:26:17 UTC, anonymous wrote: because `c is c` Thanks. One can see this documented in http://dlang.org/operatoroverloading.html#equals But 1: how can one override this behavior 2: what is the design reason for this Especially: how can one implement side effects on invoking `==' or `!='? -manfred
opEquals optimized away?
class C{ override bool opEquals( Object o){ return true; } } unittest{ auto c= new C; assert( c == c); } `rdmd --main -unittest -cov' shows, that opEquals is not executed. Why? -manfred