presence of function template prevents diagnostic

2020-11-14 Thread kdevel via Digitalmars-d-learn
~~~A.d module A; import std.stdio; void bar (int s) { __PRETTY_FUNCTION__.writeln; } ~~~ ~~~foo.d import std.stdio; import A; alias bar = A.bar; version (X) { void bar (T) (T t) { __PRETTY_FUNCTION__.writeln; } } void bar (int s) { __PRETTY_FUNCTION__.writeln; } void main () { bar (1);

Value based overload resolution?

2020-11-09 Thread kdevel via Digitalmars-d-learn
Today I came across this: ~~~id.d import std.stdio : writeln; T foo (T) (T s) { __PRETTY_FUNCTION__.writeln; return s; } short foo (short s) { __PRETTY_FUNCTION__.writeln; return s; } T id (T) (T t) { return t; } int main () { foo (1); foo (1L); foo (id (1)); foo

Re: Variable assignment in “if” condition in Dlang

2020-05-03 Thread kdevel via Digitalmars-d-learn
On Sunday, 3 May 2020 at 15:13:48 UTC, H. S. Teoh wrote: On Sun, May 03, 2020 at 02:53:21PM +, Baby Beaker via Digitalmars-d-learn wrote: How can I assign a variable in “if” condition in Dlang? if (auto obj = someFunction(...)) { // use obj here, it's guaranteed to

Re: Checked!({short, ushort, byte, ubyte}, Throw): compilation fails

2020-04-18 Thread kdevel via Digitalmars-d-learn
On Saturday, 18 April 2020 at 08:39:52 UTC, tsbockman wrote: [...] You also get a deprecation message, about an integral promotion not being performed. I believe the result is correct and the warning can be ignored. So the warning is a bug? The deprecation message is a consequence of a

Re: Checked!({short, ushort, byte, ubyte}, Throw): compilation fails

2020-04-17 Thread kdevel via Digitalmars-d-learn
On Friday, 17 April 2020 at 12:59:20 UTC, Simen Kjærås wrote: [Deleted text makes sense] And assigning from an int to a short may discard data, so it's statically disallowed by Checked. This is a deliberate design choice, and the appropriate way to handle it is with a cast: unittest {

Re: Checked!({short, ushort, byte, ubyte}, Throw): compilation fails

2020-04-17 Thread kdevel via Digitalmars-d-learn
On Friday, 17 April 2020 at 04:29:06 UTC, Meta wrote: Unlike C/C++, char is not a numeric type in D; It's a UTF-8 code point: Thanks, it's a code /unit/. main reads now: void main () { bar!ubyte; bar!byte; bar!ushort; bar!short; bar!uint; bar!int; bar!ulong; bar!long;

Checked!({short, ushort, byte, char}, Throw): compilation fails

2020-04-16 Thread kdevel via Digitalmars-d-learn
Sorry for this lengthy post: ```x.d void foo (T) () { import std.experimental.checkedint; alias CT = Checked!(T, Throw); CT a = CT.min; CT x; --x; CT b = x; CT c = a / b; } void bar (T) () { import std.stdio; try foo!T (); catch (Exception e) writefln

Re: __tls_get_addr symbol

2020-04-13 Thread kdevel via Digitalmars-d-learn
On Monday, 13 April 2020 at 14:42:25 UTC, Marius Cristian Baciu wrote: [...] I am having some trouble locating a symbol referenced in rt/sections_elf_shared.d (__tls_get_addr). Could someone tell me where does the runtime expect to retrieve its implementation from $ gdb test (gdb) b

Re: DMD 2.090.1: SIGILL, Illegal instruction on (ahem) intel Pentium III

2020-03-11 Thread kdevel via Digitalmars-d-learn
On Thursday, 27 February 2020 at 19:24:39 UTC, Johan wrote: LDC will work fine if told what processor you have: https://d.godbolt.org/z/5hrzgm -m32 -mcpu=pentium3 (-mcpu=native should also work). When I "cross compile" on an AMD 64 Bit machine for pentium3 [AMD 64 bit] $ ldc2 -m32

Re: std.datetime & timzone specifier: 2018-11-06T16:52:03+01:00

2020-03-08 Thread kdevel via Digitalmars-d-learn
On Sunday, 8 March 2020 at 17:28:33 UTC, Robert M. Münch wrote: [...] But I have to do: DateTime dt = DateTime.fromISOExtString(split("2018-11-06T16:52:03+01:00", regex("\\+"))[0]); You don't need a regex. split (..., '+') seems to suffice here. IMO such a string should be feedable

Re: Improving dot product for standard multidimensional D arrays

2020-03-03 Thread kdevel via Digitalmars-d-learn
On Sunday, 1 March 2020 at 20:58:42 UTC, p.shkadzko wrote: pragma(inline) static int toIdx(T)(Matrix!T m, in int i, in int j) { return m.cols * i + j; } This is row-major order [1]. BTW: Why don't you make toIdx a member of Matrix? It saves one parameter. You may also define opIndex as

Re: DMD 2.090.1: SIGILL, Illegal instruction on (ahem) intel Pentium III

2020-02-27 Thread kdevel via Digitalmars-d-learn
On Thursday, 27 February 2020 at 18:07:40 UTC, Rainer Schuetze wrote: "If this is an issue, please file a bug report." Issue 20621 - Since DMD 2.087.0: 32 Bit Linux now uses XMM registers: SIGILL, Illegal instruction on intel Pentium III

Re: DMD 2.090.1: SIGILL, Illegal instruction on (ahem) intel Pentium III

2020-02-27 Thread kdevel via Digitalmars-d-learn
On Thursday, 27 February 2020 at 07:44:57 UTC, Seb wrote: On Thursday, 27 February 2020 at 00:36:49 UTC, kdevel wrote: [...] Program received signal SIGILL, Illegal instruction. [...] Does this exception relate to [1] and shall I file a bug or do I have to decommission my PIII? [...]

DMD 2.090.1: SIGILL, Illegal instruction on (ahem) intel Pentium III

2020-02-26 Thread kdevel via Digitalmars-d-learn
```test.d void main () { int [] v = new int [10]; } ``` $ [...]linux/bin32/dmd test $ gdb test [...] (gdb) r [...] Program received signal SIGILL, Illegal instruction. 0x0809ad14 in _D2gc4impl12conservativeQw3Gcx10smallAllocMFNbkKkkxC8TypeInfoZPv () [...] (gdb) disass [...] 0x0809ad14

Re: Why GNU coreutils/dd is creating a dummy file more efficiently than D's For loop?

2019-05-23 Thread kdevel via Digitalmars-d-learn
On Thursday, 23 May 2019 at 09:44:15 UTC, Cym13 wrote: [...] Note in particular the blocksize argument. I set it to 1M but by default it's 512 bytes. If you use strace with the command above you'll see a series of write() calls, each writting 1M of null bytes to testfile. That's the main

Re: Framework design, initialization and framework usage

2019-05-20 Thread kdevel via Digitalmars-d-learn
On Sunday, 19 May 2019 at 13:07:36 UTC, Robert M. Münch wrote: On 2019-05-12 17:33:16 +, kdevel said: [...] What about correctness? Correctness of what? Open a new document in MS Word or any other word processor and then press and hold the "L" key until the cursor hits the right

Re: Is using floating point type for money/currency a good idea?

2019-05-20 Thread kdevel via Digitalmars-d-learn
On Monday, 20 May 2019 at 11:47:25 UTC, Josh wrote: On Monday, 20 May 2019 at 11:10:32 UTC, Boqsc wrote: https://dlang.org/spec/float.html I'm frozen in learning basics of D lang since I want to create a simple game and I really would like a clean and simple code, however to me floating

mixing (else) static if inadvertently with else if

2019-05-18 Thread kdevel via Digitalmars-d-learn
Today I stumbled over this error: elsestaticif.d ``` import std.stdio; void insert () () { // some code } void insert (T, Args ...) (T x, Args args) { static if (T.stringof == "int") {{ `int`.writeln; }} else if (T.stringof == "bool") {{ // ← "static" is missing here

Re: 1 - 17 ms, 553 ╬╝s, and 1 hnsec

2019-05-17 Thread kdevel via Digitalmars-d-learn
On Friday, 17 May 2019 at 20:30:56 UTC, Bastiaan Veelo wrote: On Friday, 17 May 2019 at 18:36:00 UTC, ag0aep6g wrote: I'd suggest "17 ms, and 553.1µs" for a better default (1 hns is 0.1 µs, right?). No weird "hnsecs", no false precision, still all the data that is there. I was going to

Re: Framework design, initialization and framework usage

2019-05-17 Thread kdevel via Digitalmars-d-learn
On Monday, 13 May 2019 at 09:25:05 UTC, ztop wrote: [...] The old site is archived in wayback https://web.archive.org/web/20180103191733/http://antigrain.com/ Thanks. That is the page I have been looking for:

Re: 1 - 17 ms, 553 ╬╝s, and 1 hnsec

2019-05-17 Thread kdevel via Digitalmars-d-learn
On Thursday, 16 May 2019 at 20:31:23 UTC, Vladimir Panteleev wrote: On Thursday, 16 May 2019 at 20:17:37 UTC, Steven Schveighoffer [...] hnsecs is more confusing than nanoseconds. People know what a nanosecond is, a hecto-nano-second is not as familiar a term. Agreed, which is why

Re: Framework design, initialization and framework usage

2019-05-12 Thread kdevel via Digitalmars-d-learn
On Wednesday, 8 May 2019 at 09:15:41 UTC, Ron Tarrant wrote: On Wednesday, 8 May 2019 at 06:30:56 UTC, Robert M. Münch wrote: Our focus is executable size (I'm an old school guy) and speed. What about correctness? [...] For some simple real-time grid example see:

Re: dmd -unittest -main -run: undefined reference to `_D1c12__ModuleInfoZ'

2019-05-01 Thread kdevel via Digitalmars-d-learn
On Wednesday, 1 May 2019 at 22:35:12 UTC, ag0aep6g wrote: [...] Or use -i so that DMD compiles the imported module automatically: dmd -unittest -main -i -run package.d Now I have: a/main.d a/b/package.d a/b/c/package.d b/package.d and c/package.d as before. a/main.d is ``` import b;

Re: dmd -unittest -main -run: undefined reference to `_D1c12__ModuleInfoZ'

2019-05-01 Thread kdevel via Digitalmars-d-learn
On Wednesday, 1 May 2019 at 22:35:12 UTC, ag0aep6g wrote: On 02.05.19 00:25, kdevel wrote: dmd -unittest -main -run package.d c/package.d That doesn't compile c/package.d. Everything after `-run package.d` is interpreted as an argument to the compiled program. Thanks for the information.

dmd -unittest -main -run: undefined reference to `_D1c12__ModuleInfoZ'

2019-05-01 Thread kdevel via Digitalmars-d-learn
In the current working directory b/ I have package.d ``` module b; import c; void bar (string s) { mkdir (s); } ``` c/package.d ``` module c; package import std.file; ``` $ dmd -unittest -main package.d c/package.d produces the binary "package" as expected, but $ dmd -unittest

Re: Packages / imports & references between modules

2019-04-28 Thread kdevel via Digitalmars-d-learn
On Sunday, 28 April 2019 at 14:24:08 UTC, Robert M. Münch wrote: On 2019-04-28 11:44:03 +, Mike Parker said: They're different symbols because they're in different modules. The module and package name is part of the symbol name. Ok, that's what I assumed too. Just import A.b in A.a.

Cyclic dependency between module A and B

2019-04-10 Thread kdevel via Digitalmars-d-learn
Recently (before refactoring) my application complained right after invocation: object.Error@src/rt/minfo.d(371): Cyclic dependency between module Filebrowser and App Filebrowser* -> App* -> Filebrowser* Is it possible to detect this dependency before the program is started?

Re: Iterate/sort associative array by value?

2019-04-08 Thread kdevel via Digitalmars-d-learn
On Sunday, 7 April 2019 at 17:16:12 UTC, Seb wrote: --- ["a": 1].byPair.array.sort!((a, b) => a.value < a.value).release.each!writeln; --- What's the purpose of .release? The documentation in https://dlang.org/phobos/std_range.html#.SortedRange.release is rather monosyllabic.

Re: § 28.3 Pointers and the Garbage Collector

2019-04-07 Thread kdevel via Digitalmars-d-learn
On Sunday, 7 April 2019 at 10:17:53 UTC, AltFunction1 wrote: On Sunday, 7 April 2019 at 10:05:26 UTC, kdevel wrote: In § 28.3 Pointers and the Garbage Collector [1] we read Do not add or subtract an offset to a pointer such that the result points outside of the bounds of the garbage

§ 28.3 Pointers and the Garbage Collector

2019-04-07 Thread kdevel via Digitalmars-d-learn
In § 28.3 Pointers and the Garbage Collector [1] we read Do not add or subtract an offset to a pointer such that the result points outside of the bounds of the garbage collected object originally allocated. char* p = new char[10]; char* q = p + 6; // ok q = p + 11;

Re: How to decode UTF-8 text?

2019-03-27 Thread kdevel via Digitalmars-d-learn
On Wednesday, 27 March 2019 at 13:39:07 UTC, Andrey wrote: I have got some text with UTF-8. For example this part: Παράλληλη αναζήτηση This looks like a UTF-8 sequence which has been UTF-8 encoded. How to decode it to get this result? Παράλληλη αναζήτηση Undo the second

latin9 characters in filesystem and command line; std.encoding [ISO-8859-15]

2019-03-17 Thread kdevel via Digitalmars-d-learn
This program: ```ls.d import std.stdio; import std.file; void main (string [] args) { auto entries = dirEntries (args[1], SpanMode.shallow, false); foreach (e; entries) writeln (e.name); } ``` lists the contents of a directory even if args[1] and the filesystem contain names

Re: Casting int[] to ubyte[]: element wise cast or slice cast

2019-02-16 Thread kdevel via Digitalmars-d-learn
On Friday, 15 February 2019 at 18:11:11 UTC, Dennis wrote: Your should report our observation: https://issues.dlang.org ``` void main () { enum A = [0x10203040, 0x50607080]; // shall enum behave like immutable? auto B = [0x10203040, 0x50607080]; assert (A == B); auto p = cast

Re: dirEntries within static foreach: memory.d(827): Error: fakePureErrno cannot be interpreted at compile time, because it has no available source code

2019-02-10 Thread kdevel via Digitalmars-d-learn
On Monday, 11 February 2019 at 00:54:27 UTC, Seb wrote: On Monday, 11 February 2019 at 00:19:02 UTC, kdevel wrote: [...] You can't read or list files at compile-time. dmd can read files at compile time using the import function [1] What are you trying to do? Incorporate HTML template

dirEntries within static foreach: memory.d(827): Error: fakePureErrno cannot be interpreted at compile time, because it has no available source code

2019-02-10 Thread kdevel via Digitalmars-d-learn
I am trying to get this code compiled: ```TemplateStore.d module TemplateStore; import std.path; import std.conv; import std.file; immutable string[string] template_map; static this () { static foreach (f; dirEntries (``, `*.html`, SpanMode.shallow)) { pragma (msg, `reading template

Re: Singleton in Action?

2019-02-05 Thread kdevel via Digitalmars-d-learn
On Monday, 4 February 2019 at 10:17:53 UTC, bauss wrote: On Saturday, 2 February 2019 at 16:56:45 UTC, Ron Tarrant wrote: [...] Here's the singleton code I've been playing with: [...] static bool instantiated_; // Thread global __gshared DSingleton instance_;

API Documentation

2019-01-20 Thread kdevel via Digitalmars-d-learn
Online but not on a local installation I frequently land on pages under https://dlang.org/library/ (API Documentation). What is the reason for this duplicate docs? The API documentation looks much cleaner and better structured. https://dlang.org/library/std/range.html vs.

Re: Is there a nice syntax to achieve optional named parameters?

2019-01-17 Thread kdevel via Digitalmars-d-learn
On Thursday, 17 January 2019 at 01:43:42 UTC, SrMordred wrote: On Tuesday, 15 January 2019 at 11:14:54 UTC, John Burton wrote: [...] auto window = Window(); window.title = "My Window"; window.width = 1000; window.create(); [...] Is there a better way that's not ugly? [...] //usage:

GCC 4.9.4 + GDC-patch: internal compiler error in libphobos/src/std/math.d:8040:47

2019-01-05 Thread kdevel via Digitalmars-d-learn
I applied the head commit ce249d880969111384d17f744687e427c843f1d4 Merge: 8a6b7a4 0e517e4 Author: Eugene Wissner Date: Tue Apr 10 15:37:32 2018 +0200 Merge pull request #647 from belka-ew/gdc-49up Merge branch gdc-5 into gdc-4.9 of branch gdc-4.9 on top of

D man pages

2019-01-05 Thread kdevel via Digitalmars-d-learn
For years I missed the man pages of the C++ standard library and now found out that some Linux distros provide them as extra package. The man pages are not generated by a default during a GCC bootstrap install but need an explicit make doc-install-man in the corresponding doc directory of

Re: reimplementing an interface in a derived class

2019-01-04 Thread kdevel via Digitalmars-d-learn
On Friday, 4 January 2019 at 20:21:56 UTC, Steven Schveighoffer wrote: missing in the source. But why is d a null reference in the first place? Because when you dynamically cast one object or interface to another object or interface, and that result is not possible (if you remove ",D" from

Re: reimplementing an interface in a derived class

2019-01-04 Thread kdevel via Digitalmars-d-learn
On Friday, 4 January 2019 at 11:27:59 UTC, Alex wrote: On Friday, 4 January 2019 at 09:58:59 UTC, bauss wrote: [...] As for the OP, I think here the usefulness of ", D" should be visible: [...] class B : A, D { override int foo() { return 2; } } [...] D d = cast(D) b;

reimplementing an interface in a derived class

2019-01-03 Thread kdevel via Digitalmars-d-learn
https://dlang.org/spec/interface.html #11 has this code example: ``` interface D { int foo(); } class A : D { int foo() { return 1; } } class B : A, D { override int foo() { return 2; } } ... B b = new B(); b.foo();// returns 2 D d = cast(D) b; d.foo();//

Re: What does auto std.stdio.File.ByChunkImpl byChunk (ulong chunkSize ); mean?

2018-08-03 Thread kdevel via Digitalmars-d-learn
On Friday, 3 August 2018 at 17:27:07 UTC, Adam D. Ruppe wrote: But remember, this is documentation that just happens to look like code, so it is intended to be legible by people rather than the compiler. I could not find any elucidation of the meaning of auto when used as a return type

Re: What does auto std.stdio.File.ByChunkImpl byChunk (ulong chunkSize ); mean?

2018-08-03 Thread kdevel via Digitalmars-d-learn
On Friday, 3 August 2018 at 17:06:16 UTC, Adam D. Ruppe wrote: On Friday, 3 August 2018 at 16:58:26 UTC, kdevel wrote: What does auto std.stdio.File.ByChunkImpl byChunk ( ulong chunkSize ); on https://dlang.org/library/std/stdio/file.by_chunk.html mean? It looks like ddox trying

What does auto std.stdio.File.ByChunkImpl byChunk (ulong chunkSize ); mean?

2018-08-03 Thread kdevel via Digitalmars-d-learn
What does auto std.stdio.File.ByChunkImpl byChunk ( ulong chunkSize ); on https://dlang.org/library/std/stdio/file.by_chunk.html mean? Is that a (forward) declaration of a function named byChunk taking a single ulong argument name chunkSize. But what does that function return?

Re: Better diagnostics for null classes dereferencing

2018-07-10 Thread kdevel via Digitalmars-d-learn
On Tuesday, 10 July 2018 at 22:31:54 UTC, Adam D. Ruppe wrote: Turn off rtTrapExceptions though the command line switch PR is STILL NOT MERGED https://github.com/dlang/druntime/pull/2035 extern (C) __gshared bool rt_trapExceptions; static this () { rt_trapExceptions =

Re: Better diagnostics for null classes dereferencing

2018-07-10 Thread kdevel via Digitalmars-d-learn
On Tuesday, 10 July 2018 at 21:09:23 UTC, Steven Schveighoffer wrote: [...] As far as the OS is concerned, a[2 .. $] is within the process memory limit. Of course, that's an out of bounds access, so the compiler or the bounds check *should* complain. It complains at runtime > ./dumpme2

Re: Better diagnostics for null classes dereferencing

2018-07-10 Thread kdevel via Digitalmars-d-learn
On Tuesday, 10 July 2018 at 20:10:54 UTC, Adam D. Ruppe wrote: On Tuesday, 10 July 2018 at 19:01:22 UTC, Per Nordlöw wrote: [...] Run the program in a debugger, or run `ulimit -c unlimited` to enable core dumps [...] Works for null ptr deref but how do I enforce core dumps in this code:

Re: guard clause style static if

2018-07-10 Thread kdevel via Digitalmars-d-learn
On Saturday, 7 July 2018 at 11:56:40 UTC, rikki cattermole wrote: void bar (T ...) (T args) if (T.length == 0) { return; [...] } void bar (T ...) (T args) if (T.length > 0) { writeln (args [0]); return bar (args [1 .. $]); } This is a version without a

Re: guard clause style static if

2018-07-10 Thread kdevel via Digitalmars-d-learn
On Saturday, 7 July 2018 at 13:12:59 UTC, Alex wrote: The site you cited for the guard clause above (c2.com) works at runtime. ? The intention is to shorten the paths inside a function, I think. Therefore, a static "guard clause" is a contradiction, if I understand it correctly. The term

Re: guard clause style static if

2018-07-10 Thread kdevel via Digitalmars-d-learn
On Saturday, 7 July 2018 at 13:03:32 UTC, rikki cattermole wrote: void func() { return; func2(); } Which is clearly an error. Hence why you need to add else block. There is no error in this generated code because func2 is unreachable. That there is a state/stage during

Re: guard clause style static if

2018-07-10 Thread kdevel via Digitalmars-d-learn
On Tuesday, 10 July 2018 at 00:11:27 UTC, Steven Schveighoffer wrote: On 7/7/18 7:28 AM, kdevel wrote: It appears not to be possible to use static if in "guard clause style" as in    void bar (T ...) (T args)    {   static if (args.length == 0) return;   writeln (args

Re: guard clause style static if

2018-07-07 Thread kdevel via Digitalmars-d-learn
On Saturday, 7 July 2018 at 12:46:08 UTC, rikki cattermole wrote: On 08/07/2018 12:40 AM, kdevel wrote: Interesting alternative That was not an alternative. That is what your code was doing. What my original code was supposed to do. But it did not compile. Error: array index [0] is

Re: guard clause style static if

2018-07-07 Thread kdevel via Digitalmars-d-learn
On Saturday, 7 July 2018 at 11:56:40 UTC, rikki cattermole wrote: On 07/07/2018 11:44 PM, kdevel wrote: On Saturday, 7 July 2018 at 11:29:35 UTC, rikki cattermole wrote:    static if (args.length == 0)   return; else {    writeln (args [0]);    return bar (args [1 ..

Re: guard clause style static if

2018-07-07 Thread kdevel via Digitalmars-d-learn
On Saturday, 7 July 2018 at 11:29:35 UTC, rikki cattermole wrote:   static if (args.length == 0) return; else {   writeln (args [0]);   return bar (args [1 .. $]); } That's not guard clause style [1][2]. [1]

guard clause style static if

2018-07-07 Thread kdevel via Digitalmars-d-learn
It appears not to be possible to use static if in "guard clause style" as in void bar (T ...) (T args) { static if (args.length == 0) return; writeln (args [0]); return bar (args [1 .. $]); } Is this intended?

Re: errnoEnforce: which imports?

2018-06-29 Thread kdevel via Digitalmars-d-learn
On Friday, 29 June 2018 at 09:22:03 UTC, Jonathan M Davis wrote: Shall I create a bug report? Yes. Aside from someone trying it out and complaining about it, it probably wouldn't be noticed or fixed, since it's one of the few tests that doesn't work as a ddoc-ed unit test. Issue 19041 -

Re: errnoEnforce: which imports?

2018-06-29 Thread kdevel via Digitalmars-d-learn
On Friday, 29 June 2018 at 02:28:04 UTC, Jonathan M Davis wrote: [...] really, that example needs to be completely redone. Shall I create a bug report?

errnoEnforce: which imports?

2018-06-28 Thread kdevel via Digitalmars-d-learn
In https://dlang.org/phobos/std_exception.html#errnoEnforce this example is shown: --- auto f = errnoEnforce(fopen("data.txt")); auto line = readln(f); enforce(line.length); // expect a non-empty line --- I added import std.stdio; import std.exception; and get an error message which

Re: Nullable!T with T of class type

2018-06-28 Thread kdevel via Digitalmars-d-learn
On Thursday, 28 June 2018 at 19:22:38 UTC, Jonathan M Davis wrote: Nullable makes sense in generic code, because the code isn't written specifically for them, but something like Nullable!MyClass in non-generic code is pointless IMHO, because a class reference is already nullable. It is

Re: Nullable!T with T of class type

2018-06-28 Thread kdevel via Digitalmars-d-learn
On Tuesday, 26 June 2018 at 21:54:49 UTC, Jonathan M Davis wrote: [H]onestly, I don't understand why folks keep trying to put nullable types in Nullable in non-generic code. How do you signify that a struct member of class type is optional?

Re: Nullable!T with T of class type

2018-06-26 Thread kdevel via Digitalmars-d-learn
On Tuesday, 26 June 2018 at 14:32:59 UTC, Nathan S. wrote: On Monday, 25 June 2018 at 19:40:30 UTC, kdevel wrote: Is it possible to "lower" the Nullable operations if T is a class type such that there is only one level of nullification? Yes: https://run.dlang.io/is/hPxbyf template

Re: Nullable!T with T of class type

2018-06-26 Thread kdevel via Digitalmars-d-learn
On Monday, 25 June 2018 at 22:58:41 UTC, Jonathan M Davis wrote: On Monday, June 25, 2018 19:40:30 kdevel via Digitalmars-d-learn wrote: R r; if (r.s is null) throw new Exception ("some error message"); [...] Why can't this programming error be detected at co

Nullable!T with T of class type

2018-06-25 Thread kdevel via Digitalmars-d-learn
Just stumbled over the following design: class S {...} class R { : Nullable!S s; : } s was checked in code like R r; : if (r.s is null) throw new Exception ("some error message"); At runtime the following was caught: fatal error: caught

Re: Mysql query result access by field name

2018-05-21 Thread kdevel via Digitalmars-d-learn
On Monday, 21 May 2018 at 14:17:23 UTC, Steven Schveighoffer wrote:    Data f;    allrows[0].toStruct (f); I haven't checked this. This only works if your struct has exactly the same layout as the fields. So if, for instance, your rows are selected "title", "name", "surname", but your

Re: Mysql query result access by field name

2018-05-21 Thread kdevel via Digitalmars-d-learn
On Sunday, 20 May 2018 at 16:08:03 UTC, ipkwena wrote: How does one access the columns fields in a Mysql query results by the column name. [...] Data f; f.name = to!string(allrows[0][0]); f.surname = to!string(allrows[0][1]); f.title = to!string(allrows[0][2]); I am using the mysql-native

Re: fft and isPowerOf2?

2018-05-17 Thread kdevel via Digitalmars-d-learn
On Thursday, 17 May 2018 at 12:34:25 UTC, Andre Pany wrote: this applications throws an error in std.numeric (Line 2826). => assert(isPowerOf2(range.length)); Isn't it possible to give an arbitrary length of data to fft like in numpy? There is a mathematical background which is well

Re: Declare and Define Before Use? [rant]

2018-04-04 Thread kdevel via Digitalmars-d-learn
On Wednesday, 4 April 2018 at 19:19:30 UTC, Ali wrote: On Wednesday, 4 April 2018 at 18:57:27 UTC, kdevel wrote: [...] I think the rules should have been the same everywhere and if there was an exception to be made, it could be made for the main function since the main function is special

Declare and Define Before Use? [rant]

2018-04-04 Thread kdevel via Digitalmars-d-learn
Why are people writing import std.stdio; void main () { S s; s.foo; } struct S { void foo () { writeln ("a"); } } but not void main () { S s; s.foo; } struct S { void foo () { writeln

Re: how to correctly populate an array of dynamic closures?

2018-03-29 Thread kdevel via Digitalmars-d-learn
On Thursday, 29 March 2018 at 20:05:35 UTC, ag0aep6g wrote: On Thursday, 29 March 2018 at 19:02:51 UTC, kdevel wrote: On Thursday, 29 March 2018 at 15:16:07 UTC, Ivan Kazmenko wrote: [...] int delegate () [] guns; foreach (i; 0..2) guns ~= () => i; foreach (i; 0..2)

Re: how to correctly populate an array of dynamic closures?

2018-03-29 Thread kdevel via Digitalmars-d-learn
On Thursday, 29 March 2018 at 15:16:07 UTC, Ivan Kazmenko wrote: import std.stdio; void main () { int delegate () [] funs; funs ~= () => 0; funs ~= () => 1; foreach (i; 0..2) writeln (funs[i] ()); // 0 and 1 as expected int delegate () [] guns;

compilers w/ different language features: version block

2018-02-24 Thread kdevel via Digitalmars-d-learn
A code fragment using static foreach https://forum.dlang.org/thread/jiefcxwqbjzqnmtaz...@forum.dlang.org#post-beruryblsptnunsowjph:40forum.dlang.org does not compile with the current GDC (GCC 4.9.4 and 5.5.0). I tried to encapsulate this code into a version block but GDC still checks the

Re: short s, t; t = -s: no (longer) works: Deprecation: integral promotion not done for -s, use

2018-02-24 Thread kdevel via Digitalmars-d-learn
On Saturday, 24 February 2018 at 22:30:09 UTC, Steven Schveighoffer wrote: The prime example is this: byte b = -128; int x = -b; What would you expect x to be? a) 128 b) -128 Neither nor. I would prefer the codomain of "-" be the range of byte and hence an exception thrown in that

Re: short s, t; t = -s: no (longer) works: Deprecation: integral promotion not done for -s, use

2018-02-24 Thread kdevel via Digitalmars-d-learn
On Saturday, 24 February 2018 at 20:17:12 UTC, Steven Schveighoffer wrote: On 2/24/18 3:07 PM, kdevel wrote: I don't get the point of the deprecation message: --- intprom.d import std.stdio; void main () {    short s, t;    t = -s; } --- https://dlang.org/changelog/2.078.0.html#fix16997

short s, t; t = -s: no (longer) works: Deprecation: integral promotion not done for -s, use

2018-02-24 Thread kdevel via Digitalmars-d-learn
I don't get the point of the deprecation message: --- intprom.d import std.stdio; void main () { short s, t; t = -s; } --- $ dmd intprom.d intprom.d(6): Deprecation: integral promotion not done for -s, use '-transition=intpromote' switch or -cast(int)(s) What shall I do in order to

array/Array: "hard" bounds checking

2018-02-21 Thread kdevel via Digitalmars-d-learn
Is there a D equivalent of the C++ at method? I would like to reformulate repro2.d --- void main () { import std.stdio; import std.container; import std.range; auto z = Array!char(); z.reserve(0xC000_); z.capacity.writeln; z.length.writeln; for (uint u = 0; u <

Re: enforce (i > 0) for i = int.min does not throw

2018-01-30 Thread kdevel via Digitalmars-d-learn
On Sunday, 28 January 2018 at 19:17:49 UTC, Steven Schveighoffer wrote: This is insane. i > 0 is used in so many places. The only saving grace appears to be that int.min is just so uncommonly seen in the wild. And another one that it does not happen when compiled with optimization (-O) and

Re: std_exception.html#enforce: example does not compile

2018-01-27 Thread kdevel via Digitalmars-d-learn
On Saturday, 27 January 2018 at 20:33:46 UTC, Jonathan M Davis wrote: Shall I file a bug report? Yes. https://issues.dlang.org/show_bug.cgi?id=18319

Re: D generates large assembly for simple function

2018-01-27 Thread kdevel via Digitalmars-d-learn
On Saturday, 27 January 2018 at 19:43:50 UTC, Stefan Koch wrote: On Saturday, 27 January 2018 at 19:42:01 UTC, Matt wrote: Godbolt link: https://godbolt.org/g/t5S976 The actual code is : imul edi, edi mov eax, edi ret Could you please paste the source code? I mean in say 5 years when

Re: std_exception.html#enforce: example does not compile

2018-01-27 Thread kdevel via Digitalmars-d-learn
On Saturday, 27 January 2018 at 18:34:35 UTC, Jonathan M Davis wrote: The example still does not compile. That has nothing to do with enforce. std.stdio.readln does not take a FILE*. In general, you shouldn't mix core.stdc.stdio and std.stdio. The code is from the official documentation:

Re: assert and enforce both compiled out with -release

2018-01-27 Thread kdevel via Digitalmars-d-learn
On Saturday, 27 January 2018 at 18:00:32 UTC, rjframe wrote: I think I see what you mean; you interpret "use asserts, because enforce will be compiled out" to imply that asserts wouldn't be compiled out, correct? Is there any other meaningful interpretation? Since, in reality, both would be

Re: std_exception.html#enforce: example does not compile

2018-01-27 Thread kdevel via Digitalmars-d-learn
On Saturday, 27 January 2018 at 16:10:29 UTC, Jonathan M Davis wrote: On Saturday, January 27, 2018 13:29:00 kdevel via Digitalmars-d-learn wrote: What's wrong here? And why is the "selective import" of enforce necessary? Because you named your module enforce. As such, by default,

Re: assert and enforce both compiled out with -release

2018-01-27 Thread kdevel via Digitalmars-d-learn
On Saturday, 27 January 2018 at 16:19:30 UTC, Jonathan M Davis wrote: On Saturday, January 27, 2018 14:59:50 kdevel via Digitalmars-d-learn wrote: >>> https://github.com/dlang/phobos/blob/master/std/exception.d >> >> "Use $(D assert) in contracts." is s

Re: enforce (i > 0) for i = int.min does not throw

2018-01-27 Thread kdevel via Digitalmars-d-learn
On Saturday, 27 January 2018 at 14:49:52 UTC, Ali Çehreli wrote: But enforce is a red herring there. This prints true with 2.078 as well: import std.stdio; void main () { int i = int.min; writeln(i > 0);// prints 'true' with 2.078 } test.d --- import std.stdio; void main () {

Re: assert and enforce both compiled out with -release

2018-01-27 Thread kdevel via Digitalmars-d-learn
On Saturday, 27 January 2018 at 14:51:23 UTC, Ali Çehreli wrote: On 01/27/2018 06:36 AM, kdevel wrote: On Saturday, 27 January 2018 at 14:31:13 UTC, Ali Çehreli wrote: > But assert is also ignored in release mode: The documentation is not clear. "they will be compiled out" means "contracts

Re: assert and enforce both compiled out with -release

2018-01-27 Thread kdevel via Digitalmars-d-learn
On Saturday, 27 January 2018 at 14:31:13 UTC, Ali Çehreli wrote: > But assert is also ignored in release mode: The documentation is not clear. "they will be compiled out" means "contracts are compiled out". So, an enforce() would disappear if it's inside such a block, which should not be what

enforce (i > 0) for i = int.min does not throw

2018-01-27 Thread kdevel via Digitalmars-d-learn
I would expect this code enforce3.d --- import std.exception; void main () { int i = int.min; enforce (i > 0); } --- to throw an "Enforcement failed" exception, but it doesn't: $ dmd enforce3.d $ ./enforce3 [nothing]

assert and enforce both compiled out with -release

2018-01-27 Thread kdevel via Digitalmars-d-learn
https://dlang.org/phobos/std_exception.html#enforce states: | Also, do not use enforce inside of contracts (i.e. inside of in and out blocks | and invariants), because they will be compiled out when compiling with -release. | Use assert in contracts. But assert is also ignored in release

std_exception.html#enforce: example does not compile

2018-01-27 Thread kdevel via Digitalmars-d-learn
https://dlang.org/phobos/std_exception.html#enforce and also https://dlang.org/library/std/exception/enforce.html present this example: --- auto f = enforce(fopen("data.txt")); auto line = readln(f); enforce(line.length, "Expected a non-empty line."); --- fopen, readln and enforce need

variable template question

2018-01-14 Thread kdevel via Digitalmars-d-learn
vartmpl.d ``` import std.stdio : writeln; import decimal : decimal32; template F(T) { immutable T c = 3; } void foo (T) () { immutable T t = 1; } void main () { // immutable decimal32 i = 1; // Error: none of the overloads of '__ctor' are callable using a immutable object //

Re: function template specialization question D vs. C++

2018-01-14 Thread kdevel via Digitalmars-d-learn
On Sunday, 14 January 2018 at 02:24:52 UTC, Adam D. Ruppe wrote: On Sunday, 14 January 2018 at 02:14:50 UTC, Jonathan M Davis wrote: If you're using template constraints rather than template specializations, then you can't have any unconstrained templates. Not true: see the tip of the week

Re: function template specialization question D vs. C++

2018-01-13 Thread kdevel via Digitalmars-d-learn
On Sunday, 14 January 2018 at 00:30:37 UTC, Nicholas Wilson wrote: The usual way to do what you are trying to do is with template constraints. void foo(T)() if (is(T== float)) { ...} Thanks. That works but looks a bit ugly. Am I right that I have to leave out the primary (unconstrained)

function template specialization question D vs. C++

2018-01-13 Thread kdevel via Digitalmars-d-learn
fusp.d ``` import std.stdio; import std.typecons; void foo (T) () { writeln ("(1) foo T = ", T.stringof); } void foo (T : float) () { writeln ("(2) foo T = ", T.stringof); } // void foo (T : double) () // { //writeln ("(2) foo T = ", T.stringof); // } void main () { foo!float;

Re: compile-time checked format strings

2018-01-13 Thread kdevel via Digitalmars-d-learn
On Saturday, 13 January 2018 at 19:40:09 UTC, Adam D. Ruppe wrote: For ints, it catches all that, but for float, it just bails out of the check as soon as it actually *succeeds* - because that kills CTFE. Confirmed. Thanks! args.d ``` import std.stdio; void main () { // writefln!"%2.2d

compile-time checked format strings

2018-01-13 Thread kdevel via Digitalmars-d-learn
occasion: http://forum.dlang.org/thread/mutegviphsjwqzqfo...@forum.dlang.org?page=3#post-mailman.2136.1515709204.9493.digitalmars-d-announce:40puremagic.com dmd checks the types but does not count the arguments. ctcfs.d ``` import std.stdio; import std.math; void unit (T) () { auto pi = 4

Re: Floating Point Literals: float (f) and real (L) suffix issue

2018-01-12 Thread kdevel via Digitalmars-d-learn
On Friday, 12 January 2018 at 12:45:59 UTC, kdevel wrote: suffix.d ``` void main () { real r = 1.L; float f = 1.f; } ``` $ dmd suffix.d suffix.d(3): Error: no property 'L' for type 'int' suffix.d(4): Error: no property 'f' for type 'int' According to the grammar in

Floating Point Literals: float (f) and real (L) suffix issue

2018-01-12 Thread kdevel via Digitalmars-d-learn
suffix.d ``` void main () { real r = 1.L; float f = 1.f; } ``` $ dmd suffix.d suffix.d(3): Error: no property 'L' for type 'int' suffix.d(4): Error: no property 'f' for type 'int' According to the grammar in dmd2/html/d/spec/lex.html both are valid FloatLiterals. Any comments?

Re: union/toString: crash/segfault: What's happening here?

2018-01-12 Thread kdevel via Digitalmars-d-learn
Thanks for the quick answer! On Friday, 12 January 2018 at 02:16:39 UTC, Adam D. Ruppe wrote: On Friday, 12 January 2018 at 00:54:03 UTC, kdevel wrote: $ dmd crash.d $ ./crash Nicholas Wilson is right that you can use = "" to work around it, but with strings, null is supposed to behave the

union/toString: crash/segfault: What's happening here?

2018-01-11 Thread kdevel via Digitalmars-d-learn
crash.d ``` import std.stdio; union U { float f; int i; string toString () { string s; return s; } } void main () { U u; writeln (u); } ``` $ dmd crash.d $ ./crash std.exception.ErrnoException@/.../dmd2/linux/bin64/../../src/phobos/std/stdio.d(2776): (Bad

  1   2   >