Re: Packing of Struct Fields

2020-10-17 Thread ag0aep6g via Digitalmars-d-learn
On 17.10.20 14:35, Per Nordlöw wrote: struct S {     int i;     bool b; } struct T {     S s; // reinterpreting this as an array can only access this first element anyway     char c; // so why can't this be aligned directly after `s` without any padding? } c does come directly after

Re: Packing of Struct Fields

2020-10-16 Thread ag0aep6g via Digitalmars-d-learn
On 16.10.20 22:32, Per Nordlöw wrote: Why is `T.sizeof` 12 instead of 8 when `U.sizeof` is 8 in the following example? struct S {     int i;     bool b; } struct T {     S s;     char c; } struct U {     int i;     bool b;     char c; } ? S.sizeof: 4 bytes for the int + 1 byte for

Re: Escape this in pure members

2020-09-23 Thread ag0aep6g via Digitalmars-d-learn
On 23.09.20 02:06, DlangUser38 wrote: The following analysis might be wrong but I think that `scope` as a **member** function attribute is not supposed to be used as that is not even documented. It's documented here: https://dlang.org/spec/memory-safe-d.html#scope-return-params Quote:

Re: Call C variadic function from D variadic function

2020-09-13 Thread ag0aep6g via Digitalmars-d-learn
```     /// Add a single line to an existing header     auto addLine(T...)(RecordType type, T kvargs)     if(kvargs.length > 0 && isSomeString!(T[0]))     {     static assert (kvargs.length %2 == 0);   // K-V pairs => even number of variadic args     string varargMagic(size_t

Re: How do I copy struct having immutable pointer member when enabled DIP1000?

2020-08-30 Thread ag0aep6g via Digitalmars-d-learn
On 31.08.20 06:24, outlandkarasu wrote: I thought that I cannot make non-scope `ref` parameters from `scope` array references. But I found It allowed currently. [...] enum Currency : string {     USD = "USD", EUR = "EUR", GBP = "GBP", JPY = "JPY", } struct Instrument {     Currency bid;   

Re: How do I copy struct having immutable pointer member when enabled DIP1000?

2020-08-30 Thread ag0aep6g via Digitalmars-d-learn
On 30.08.20 17:24, outlandkarasu wrote: enum Tag { tag = "tag" } struct A { Tag tag; } A createA() @safe {     scope a = A(Tag.tag);     // Error: scope variable a may not be returned     return a;     // NG     // return A(a);     // return A(a.tag); } [...] I

Re: in; scope; scope ref; DIP1000; documentation

2020-08-27 Thread ag0aep6g via Digitalmars-d-learn
On 27.08.20 20:49, James Blachly wrote: 1. The thread involves 'in' qualifier. Documentation (https://dlang.org/spec/function.html#param-storage) indicates that `in` is defined as `scope const` and should not be used as it is not implemented. **Is this [fact and recommendation] still true?**

Re: String mixin from within a template

2020-08-23 Thread ag0aep6g via Digitalmars-d-learn
On Sunday, 23 August 2020 at 20:54:22 UTC, data pulverizer wrote: compiled string 1: alias x0 = Remove(indicies[i] - i, Args); Error: found - when expecting ) Error: semicolon expected to close alias declaration Error: no identifier for declarator i Error: declaration expected, not , ...

Re: String mixin from within a template

2020-08-23 Thread ag0aep6g via Digitalmars-d-learn
On Sunday, 23 August 2020 at 19:42:47 UTC, data pulverizer wrote: `alias x` ~ i ~ ` = Remove(indexes[i] - i, x`~ (i - 1) ~ `);` [...] ```d Error: no identifier for declarator x ``` Indicating that the concatenation `~` is not working, and I only get the partial string when I print out

Re: Template constraint on alias template parameter.

2020-08-06 Thread ag0aep6g via Digitalmars-d-learn
On Thursday, 6 August 2020 at 16:01:35 UTC, jmh530 wrote: The code below compiles, but I want to put an additional constraint on the `test` function is only called with a Foo struct. I tried things like is(T == Foo) and is(T : Foo), but those don't work. However, something like is(T!int :

Re: dynamic array .length vs .reserve - what's the difference?

2020-07-31 Thread ag0aep6g via Digitalmars-d-learn
On 31.07.20 01:42, wjoe wrote: I could swear just a few weeks ago there was someone asking how to tell if an array was null or of length 0 and an answer was that it's the same and can't be distinguished so I assumed that assigning a slice of 0 length is the same as setting the array to null

Re: constructing labels for static foreach inside switch inside foreach

2020-07-08 Thread ag0aep6g via Digitalmars-d-learn
On 08.07.20 14:24, Steven Schveighoffer wrote: I solved it for now by extrapolating the inner code into a local template function. But this is definitely an awkward situation for static foreach. FWIW, you can write the extra function like this: static foreach (T; Types) () {

Re: [DIP1000] Something I don't quite understand regarding 'scope'

2020-06-29 Thread ag0aep6g via Digitalmars-d-learn
On 29.06.20 02:28, Stanislav Blinov wrote: void local(Args...)(Args args) { } void main() @safe {     import std.stdio;     scope int* p;     local(p);   // Ok     writeln(p); // Error: scope variable p assigned to non-scope parameter _param_0 calling std.stdio.writeln!(int*).writeln }

Re: isInputRange not satisfied even if all individual conditions are satisfied

2020-06-26 Thread ag0aep6g via Digitalmars-d-learn
On 26.06.20 15:35, ag0aep6g wrote: `isInputRange!R` fails because it has no knowledge of your free `empty` function. Without `empty`, `R` is obviously not a range. To be clear: It's the same with `front` and `popFront`. You can't implement any range primitives as free functions. It only

Re: isInputRange not satisfied even if all individual conditions are satisfied

2020-06-26 Thread ag0aep6g via Digitalmars-d-learn
On 26.06.20 15:09, Johannes Loher wrote: import std.meta : allSatisfy, staticMap; import std.traits : allSameType; import std.range : isInputRange, ElementType, empty; [...] @property bool empty(TypeArgs...)(auto ref scope SumType!(TypeArgs) r) if (allSatisfy!(isInputRange, TypeArgs)

Re: Metaprogramming with D

2020-06-09 Thread ag0aep6g via Digitalmars-d-learn
On 09.06.20 20:16, Ali Çehreli wrote: I am biased but I like my :) index of the book, where all such syntax items appear:   https://ddili.org/ders/d.en/ix.html Oh yeah. It's how I got the link. You might want to fix some of the URLs, though. Characters like '{' or '[' need to be

Re: Metaprogramming with D

2020-06-08 Thread ag0aep6g via Digitalmars-d-learn
On 08.06.20 16:45, ag0aep6g wrote: On 08.06.20 16:41, Jan Hönig wrote: On Sunday, 7 June 2020 at 00:45:37 UTC, Ali Çehreli wrote: [...]   writeln(q{   void foo() {   }     }); What is the name of this `q` thing? How do i find it? Are there any recent tutorials on it?

Re: Metaprogramming with D

2020-06-08 Thread ag0aep6g via Digitalmars-d-learn
On 08.06.20 16:41, Jan Hönig wrote: On Sunday, 7 June 2020 at 00:45:37 UTC, Ali Çehreli wrote: [...]   writeln(q{   void foo() {   }     }); What is the name of this `q` thing? How do i find it? Are there any recent tutorials on it? https://dlang.org/spec/lex.html#token_strings

Re: Mixin and imports

2020-06-08 Thread ag0aep6g via Digitalmars-d-learn
On 08.06.20 16:27, data pulverizer wrote: Out of curiosity what does the "." in front of `foo` mean? I've seen that in some D code on the compiler in GitHub and have no idea what it does. I tried Googling it to no avail. It doesn't have anything to do with UFCS does it?

Re: Use classes as keys in associative array

2020-06-06 Thread ag0aep6g via Digitalmars-d-learn
On Saturday, 6 June 2020 at 16:49:29 UTC, JN wrote: Is it possible to use different class instances as keys for associative array, but compare them by the contents? I tried to override opEquals but it doesn't seem to work. You also need toHash.

Re: Determining @trusted-status

2020-05-29 Thread ag0aep6g via Digitalmars-d-learn
On 29.05.20 08:28, JN wrote: Alternatively you could just use @trusted blocks. Unsafe blocks are a common practice in languages like C# or Rust when it comes to calling unsafe code. @safe isn't about 100% bulletproof safety. @safe is (should be) about not having memory related errors outside

Re: Determining @trusted-status

2020-05-29 Thread ag0aep6g via Digitalmars-d-learn
On 29.05.20 02:09, Clarice wrote: It seems that @safe will be de jure, whether by the current state of DIP1028 or otherwise. However, I'm unsure how to responsibly determine whether a FFI may be @trusted: the type signature and the body. Should I run, for example, a C library through valgrind

Re: How to get the pointer of "this" ?

2020-05-26 Thread ag0aep6g via Digitalmars-d-learn
On 26.05.20 15:43, Vinod K Chandran wrote: So far now, two solutions are very clear for this problem. 1. As per John Chapman's suggestion - use cast(DWORD_PTR)cast(void*)this). 2. Use another varibale to use as an lvalue. - Button dummyBtn = this; cast(DWORD_PTR) Among these two, i

Re: Variable "i" can not be read at compile time

2020-05-24 Thread ag0aep6g via Digitalmars-d-learn
On 24.05.20 19:13, data pulverizer wrote: Thank you very much. I though that if I used a `static foreach` loop D would attempt to run the calculation `bench()` at compile time rather than at run time but it doesn't which is good. So `static foreach` allows you to index at compile time and if

Re: Variable "i" can not be read at compile time

2020-05-24 Thread ag0aep6g via Digitalmars-d-learn
On 24.05.20 18:34, data pulverizer wrote: I'm getting the error: ``` Error: variable i cannot be read at compile time Error: template instance script.runKernelBenchmarks!(Tuple!(DotProduct!float, Gaussian!float, Polynomial!float, Exponential!float, Log!float, Cauchy!float, Power!float,

Re: Distinguish between a null array and an empty array

2020-05-24 Thread ag0aep6g via Digitalmars-d-learn
On 24.05.20 14:29, bauss wrote: Dang, that sucks there is no proper way and I would say that's a big flaw of D. Because what I need it for is for some data serialization but if the value is an empty array then it should be present and if it's null then it should not be present. Since null

Re: Distinguish between a null array and an empty array

2020-05-24 Thread ag0aep6g via Digitalmars-d-learn
On 24.05.20 14:12, bauss wrote: Is there a way to do that? Since the following are both true: int[] a = null; int[] b = []; assert(a is null); assert(!a.length); assert(b is null); assert(!b.length); What I would like is to tell that b is an empty array and a is a null array. No way.

Re: Why does indexing a string inside of a recursive call yield a different result?

2020-05-10 Thread ag0aep6g via Digitalmars-d-learn
On 10.05.20 12:02, Adnan wrote: ulong editDistance(const string a, const string b) {     if (a.length == 0)     return b.length;     if (b.length == 0)     return a.length;     const auto delt = a[$ - 1] == b[$ - 1] ? 0 : 1;     import std.algorithm : min;     return min(  

Re: CTFE and Static If Question

2020-05-07 Thread ag0aep6g via Digitalmars-d-learn
On 07.05.20 17:00, jmh530 wrote: Does foo!y0(rt) generate the same code as foo(rt, y0)? How is the code generated by foo(rt, x0) different from foo(rt,y0)? auto foo(bool rtct)(int rt) {     static if (rtct)     return rt + 1;     else     return rt; } auto foo(int rt, bool rtct) {

Re: Thread to watch keyboard during main's infinite loop

2020-05-06 Thread ag0aep6g via Digitalmars-d-learn
On 07.05.20 02:13, Daren Scot Wilson wrote: import std.stdio; import core.stdc.stdio;  // for getchar().  There's nothing similar in D std libs? import std.concurrency; import core.thread; // just for sleep() Instead of the comment you can write: import core.thread: sleep; bool

Re: Help, what is the code mean?

2020-04-28 Thread ag0aep6g via Digitalmars-d-learn
On Tuesday, 28 April 2020 at 20:48:57 UTC, Net wrote: () { ... } (); Is there a name of this kind of function in D? unnamed? anonymous? The spec uses "anonymous". Syntactically, `() { ... }` is a function literal. There is a section called "Anonymous Functions and Anonymous Delegates"

Re: Flatten a range of static arrays

2020-02-08 Thread ag0aep6g via Digitalmars-d-learn
On 08.02.20 07:27, ag0aep6g wrote: On 08.02.20 02:38, ag0aep6g wrote: Simplified, we're looking at this: struct Joiner { int[3] _items; int[] _current; } void main() @safe { Joiner j; j._current = j._items[]; } [...] In the first reduction, `j` might be `scope`,

Re: Flatten a range of static arrays

2020-02-08 Thread ag0aep6g via Digitalmars-d-learn
On 08.02.20 15:57, Steven Schveighoffer wrote: This kind of stuff is so difficult to reason about and develop as a library that people will just end up removing dip1000 from their compilation. I 100% agree that DIP 1000 is hard to reason about. It's pretty limited by design, and the

Re: Flatten a range of static arrays

2020-02-07 Thread ag0aep6g via Digitalmars-d-learn
On 08.02.20 02:38, ag0aep6g wrote: Simplified, we're looking at this: struct Joiner {     int[3] _items;     int[] _current; } void main() @safe {     Joiner j;     j._current = j._items[]; } I.e., a self-referential struct. Or most fundamentally: struct Joiner {    

Re: Flatten a range of static arrays

2020-02-07 Thread ag0aep6g via Digitalmars-d-learn
On 08.02.20 01:17, Steven Schveighoffer wrote: The original code is not invalid though. f is not valid, and that is a bug, but the original code posted by nullptr should be fine by memory safety standards. Maybe. But then it should also work with `int[3] front;`. If there is no possible way

Re: Flatten a range of static arrays

2020-02-07 Thread ag0aep6g via Digitalmars-d-learn
On 08.02.20 00:10, nullptr wrote: ``` import std; struct SomeRange {     int[3] val;     enum empty = false;     auto popFront() @safe {}     ref auto front() @safe     {     return val;     } } void main() @safe {     SomeRange().take(10).map!((return ref x) =>

Re: Cannot take slice of scope static array in @safe code

2020-02-02 Thread ag0aep6g via Digitalmars-d-learn
On 02.02.20 19:49, ag0aep6g wrote: On 02.02.20 19:18, Steven Schveighoffer wrote: I'm not sure if I got it right, but like this?     int*[][] g1;     int*[] g2;     int* g3;     void main() @safe     {     /* An array stored on the stack, of references to heap data: */    

Re: Cannot take slice of scope static array in @safe code

2020-02-02 Thread ag0aep6g via Digitalmars-d-learn
On 02.02.20 19:18, Steven Schveighoffer wrote: On 2/2/20 10:20 AM, ag0aep6g wrote: [...] void main() @safe { int* a0; scope int** b0 = /* accepted */ scope int* a2; scope int** b2 = /* rejected */ } Now it's important to realize that

Re: Cannot take slice of scope static array in @safe code

2020-02-02 Thread ag0aep6g via Digitalmars-d-learn
On 02.02.20 14:40, Dennis wrote: Compiling the following with -dip1000 gives an error. ``` void main() @safe {     string[1] a0;     scope int[1] a1;     scope string[1] a2;     scope string[] b0 = a0[]; // Fine     scope int[] b1 = a1[]; // Fine     scope string[] b2 = a2[]; // Error:

Re: template instantiation problems

2020-01-10 Thread ag0aep6g via Digitalmars-d-learn
On 10.01.20 18:27, berni44 wrote: This clearly shows, that packageName is only instatiated once at top level although mod0 and mod1 are two different things (at least their stringof produces different results) and therefore should be instantiated twice. Now I don't know if this is a bug in

Re: Difference between slice[] and slice

2019-09-25 Thread ag0aep6g via Digitalmars-d-learn
On 25.09.19 22:36, WhatMeWorry wrote: On Wednesday, 25 September 2019 at 19:25:06 UTC, Ali Çehreli wrote: On 09/25/2019 12:06 PM, WhatMeWorry wrote: [...] > In short, is there anytime that one would want to use "slice[] = > something" syntax?I That changes element values. Ok.  But which

Re: Looking for a Simple Doubly Linked List Implementation

2019-09-21 Thread ag0aep6g via Digitalmars-d-learn
On 21.09.19 10:34, Ron Tarrant wrote: Here's a question for the room: Does a doubly-linked list always have to be done with structs? Can it be classes instead? (Maybe that's why I can't get it to work, because I've been trying to make an OOP version?) It can be done with classes. When I

Re: segmentation fault when running void main() {}

2019-09-18 Thread ag0aep6g via Digitalmars-d-learn
On 17.09.19 20:03, berni wrote: I'm trying to install D on my old 32-bit machine (debian stable). First I tried to install a precompiled version and now I followed [1]. In both cases, I always get a segmentation fault when I try to run a compiled program. You're probably hitting this issue:

Re: getting rid of immutable (or const)

2019-09-05 Thread ag0aep6g via Digitalmars-d-learn
On 05.09.19 21:51, berni wrote: void main() {     int[int] a;     immutable int b = 17;     a[1] = b;  // <-- expecting error here     const oldPointer = (1 in a);     immutable int c = 10;     a[1] = c;     assert(oldPointer is (1 in a));     Point[int] d;    

Re: Why is sformat and formattedWrite (appender) allocating GC mem here?

2019-09-03 Thread ag0aep6g via Digitalmars-d-learn
On 03.09.19 16:03, James Blachly wrote: For my own learning, why was a unittest to ensure no GC added to sformat instead of a @nogc annotation? `sformat` uses the GC less now, but it's not @nogc. It can still throw GC-allocated exceptions, e.g. when the arguments don't match the format

Re: Why is sformat and formattedWrite (appender) allocating GC mem here?

2019-08-31 Thread ag0aep6g via Digitalmars-d-learn
On 31.08.19 14:07, cc wrote: I'm guessing it's allocating a string first to write the contents of the array and then inserting that string into the buffer I supplied. Is there no way to have it skip this step and just write each element (plus the joining punctuation, etc) directly into the

Re: += on associative arrays leads to surprising result

2019-08-27 Thread ag0aep6g via Digitalmars-d-learn
On 27.08.19 18:12, berni wrote: import std.stdio; void main() {     real[int] a;     a[0] += 100;     writeln(a); } results (independed of the used compiler) in [0:100] I was a little bit surprised, because a[0] += 100 should be the same as a[0] = a[0]+100, which leads to a range

Re: Template specialized functions creating runtime instructions?

2019-08-20 Thread ag0aep6g via Digitalmars-d-learn
On 21.08.19 01:48, ads wrote: This piece of code creates a fizzbuzz string with template parameters. auto fizzbuzz(uint N)() { string accumulate; return fizzbuzz!N(accumulate); } auto fizzbuzz(uint N)(ref string result) if (N % 3 && N % 5) { import std.conv : to; result ~=

Re: filtering a row of a jagged array

2019-08-11 Thread ag0aep6g via Digitalmars-d-learn
On 11.08.19 18:11, DanielG wrote: auto x = whatever[2].filter(x => x > 7); // error You just forgot an exclamation mark here. auto x = whatever[2].filter!(x => x > 7); // works

Re: Private variables accessible from outside class

2019-08-08 Thread ag0aep6g via Digitalmars-d-learn
On 08.08.19 18:03, Drobet wrote: Then why does it in the tour say that it can only be "seen by Integer"? https://tour.dlang.org/tour/en/basics/classes That's an error in the tour.

Re: Why does choose not work here

2019-08-01 Thread ag0aep6g via Digitalmars-d-learn
On 01.08.19 22:23, Matt wrote: Version 4 does not work when PairedA.previous is null. I'd love to understand why. [...] auto myFilter(R1, R2)(R1 a, R2 b) { import std.algorithm : filter, canFind; return a.filter!(c => b.canFind(c)); } struct A { uint[] starts, stops;

Re: Why in Phobos is empty() sometimes const and sometimes not

2019-07-29 Thread ag0aep6g via Digitalmars-d-learn
On 29.07.19 21:35, H. S. Teoh wrote: Generally, the idiom is to let the compiler do attribute inference by templatizing your code and not writing any explicit attributes, then use unittests to ensure that instantiations of the range that ought to have certain attributes actually have those

Re: __stdin.d(2): Error: found End of File when expecting }

2019-07-17 Thread ag0aep6g via Digitalmars-d-learn
On 17.07.19 21:05, Andre Pany wrote: ``` #!/bin/bash text=" import std; void main() {     while(true)     {     string enemy1 = readln().strip;     int dist1 = to!int(readln().strip);     string enemy2 = readln().strip;     int dist2 = to!int(readln().strip);    

Re: q about slices, strings

2019-07-13 Thread ag0aep6g via Digitalmars-d-learn
On 13.07.19 22:35, Kevin Bailey wrote:     int[char[2]] aa;     auto arr = "ABBBA";     foreach (i; 0 .. arr.length - 1)     aa[arr[i .. $][0 .. 2]]++; which I changed to:     aa[arr[i .. i+2][0 .. 2]]++; in the hopes of only doing:     aa[arr[i .. i+2]]++; The question

Re: Trying to alias this a grapheme range + making it a forward range

2019-07-08 Thread ag0aep6g via Digitalmars-d-learn
On 08.07.19 23:55, aliak wrote: struct ustring {     string data;     this(string data) {     this.data = data;     }     auto get() {     static struct Range {     typeof(string.init.byGrapheme) source;     bool empty() { return source.empty; }     void

Re: Why are immutable array literals heap allocated?

2019-07-06 Thread ag0aep6g via Digitalmars-d-learn
On 06.07.19 01:12, Patrick Schluter wrote: On Friday, 5 July 2019 at 23:08:04 UTC, Patrick Schluter wrote: On Thursday, 4 July 2019 at 10:56:50 UTC, Nick Treleaven wrote: immutable(int[]) f() @nogc {     return [1,2]; } [...] and it cannot optimize it away because it doesn't know what the

Re: Finding Max Value of Column in Multi-Dimesional Array

2019-07-05 Thread ag0aep6g via Digitalmars-d-learn
On 05.07.19 20:49, Samir wrote: As a follow-on to my earlier question, is there a way to pass a variable to the `map` function that specifies the column, rather than hard-coding it?  I'm thinking of something like: p.map!("a[column]").maxElement.writeln; You can't do that with the string

Re: Associative Array & different template types

2019-07-03 Thread ag0aep6g via Digitalmars-d-learn
On 03.07.19 20:20, Robert M. Münch wrote: So, I need to carry around the object from which a delegate was created from because it's not possible to query the delegate for the object later somewhere else in the code. It is possible to get the context object out of a delegate: class C {

Re: Using scanw Ncurses in D lang

2019-06-15 Thread ag0aep6g via Digitalmars-d-learn
On 15.06.19 23:20, Gabol wrote: example: scanw("% i", & number); // The compiler accuses error. Error: function deimos.ncurses.curses.scanw(char* fmt, ...) is not callable using argument types (string, int*) source/app.d(8,14):    cannot pass argument "0" of type string to parameter char*

Re: Delegate / Error: cannot implicitly convert expression...

2019-06-15 Thread ag0aep6g via Digitalmars-d-learn
On Saturday, 15 June 2019 at 17:24:45 UTC, user1234 wrote: --- void foo(){writeln(__PRETTY_FUNCTION__);} void main(string[] args) { void delegate() dg; dg.funcptr = dg.ptr = null; // usually a "this" or a frame address dg(); } --- because dg.ptr would be used to retrieve the

Re: Function parameters UDAs

2019-06-10 Thread ag0aep6g via Digitalmars-d-learn
On 11.06.19 01:12, Johannes Loher wrote: I would like to iterate over all parameters of a function using static foreach and then process each parameter's UDAs. But by using static foreach on the parameter tuple, slicing it is not possible anymore, so the suggested workaround does not work in

Re: Error: char 0x200b not allowed in identifier

2019-06-03 Thread ag0aep6g via Digitalmars-d-learn
On 03.06.19 15:37, zoujiaqing wrote: Error for code: source/hunt/xml/Element.d(12,13): Error: char 0x200b not allowed in identifier U+200B is: ZERO WIDTH SPACE. Somehow you got that invisible character into your code. You have to get rid of it. To do it manually, navigate to the locations

Re: How to create an overwriteable struct that is always const?

2019-06-02 Thread ag0aep6g via Digitalmars-d-learn
On 02.06.19 04:22, David Zhang wrote: On Saturday, 1 June 2019 at 13:00:50 UTC, ag0aep6g wrote: How is setting/replacing different from modifying? e.g.:     S s;     this() { s = ...; }     update(S s) { this.s = s; }     mod(int i) { s.i = i; } // illegal Kinda like how strings can

Re: How to create an overwriteable struct that is always const?

2019-06-01 Thread ag0aep6g via Digitalmars-d-learn
On 01.06.19 14:51, David Zhang wrote:     struct S {     /*const*/ char* pointer;     ... other members ...     this(/*const*/ char* p, ... others ...) {     pointer = p;     ...     }     } What I want, is to be able to use `S` in other data structures

Re: Parameter pack expansion

2019-05-30 Thread ag0aep6g via Digitalmars-d-learn
On 30.05.19 22:20, Tomas wrote: Surely, there has to be a standard function which does exactly(probably better) the same thing as what `myMap` does. Nope.

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

2019-05-20 Thread ag0aep6g via Digitalmars-d-learn
On 20.05.19 13:47, Josh wrote: Normally I would say no, no and no.  Rounding issues will kill you every time. And you'd be right.   However: import std.stdio; import std.range; void main() { foreach (i; iota(1, 1000)) {     writefln("%f", cast(float) i / 100.0); } } Doesn't

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

2019-05-17 Thread ag0aep6g via Digitalmars-d-learn
On 16.05.19 17:55, Vladimir Panteleev wrote: On Thursday, 16 May 2019 at 15:52:05 UTC, Steven Schveighoffer wrote: [...] The output shouldn't involve the inner workings of the type. It should be changed to say 10 ns. If the output is meant for the developer, then I disagree subjectively, as

Re: Cast ptr/len to D-style array

2019-05-02 Thread ag0aep6g via Digitalmars-d-learn
On 02.05.19 22:03, James Blachly wrote: I work a lot with C functions, many of which yield pointer + length. Is there a way to cast this or materialize a D-style array backed by the already allocated data (with length) to avoid copies which slow things down? Just slice the pointer with the

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

2019-05-02 Thread ag0aep6g via Digitalmars-d-learn
On 02.05.19 01:18, kdevel wrote: Now I have: a/main.d a/b/package.d a/b/c/package.d b/package.d and c/package.d as before. For reference, a/b/c/package.d is this: module c; package import std.file; And a/b/package.d starts with: module b; import c; a/main.d is ``` import b;

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

2019-05-01 Thread ag0aep6g via Digitalmars-d-learn
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. I.e., that line effectively does this: dmd -unittest -main package.d ./package

Re: Alias to struct memembers of a function paramater as a shortcut => need this for XYZ of type void*

2019-04-07 Thread ag0aep6g via Digitalmars-d-learn
On 07.04.19 17:36, Robert M. Münch wrote: The docs state that an alias can either be related to the type or the symbol. Hence, in my case I expected it to be the symbol... The symbol is `X.a`. A field of an instance doesn't make a distinct symbol.

Re: Alias to struct memembers of a function paramater as a shortcut => need this for XYZ of type void*

2019-04-07 Thread ag0aep6g via Digitalmars-d-learn
On 07.04.19 14:23, Robert M. Münch wrote: struct X { TYPE a; TYPE b; } myFunc(X _struct){ alias a = _struct.a; a = myOtherFunc(); } X myStruct; myFun(myStruct); This gives an error: need this for a of type void* I don't understand why, because all I want is a

Re: alias sequences of sequences

2019-04-07 Thread ag0aep6g via Digitalmars-d-learn
On 07.04.19 06:58, Alex wrote: Is there any way to get sequences of sequences? Using RT, I have to use strings [[`string`, `0`], ...] when it would be much better to use [[string, 0], ...] Ideally it wouldn't add so much overhead that it defeats the purpose. You can make a template that

Re: CTFE & code generators based on PEG grammars?

2019-04-07 Thread ag0aep6g via Digitalmars-d-learn
On 07.04.19 05:32, Alex wrote: readlin is not a CT function. You misinterpreted what I said. Yeah, bad example from me. This would probably have been better: auto v = "foo"; enum y = f(v); /* Error: variable v cannot be read at compile time */ Also, the `readln` example wasn't

Re: CTFE & code generators based on PEG grammars?

2019-04-06 Thread ag0aep6g via Digitalmars-d-learn
On 06.04.19 16:19, Alex wrote: That is CTFE is CT RTFE where runtime functions are executed at compile time when the inputs are CT. You may have the right idea, but the last part of that sentence is wrong/misleading. CTFE happens when the result is required at CT. The inputs must be

Re: Using opOpAssign, cannot assign sequence

2019-04-05 Thread ag0aep6g via Digitalmars-d-learn
On 05.04.19 16:00, Alex wrote: I was thinking using tuple would work(of course is longer than Add but would allow for a more general approach, it would require automatic unpacking though and so doesn't work. `tuple` works for me: import std.typecons: tuple; class X(T ...) { void

Re: Wrong initialization of variables

2019-04-01 Thread ag0aep6g via Digitalmars-d-learn
On 01.04.19 18:31, Andrey wrote: Also with AST switch I get code where there aren't any lines with text "bool hasqwerty = false;" or "bool haszaqy = false;". What happens? Compiler bug. https://issues.dlang.org/show_bug.cgi?id=19479

Re: "if" statement

2019-03-24 Thread ag0aep6g via Digitalmars-d-learn
On 24.03.19 13:45, Francesco Mecca wrote: ``` alias Alg = Algebraic!(int, string); void main() { int n = 2;     Alg value;     value = n == 2 ? 2 : "string"; } ``` The original code used SumType but the effect is the same. I suppose that I could write the following: ```     if(n ==

Re: local class instance (at module-level)

2019-03-14 Thread ag0aep6g via Digitalmars-d-learn
On 14.03.19 20:43, Jacob Carlborg wrote: class C {     uint i ;     this (uint i) {     this.i = i ;     }     this (uint i) shared {     this.i = i ;     }     this (uint i) immutable {     this.i = i ;     } } __gshared c0 = new C(0); shared c1 = new shared C(1);

Re: How are (Static) Libraries with Templates Compiled?

2019-03-11 Thread ag0aep6g via Digitalmars-d-learn
On Monday, 11 March 2019 at 19:53:53 UTC, jmh530 wrote: So what information is in the static library that allows this to take place? None. The information is in in the source or interface file (.d/.di). Templates can't be compiled before they're instantiated.

Re: Array of byLineCopy ranges behaves as they are byLine

2019-03-11 Thread ag0aep6g via Digitalmars-d-learn
On Monday, 11 March 2019 at 15:23:53 UTC, HaraldZealot wrote: ```d File[] files; foreach(filename; args[1 .. $]) { files ~= File(filename, "r"); } auto ranges = files.map!(a => a.byLineCopy); writeln(ranges[0].front); writeln(ranges[0].front); writeln(ranges[0].front); ``` produces ``` 1 2

Re: 2 class issues

2019-03-07 Thread ag0aep6g via Digitalmars-d-learn
On 07.03.19 11:38, spir wrote: -1- How to enforce that subclasses implement given methods without using "abstract", which seems to make the whole class abstract? Not, as far as I can tell. You can't force derived classes to override an existing implementation. And you can't omit the

Re: Why is my @pure function @system when placed in a struct?

2019-02-27 Thread ag0aep6g via Digitalmars-d-learn
On 27.02.19 19:10, Dukc wrote: I tested a bit, and it appears that attribute inference is not done at all for templates inside structs -the attribute need not be a delegate: struct S     {     static int fImpl(Ret)() { return Ret.init; }     pragma(msg,

Re: template alias argument accepts only class/interface types.

2019-02-23 Thread ag0aep6g via Digitalmars-d-learn
On 23.02.19 23:30, Alexandru Ermicioi wrote: According to https://dlang.org/spec/template.html#TemplateAliasParameter, simple types and arrays are excluded from the list of supported "alias X" arguments. I'm wondering why do we have such limitation? Is there any reasoning at limiting

Re: Generalizing over function pointers and delegates

2019-02-15 Thread ag0aep6g via Digitalmars-d-learn
On 15.02.19 15:20, Bastiaan Veelo wrote: Exploiting this, it is possible to explicitly convert a function pointer into a delegate [2]: ``` Ret delegate(Args args) fun_to_dlg(Ret, Args...)(Ret function(Args args) fun) {     Ret delegate(Args) dlg;     dlg.funcptr = fun;     return dlg; }

Re: What is the Utility of Parent Class Method Hiding in Inheritance?

2019-01-14 Thread ag0aep6g via Digitalmars-d-learn
On 14.01.19 10:10, Vijay Nayar wrote: After a bit of reading, I understood the rule and how it works, but what I'm missing is the "why".  Why is it desirable to hide methods from a parent class which have the same name (but different arguments) as a method in a class?

Re: Dlang tour - Unittesting example

2018-10-02 Thread ag0aep6g via Digitalmars-d-learn
On 10/02/2018 03:24 PM, Basile B. wrote: The problem is the NaN madness. Since several values are NaN there's this strange stuff: void main() {     import std.stdio;     import std.math : isNaN;     double d;     writeln(d.init);    // nan     writeln(d); // nan    

Re: "Error: function expected before (), not module *module* of type void

2018-09-22 Thread ag0aep6g via Digitalmars-d-learn
On 09/22/2018 04:51 AM, Samir wrote: Thanks for your help, Adam!  Right after posting my question, I started reading this site: https://www.tutorialspoint.com/d_programming/d_programming_modules.htm Better read the original: http://ddili.org/ders/d.en/modules.html

Re: Error: incompatible types for 'shared(SysTime)' and 'shared(SysTime)'

2018-09-13 Thread ag0aep6g via Digitalmars-d-learn
On 09/13/2018 03:25 PM, Arafel wrote:     // How can we update the timestamp? Neither of those work     timestamp = Clock.currTime;     timestamp = cast(shared) Clock.currTime; cast() timestamp = Clock.currTime;

Re: Process in parallel and output result to stdout theread-safely

2018-09-08 Thread ag0aep6g via Digitalmars-d-learn
On 09/03/2018 08:13 PM, Dr.No wrote: But it in the middle of output, I got output like this: outjson = {"barCode":"20","ade":"20"}♪◙outjson = {"barCode":"X21","ade":"21"} also there's that extra ♪◙ character. Thos sounds memory violation somewhere. This only happens when using

Re: Get max elemenr over RegexMatch

2018-08-24 Thread ag0aep6g via Digitalmars-d-learn
On 08/24/2018 01:13 PM, Andrey wrote: This code produces an error: auto matches = content.matchAll(pattern); auto max = matches.maxElement!"a => a.back.to!uint"(); You're mixing two different notations. It's either matches.maxElement!(a => a.back.to!uint)() or

Re: Pure opEquals in a class

2018-08-20 Thread ag0aep6g via Digitalmars-d-learn
On Monday, 20 August 2018 at 19:36:15 UTC, werter wrote: The code below doesn't work. Is it possible to make a pure opEquals in a class? [...] pure bool opEquals(const A rhs) const { return b == rhs.b; } It doesn't

Re: Make function alias

2018-08-20 Thread ag0aep6g via Digitalmars-d-learn
On 08/20/2018 03:14 PM, Andrey wrote: Hello, I want to make an alias to function "std.stdio.writeln" and "std.stdio.write" and use it like: static void log(bool newline = true)(string text) {    alias print(T...) = newline ? :    _file.print();    text.print(); } Unfortunately, it

Re: Are properties mature enough?

2018-08-19 Thread ag0aep6g via Digitalmars-d-learn
On 08/19/2018 08:55 PM, Neia Neutuladh wrote: You *could* add @property to the next and seed functions. That forces people to use them as fields. It doesn't.

Re: unimplemented abstract function compiles.

2018-08-12 Thread ag0aep6g via Digitalmars-d-learn
On 08/12/2018 07:29 PM, Eric wrote: I thought it would work the same way as an interface (which must be implemented by the direct sub class, otherwise compile error). From the spec text [1], I'd also expect an error. It says: "An abstract member function must be overridden by a derived

Re: @nogc with opApply

2018-08-11 Thread ag0aep6g via Digitalmars-d-learn
On 08/11/2018 12:00 PM, Alex wrote: ´´´ import std.experimental.all; static assert(isIterable!S); [...] struct S { [...]     int opApply(scope int delegate(ref uint) /*@nogc*/ operations) //@nogc     { [...]     } } ´´´ Everything works fine, before I try to use the opApply function

Re: unimplemented abstract function compiles.

2018-08-11 Thread ag0aep6g via Digitalmars-d-learn
On 08/11/2018 10:55 PM, Eric wrote: Code below compiles while I would not expect it to compile. Is there a reason that this compiles? [...] class I {   abstract void f(); } class C : I { } unittest {   C c = cast(C) Object.factory("C");   c.f(); } Not a bug, as far as I see. You

Re: unimplemented abstract function compiles.

2018-08-11 Thread ag0aep6g via Digitalmars-d-learn
On 08/11/2018 11:20 PM, rikki cattermole wrote: On 12/08/2018 8:55 AM, Eric wrote: Code below compiles while I would not expect it to compile. Is there a reason that this compiles? [...] No bug. You forgot to throw -unittest when you compiled. [...] Error: program killed by signal 11 If

Re: CJK problem when using console outputs

2018-07-16 Thread ag0aep6g via Digitalmars-d-learn
On 07/16/2018 11:30 AM, zhani wrote: i got some problem about using CJK in windows10 console. here my code(a code file encoded the utf-8): -- import std.stdio; /* static this(){ core.stdc.wchar_.fwide(core.stdc.stdio.stdout, 1);

Re: class that is initialized becomes null when outside of function

2018-07-09 Thread ag0aep6g via Digitalmars-d-learn
On 07/09/2018 11:18 AM, Flaze07 wrote: class Game { [...]     RenderWindow win; [...]     void init()     { [...]     auto win = new RenderWindow( VideoMode( 600, 600 ), "snake" ); [...]     }     void run()     { [...]     writeln( win is null ); [...]     } } the

  1   2   3   4   5   6   7   >