Re: Parameters declared as the alias of a template won't accept the arguments of the same type.

2022-05-02 Thread Stanislav Blinov via Digitalmars-d-learn
On Monday, 2 May 2022 at 20:16:04 UTC, ag0aep6g wrote: On 02.05.22 21:17, Stanislav Blinov wrote: On Monday, 2 May 2022 at 16:29:05 UTC, Loara wrote: [...] ```d     template MyAlias(T){   alias MyAlias = int;     }     T simp(T)(MyAlias!T val){   return T.init;     }     int main(){

Re: Parameters declared as the alias of a template won't accept the arguments of the same type.

2022-05-02 Thread Stanislav Blinov via Digitalmars-d-learn
On Monday, 2 May 2022 at 20:08:48 UTC, Ali Çehreli wrote: On 5/2/22 12:17, Stanislav Blinov wrote: > On Monday, 2 May 2022 at 16:29:05 UTC, Loara wrote: > >> Template deduction for aliased function parameter is a very tricky >> argument and it's not so simple to handle in certain cases. Consider

Re: Parameters declared as the alias of a template won't accept the arguments of the same type.

2022-05-02 Thread Stanislav Blinov via Digitalmars-d-learn
On Monday, 2 May 2022 at 16:29:05 UTC, Loara wrote: Template deduction for aliased function parameter is a very tricky argument and it's not so simple to handle in certain cases. Consider for example this code: ```d template MyAlias(T){ alias MyAlias = int; } T

Re: CTFE and BetterC compatibility

2022-04-27 Thread Stanislav Blinov via Digitalmars-d-learn
On Wednesday, 27 April 2022 at 14:21:15 UTC, Claude wrote: This is a long-standing pain point with BetterC (see https://issues.dlang.org/show_bug.cgi?id=19268). As for this: If I compile without the BetterC switch, compilation actually works but I'll have some linker issues: ``` $ gcc

Re: std.typecons Typedef initializers?

2022-04-25 Thread Stanislav Blinov via Digitalmars-d-learn
On Monday, 25 April 2022 at 23:41:47 UTC, Chris Katko wrote: So to use a typedef'd struct... I have to basically add the original type on top of the typedef'd type every time? Surely it's not this clunky? I mean, why even use a typedef then. Why not use just pair, sPair, vPair, etc as

Re: Assigning to array of structs with custom constructor

2022-04-25 Thread Stanislav Blinov via Digitalmars-d-learn
On Monday, 25 April 2022 at 14:36:25 UTC, cc wrote: ```d struct Foo { string s; this(string s) { this.s = s; } } Foo foo = "a"; Foo[] foos = ["a"]; // Error: cannot implicitly convert expression `["a"]` of type `string[]` to `Foo[]` Foo[] foos = cast(Foo[]) ["a"]; // Error:

Re: How to use destroy and free.

2022-04-25 Thread Stanislav Blinov via Digitalmars-d-learn
On Monday, 25 April 2022 at 10:13:43 UTC, Alain De Vos wrote: Ali, thanks for the answer but i rephrase my question. How to destroy,free , for garbage-collection-cycle in the destructor of this code : // But How to force destroy and free , GC-cycle for heap object i ? Short answer: use

Re: Variables & kind of memory

2022-04-23 Thread Stanislav Blinov via Digitalmars-d-learn
On Saturday, 23 April 2022 at 03:41:17 UTC, Alain De Vos wrote: Feel free to elaborate. Variables declared at module scope, and static variables in function/aggregate scopes, unless also annotated as `shared` or `__gshared`, are thread-local, therefore are placed in thread-local storage.

Re: Lambda Tuple with Map Reduce

2022-04-20 Thread Stanislav Blinov via Digitalmars-d-learn
On Wednesday, 20 April 2022 at 08:37:09 UTC, Salih Dincer wrote: On Wednesday, 20 April 2022 at 08:04:42 UTC, Salih Dincer wrote: I get an unexpected result inside the second foreach() loop. Anyone know your reason? It's my fault, here is the solution: ```d foreach(fun; funs) {

Re: save and load a 2d array to a file

2022-04-19 Thread Stanislav Blinov via Digitalmars-d-learn
On Tuesday, 19 April 2022 at 06:05:27 UTC, Ali Çehreli wrote: One quirk of rawWrite and rawRead is that they want slices of objects. It is a little awkward when there is just one thing to write and read. Uncompiled but something like this: int i = 42; file.rawWrite(*cast((int[1]*)()));

Re: Nested function requires forward declaration?

2022-04-14 Thread Stanislav Blinov via Digitalmars-d-learn
On Thursday, 14 April 2022 at 08:55:25 UTC, Chris Katko wrote: Using DMD. v2.098-beta-2 Not sure if right terminology. But I just wrote a nested function that uses a variable outside its body. The capture (right term?) is obvious where the invocation is. However, I have to move the

Re: How to implement this?

2022-04-08 Thread Stanislav Blinov via Digitalmars-d-learn
On Friday, 8 April 2022 at 05:53:03 UTC, Elvis Zhou wrote: assumeNoEscapeOrWhatever!DynamicArray structs; structs ~= cast(A*) is it possible? That's what `@trusted` is for. And that's also why it should be used with care, and on the smallest code possible. ```d struct A {} struct B { A a;

Re: A weird example of .toUTF16z concatination side-effects in wcsncat

2022-04-07 Thread Stanislav Blinov via Digitalmars-d-learn
On Thursday, 7 April 2022 at 10:50:35 UTC, BoQsc wrote: wchar_t* clang_string = cast(wchar_t *)"AA"; You're witnessing undefined behavior. "AA" is a string literal and is stored in the data segment. Mere cast to wchar_t* does not make writing through that

Re: How to print or check if a string is "\0" (null) terminated in the D programming language?

2022-04-06 Thread Stanislav Blinov via Digitalmars-d-learn
On Wednesday, 6 April 2022 at 08:55:43 UTC, BoQsc wrote: I have a feeling that some parts of my code contains unterminated strings and they do overflow into other string that is to be combined. I'd like to take a look at strings, analyse them manually and see if any of them end up terminated

Re: Is it safe to read to memory after it has been allocated with `pureMalloc` and `pureRealloc`?

2022-04-04 Thread Stanislav Blinov via Digitalmars-d-learn
On Monday, 4 April 2022 at 07:32:00 UTC, rempas wrote: In other terms, do these functions auto-initialize memory to be ready for use? No. Neither `malloc` nor `realloc` (for which D's `pure...` variants are mere wrappers) are specified to initialize allocated memory. `calloc`, however, is -

Re: Help needed to learn templates

2022-03-19 Thread Stanislav Blinov via Digitalmars-d-learn
On Saturday, 19 March 2022 at 13:38:42 UTC, Vinod K Chandran wrote: On Saturday, 19 March 2022 at 11:47:53 UTC, Stanislav Blinov wrote: No. First of all Thanks for the reply. The answer "No" is a wonder to me. Because, from my point of view, `U` is coming from nowhere. My understanding is,

Re: Help needed to learn templates

2022-03-19 Thread Stanislav Blinov via Digitalmars-d-learn
On Saturday, 19 March 2022 at 05:54:26 UTC, Vinod K Chandran wrote: Question 1 - `U` is appearing in the first static if statement. But we had to write `U` on the template line, right? Like - `template rank(T, U)` No. Question 2 - The statif if test is - `T t == U[ ]` What does that mean

Re: How to remove all characters from a string, except the integers?

2022-03-04 Thread Stanislav Blinov via Digitalmars-d-learn
On Friday, 4 March 2022 at 19:51:44 UTC, matheus wrote: OK but there is another problem, I tested your version and mine and there is a HUGE difference in speed: string s, str = "4A0B1de!2C9~6"; Unless I did something wrong (If anything please tell). By the way on DMD was worse, it was

Re: How to remove all characters from a string, except the integers?

2022-03-03 Thread Stanislav Blinov via Digitalmars-d-learn
On Thursday, 3 March 2022 at 12:14:13 UTC, BoQsc wrote: I need to check if a string contains integers, and if it contains integers, remove all the regular string characters. I've looked around and it seems using regex is the only closest solution. ```d import std.stdio; import std.algorithm

Re: Detecting ElementType of OutputRange

2022-02-26 Thread Stanislav Blinov via Digitalmars-d-learn
On Saturday, 26 February 2022 at 12:26:21 UTC, Vijay Nayar wrote: On Saturday, 26 February 2022 at 11:44:35 UTC, Stanislav Blinov wrote: https://dlang.org/phobos/std_range_primitives.html#isOutputRange This method requires the caller to explicitly declare the output range element type, which

Re: Detecting ElementType of OutputRange

2022-02-26 Thread Stanislav Blinov via Digitalmars-d-learn
https://dlang.org/phobos/std_range_primitives.html#isOutputRange

Re: Differences between lambda function and regular functions in higher order functions

2022-02-21 Thread Stanislav Blinov via Digitalmars-d-learn
On Monday, 21 February 2022 at 10:04:16 UTC, steve wrote: I am trying to implement a simple map function. I found code to do this in another post but it only seems to work with lambda functions and I do not understand why. Any help would be greatly appreciated ``` import std.stdio; T[]

Re: Function Parameters without Names?

2022-02-20 Thread Stanislav Blinov via Digitalmars-d-learn
On Saturday, 19 February 2022 at 23:37:01 UTC, Vijay Nayar wrote: What is the main motivator to allow parameters with no names? 1) `extern(C) void* malloc(size_t);` No need for parameter name at all as that is only a declaration. You don't have an implementation thus don't need a name for

Re: Member function forwarding

2022-02-18 Thread Stanislav Blinov via Digitalmars-d-learn
On Thursday, 17 February 2022 at 21:17:02 UTC, Andrey Zherikov wrote: On Thursday, 17 February 2022 at 20:59:43 UTC, Andrey Zherikov wrote: Another question: does `auto foo(ARGS...)(ARGS args) { return a.foo(args); }` correctly forward `ref`, `const` etc. arguments? Actually the answer is

Re: what's meaning of "(a) =>"

2022-02-05 Thread Stanislav Blinov via Digitalmars-d-learn
On Saturday, 5 February 2022 at 15:10:19 UTC, step8 wrote: I'm trying to study D programming Following is code from vibe's example(web_ajax) code: void getDataFiltered(Fields field, string value) { auto table = users.filter!((a) => value.length==0 || a[field]==value)().array();

Re: ldc executable crashes with this code

2022-02-04 Thread Stanislav Blinov via Digitalmars-d-learn
On Friday, 4 February 2022 at 11:26:42 UTC, forkit wrote: If I had wrote the code below, then I should not expect anything, whatsoever, from the compiler. () @trustMe_I_am_a_complete_idiot { char[] palindrome = cast(char[])"able was I ere I saw elba"; } (); This is almost exactly what you

Re: passing a variadic parameter to randomSample

2022-01-26 Thread Stanislav Blinov via Digitalmars-d-learn
On Tuesday, 25 January 2022 at 22:07:43 UTC, Ali Çehreli wrote: On 1/25/22 13:55, forkit wrote: > auto RandomChoice(R...)(R r) Watch out though: The compiler will compile a different function per set of values. For example, there will be separate RandomChoice instances for ("hello") vs.

Re: Linkage question

2022-01-24 Thread Stanislav Blinov via Digitalmars-d-learn
On Monday, 24 January 2022 at 17:23:01 UTC, frame wrote: I understand that the linkage must match but besides the name mangling, what's happen here? What is the difference if I remove the `extern (C)` part from the T alias? The difference is in how arguments are being passed, which you seem

Re: map question

2022-01-23 Thread Stanislav Blinov via Digitalmars-d-learn
On Sunday, 23 January 2022 at 09:38:57 UTC, Siarhei Siamashka wrote: On Sunday, 23 January 2022 at 09:08:46 UTC, Stanislav Blinov wrote: Using `iota` here incurs additional computation and argument copies that are actually never used, i.e. wasted work. So I'd say go with `generate`, as that

Re: map question

2022-01-23 Thread Stanislav Blinov via Digitalmars-d-learn
On Saturday, 22 January 2022 at 23:54:27 UTC, forkit wrote: On Saturday, 22 January 2022 at 19:55:43 UTC, Stanislav Blinov wrote: thanks for the explanation. That really helped :-) writeln( generate!(() => dice(0.6, 1.4)).take(howManyTimes) ); [1, 1, 1, 1, 0] (or after reading Ali's

Re: map question

2022-01-22 Thread Stanislav Blinov via Digitalmars-d-learn
On Saturday, 22 January 2022 at 19:32:07 UTC, forkit wrote: trying to make sense of the below: // --- module test; import std; void main() { auto rnd = Random(unpredictableSeed); int howManyTimes = 5; // ok - using 'e =>' makes sense writeln(howManyTimes.iota.map!(e =>

Re: forward tuple arg to local variable + dtor

2022-01-22 Thread Stanislav Blinov via Digitalmars-d-learn
On Saturday, 22 January 2022 at 18:00:58 UTC, vit wrote: I want implement something like this: Scratch the previous reply, 'twas a brain fart... Simply take by value, no need for extra copies at all in that case. Arguments themselves will become those copies as needed. ```d import

Re: forward tuple arg to local variable + dtor

2022-01-22 Thread Stanislav Blinov via Digitalmars-d-learn
On Saturday, 22 January 2022 at 18:00:58 UTC, vit wrote: I want implement something like this: ... Take by value and make a copy without forwarding: ```d import std.typecons : Tuple; import std.meta : allSatisfy; enum bool isRcPtr(T) = is(T == RcPtr!U, U); //@safe access to data of

Re: automate tuple creation

2022-01-21 Thread Stanislav Blinov via Digitalmars-d-learn
On Friday, 21 January 2022 at 03:50:37 UTC, forkit wrote: I might have to use a kindof stringbuilder instead, then write a massive string once to the file. You're using writeln, which goes through C I/O buffered writes. Whether you make one call or several is of little consequence - you're

Re: automate tuple creation

2022-01-20 Thread Stanislav Blinov via Digitalmars-d-learn
On Thursday, 20 January 2022 at 12:15:56 UTC, forkit wrote: void createUniqueIDArray(ref int[] idArray, int recordsNeeded) { idArray.reserve(recordsNeeded); debug { writefln("idArray.capacity is %s", idArray.capacity); } // id needs to be 9 digits, and needs to start with 999

Re: why there is a [] at the end of assocArray

2022-01-19 Thread Stanislav Blinov via Digitalmars-d-learn
On Wednesday, 19 January 2022 at 13:15:35 UTC, michaelbi wrote: foreach(line; > File("input.txt").byLine.map!(a=>a.idup).array.transposed) so why there is a [] at the end of assocArray printed? thanks. ...because there's an empty line at the end of input.txt?

Re: A slice consisting of non-consecutive elements of an array?

2022-01-13 Thread Stanislav Blinov via Digitalmars-d-learn
On Thursday, 13 January 2022 at 19:52:27 UTC, forkit wrote: Any idea on how I can get a ptr (without hardcoding C style) e.g. something like this: immutable(string)*[] pointers = strings.filter!(x => x == "one").to!pointers.array; ```d import std.stdio : writeln; import std.algorithm :

Re: Returning value by ref does not create a ref. Is this intentional?

2022-01-04 Thread Stanislav Blinov via Digitalmars-d-learn
On Wednesday, 5 January 2022 at 04:35:12 UTC, Tejas wrote: ```d import std.stdio:writeln; ref int func(return ref int a){ a = 6; // modifies a as expected return a; } void main(){ int a = 5; auto c = func(a); // I expected c to alias a here c = 10; // Expected to modify a as

Re: Mixin a function into a struct only if no member with that name already exists

2021-12-29 Thread Stanislav Blinov via Digitalmars-d-learn
On Wednesday, 29 December 2021 at 10:14:13 UTC, Tobias Pankrath wrote: How do I mixin a function only if it is not already present? Perhaps use opDispatch?

Re: AA and struct with const member

2021-12-28 Thread Stanislav Blinov via Digitalmars-d-learn
On Wednesday, 29 December 2021 at 02:33:08 UTC, frame wrote: On Wednesday, 29 December 2021 at 01:11:13 UTC, Stanislav Blinov wrote: Because opIndexAssign cannot distinguish at compile time between initialization and assignment: ```d Stuff[Key] aa; aa[key] = Stuff(args); // ostensibly,

Re: Is there a way to make a function parameter accept only values that can be checked at compile time?

2021-12-28 Thread Stanislav Blinov via Digitalmars-d-learn
On Tuesday, 28 December 2021 at 22:30:30 UTC, Ali Çehreli wrote: On 12/28/21 2:06 PM, Steven Schveighoffer wrote:    void print_num(int mul)(int num) { Wasn't there a way of telling whether an 'auto ref' parameter is copied or not? void print_num()(int num, auto ref int mul) { // ? }

Re: AA and struct with const member

2021-12-28 Thread Stanislav Blinov via Digitalmars-d-learn
On Tuesday, 28 December 2021 at 22:46:16 UTC, frame wrote: On Tuesday, 28 December 2021 at 10:02:13 UTC, tsbockman wrote: // Should be a compile-time error, because it might reassign: test[key] = S(value); This might be a typo in your example but why should it be a compile-time error,

Re: How to loop through characters of a string in D language?

2021-12-23 Thread Stanislav Blinov via Digitalmars-d-learn
On Thursday, 23 December 2021 at 07:14:35 UTC, Salih Dincer wrote: It seems faster than algorithms in Phobos. We would love to see this in our new Phobos. ```d void mallocReplace() void normalReplace() string result = str.replace(';',""); }/* Console Out: Replace: 436 msecs Malloc

Re: How to properly use variadic templates (functions)?

2021-12-21 Thread Stanislav Blinov via Digitalmars-d-learn
On Tuesday, 21 December 2021 at 15:42:59 UTC, russhy wrote: Please keep us updated, that'll be interesting to see how a pure D printf would look like! It already exists, it's called std.format.write.formattedWrite, in terms of which things like std.stdio.writef are implemented.

Re: How to insert code in place with templates/mixins?

2021-12-20 Thread Stanislav Blinov via Digitalmars-d-learn
On Monday, 20 December 2021 at 18:03:09 UTC, rempas wrote: > Now the problem is that I want it to get the name of so > symbol and add it to a string literal. Let's check this example: enum state(alias name) = `name` ~ ` = 10;`; https://dlang.org/spec/traits.html#identifier

Re: dynamic array + copy ctor

2021-12-19 Thread Stanislav Blinov via Digitalmars-d-learn
On Sunday, 19 December 2021 at 22:29:21 UTC, vit wrote: Hello, Why is copy ctor in this example not called? Because D runtime isn't properly married to copy constructors yet. I.e. it's a bug, a variant of this one: https://issues.dlang.org/show_bug.cgi?id=20879

Re: How to define property type to Array!struct?

2021-12-15 Thread Stanislav Blinov via Digitalmars-d-learn
On Wednesday, 15 December 2021 at 11:36:41 UTC, Manfred Nowak wrote: 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

Re: Passing a derived class where base class is defined as ref parameter

2021-12-14 Thread Stanislav Blinov via Digitalmars-d-learn
On Tuesday, 14 December 2021 at 17:20:18 UTC, chopchop wrote: I am using the "ref" here (I put tinyurl to avoid over-referencing the post instead of the github page itself): https://tinyurl.com/bdddkmub I would like to be able to pass any kind of console to updateFoodToken ( Console c ), ie

Re: Immutability and arrays

2021-12-14 Thread Stanislav Blinov via Digitalmars-d-learn
On Tuesday, 14 December 2021 at 15:28:30 UTC, Steven Schveighoffer wrote: All the other problems you are having are deriving from this problem. Not exactly. One of the problems seems to be a genuine bug: ```d struct S { int[] x; // doesn't even participate here, neither would

Re: Immutability and arrays

2021-12-14 Thread Stanislav Blinov via Digitalmars-d-learn
On Tuesday, 14 December 2021 at 08:44:02 UTC, rumbu wrote: I am trying to understand why in this two different cases (Simple and Complex), the compiler behaviour is different. ```d struct SimpleStruct { int x;} struct ComplexStruct { int[] x; } void main() { SimpleStruct[] buf1;

Re: A debug class has started

2021-12-13 Thread Stanislav Blinov via Digitalmars-d-learn
On Monday, 13 December 2021 at 20:58:42 UTC, forkit wrote: immutable(char)[] replaceChar(char* str, ulong len, char ch1, char ch2) //snip return to!(immutable(char)[])(str); } You're calling a `to` on a char pointer, which, ostensibly, would look for null terminator. Which there may

Re: Why code failed to compile for foo2?

2021-12-11 Thread Stanislav Blinov via Digitalmars-d-learn
On Saturday, 11 December 2021 at 23:44:59 UTC, Adam Ruppe wrote: On Saturday, 11 December 2021 at 23:17:17 UTC, Stanislav Blinov wrote: ? No. If it was unsatisfied constraint, the error would've shown that. And if you try to instantiate it, you'll see it is an unsatisfied constraint anyway.

Re: Why code failed to compile for foo2?

2021-12-11 Thread Stanislav Blinov via Digitalmars-d-learn
On Saturday, 11 December 2021 at 22:59:52 UTC, Adam Ruppe wrote: On Saturday, 11 December 2021 at 22:50:45 UTC, apz28 wrote: void foo2(T)(Unqual!T x) if(isUnsigned!T) {} This means it treats foo2 as if it doesn't exist unless T is unsigned... onlineapp.d(15): Error: template

Re: How to loop through characters of a string in D language?

2021-12-11 Thread Stanislav Blinov via Digitalmars-d-learn
On Saturday, 11 December 2021 at 09:34:17 UTC, Ola Fosheim Grøstad wrote: void donttrythisathome(string s, char stripchar) @trusted { import core.stdc.stdlib; char* begin = cast(char*)alloca(s.length); A function with that name, and calling alloca to boot, cannot be @trusted ;)

Re: How to loop through characters of a string in D language?

2021-12-11 Thread Stanislav Blinov via Digitalmars-d-learn
On Friday, 10 December 2021 at 23:53:47 UTC, Ola Fosheim Grøstad wrote: ```d char[] dontdothis(string s, int i=0, int skip=0){ if (s.length == i) return new char[](i - skip); if (s[i] == ';') return dontdothis(s, i+1, skip+1); auto r = dontdothis(s, i+1, skip); r[i-skip] =

Re: How to loop through characters of a string in D language?

2021-12-10 Thread Stanislav Blinov via Digitalmars-d-learn
On Friday, 10 December 2021 at 13:22:58 UTC, Matheus wrote: My C way of thinking while using D: import std; string stripsemicolons(string input){ char[] s = input.dup; int j=0; for(int i=0;i Oooh, finally someone suggested to preallocate storage for all these reinventions of

Re: How to loop through characters of a string in D language?

2021-12-08 Thread Stanislav Blinov via Digitalmars-d-learn
On Wednesday, 8 December 2021 at 22:18:23 UTC, forkit wrote: It's also worth noting the differences in compiler output, as well as the time taken to compile, these two approaches: (1) string str = "abc;def;ab".filter!(c => c != ';').to!string; (2) string str = "abc;def;ab".replace(";", "");

Re: Any workaround for "closures are not yet supported in CTFE"?

2021-12-08 Thread Stanislav Blinov via Digitalmars-d-learn
On Wednesday, 8 December 2021 at 08:07:59 UTC, Petar Kirov [ZombineDev] wrote: ```d interface ICallable { void opCall() const; } alias Action = void delegate(); struct A { Action[] dg; } ``` At this point why not just call a spade a spade and store an array of ICallables directly?

Re: Mixin template overloads not working

2021-12-03 Thread Stanislav Blinov via Digitalmars-d-learn
On Friday, 3 December 2021 at 10:42:37 UTC, Rumbu wrote: Bug or feature? Is there any workaround? The error message explains what to do :) Error: class `mixinover.AnotherVisitor` use of `mixinover.Visitor.visit(S s)` is hidden by `AnotherVisitor`; use `alias visit = Visitor.visit;` to

Re: sleeping vs sched_yield

2021-12-02 Thread Stanislav Blinov via Digitalmars-d-learn
On Thursday, 2 December 2021 at 23:29:17 UTC, Chris Katko wrote: there's: ```d import core.thread; Thread.sleep( dur!("msecs")(10) ); ``` but what if you want to simply yield all remaining time back to the time scheduler? Is there a D std.library accessible version of POSIX

Re: bool empty() const for ranges

2021-11-26 Thread Stanislav Blinov via Digitalmars-d-learn
On Friday, 26 November 2021 at 10:44:10 UTC, Salih Dincer wrote: * Is the const essential for ranges? * Is it possible to rewind the pointer (```Node * head;```) when my head is empty by the const? `empty` is not required to be `const`, but it is required to yield the same result if called

Re: Include .def definition file information for the linker into a .d source file

2021-11-25 Thread Stanislav Blinov via Digitalmars-d-learn
On Thursday, 25 November 2021 at 09:00:52 UTC, Imperatorn wrote: What most ppl do in that case is to just provide a script, for example build.cmd that just does what it needs. The user just clicks the script and it does everything for them. "How can I make it so that I don't need an extra

Re: Any additions for write-to-file short program

2021-11-18 Thread Stanislav Blinov via Digitalmars-d-learn
On Thursday, 18 November 2021 at 22:20:48 UTC, pascal111 wrote: In next program that rewrites original written texts into new files, I see that it may need some additions or we can accept it like this because it's just a simple program that achieve its task and doesn't need any philosophical

Re: using __traits to get line number of a member

2021-11-13 Thread Stanislav Blinov via Digitalmars-d-learn
On Sunday, 14 November 2021 at 04:05:45 UTC, forkit wrote: However, there is no isClass method. Why not? How do I determine if a member is a class.. I wonder... ``` static if (is(something == class)) { /* ... */ } ``` or, if member is an instance ``` static if (is(typeof(something) ==

Re: using __traits to get line number of a member

2021-11-13 Thread Stanislav Blinov via Digitalmars-d-learn
On Saturday, 13 November 2021 at 08:04:56 UTC, forkit wrote: int i; foreach(m; __traits(allMembers, mixin(__MODULE__))) // ... __traits(getLocation, mixin(m))[1]); What you really should be doing is this: ```d static import mod = mixin(__MODULE__); foreach (i, name;

Re: using __traits to get line number of a member

2021-11-12 Thread Stanislav Blinov via Digitalmars-d-learn
On Saturday, 13 November 2021 at 05:31:51 UTC, forkit wrote: Code below is self explanatory. Any assistance on how to get the line number is welcome ;-) https://dlang.org/spec/traits.html#getLocation That?

Re: Completing C code with D style

2021-11-11 Thread Stanislav Blinov via Digitalmars-d-learn
On Thursday, 11 November 2021 at 22:10:04 UTC, forkit wrote: It's called 'staged learning'. Staged learning is the only way for humans to learn, due to the limitations of the human cognitive system. Specifically, the way short-term memory and long-term memory facilitate learning. Those who

Re: Completing C code with D style

2021-11-11 Thread Stanislav Blinov via Digitalmars-d-learn
On Thursday, 11 November 2021 at 21:56:19 UTC, Ali Çehreli wrote: On 11/11/21 11:34 AM, Stanislav Blinov wrote: > Pessimization, though, is laughably easy, and > should be avoided at all costs. I am not passionate about this topic at all and I am here mostly because I have fun in this forum.

Re: Completing C code with D style

2021-11-11 Thread Stanislav Blinov via Digitalmars-d-learn
On Thursday, 11 November 2021 at 00:11:07 UTC, H. S. Teoh wrote: It depends on what you're doing. In the OP's example, yeah worrying about allocations is totally blowing things out of proportions. But that's the thing. How would one ever learn to know where that dividing line is if all the

Re: Completing C code with D style

2021-11-11 Thread Stanislav Blinov via Digitalmars-d-learn
On Wednesday, 10 November 2021 at 23:15:09 UTC, forkit wrote: On Wednesday, 10 November 2021 at 22:17:48 UTC, russhy wrote: On Wednesday, 10 November 2021 at 06:47:32 UTC, forkit wrote: btw. My pc has 24GB of main memory, and my CPU 8MB L3 cache. So I really don't give a damn about allocations

Re: Wrong result with enum

2021-11-11 Thread Stanislav Blinov via Digitalmars-d-learn
On Thursday, 11 November 2021 at 09:11:37 UTC, Salih Dincer wrote: Unless explicitly set, default type is int. 110 is greater than int.max. 11 ```d enum w = 100_000; size_t b = w * w; // size_t b = 10 * 10; // ??? assert(b == 10_000_000_000); // Assert Failure ```

Re: Wrong result with enum

2021-11-10 Thread Stanislav Blinov via Digitalmars-d-learn
On Thursday, 11 November 2021 at 05:37:05 UTC, Salih Dincer wrote: is this a issue, do you need to case? ```d enum tLimit = 10_000; // (1) true result enum wLimit = 100_000; // (2) wrong result ``` https://dlang.org/spec/enum.html#named_enums Unless explicitly set, default type is int.

Re: Completing C code with D style

2021-11-09 Thread Stanislav Blinov via Digitalmars-d-learn
On Wednesday, 10 November 2021 at 06:47:32 UTC, forkit wrote: btw. My pc has 24GB of main memory, and my CPU 8MB L3 cache. So I really don't give a damn about allocations .. not one little bit ;-) That's not the point. The point is the program is doing unnecessary non-trivial work while

Re: Completing C code with D style

2021-11-09 Thread Stanislav Blinov via Digitalmars-d-learn
On Tuesday, 9 November 2021 at 11:03:09 UTC, forkit wrote: They both produce exactly the same output. But do vastly different things. But I tell ya.. the cognitive load .. well.. it increased dramatically ;-) Of course it did. Cuz you overthunk it. Dramatically. Your D version allocates

Re: auto ref function parameter causes that non copyable struct is copied?

2021-11-08 Thread Stanislav Blinov via Digitalmars-d-learn
On Monday, 8 November 2021 at 23:26:39 UTC, tchaloupka wrote: ``` auto gen() { Foo f; // <--- this one f.n = 42; return value(f.move()); } void main() { Foo f; f = gen().unwrap.move; } ``` ~this(0) ~this(0) ~this(0) ~this(42) <- this is a copy (that

Re: How do I assign attributes of a function to another function?

2021-11-05 Thread Stanislav Blinov via Digitalmars-d-learn
On Friday, 5 November 2021 at 06:19:16 UTC, Li30U wrote: ...e.g. ```d // ... mixin ("ReturnType /*...snip...*/ " ~ member ~ "()(Parameters! /*...snip...*/ ``` Note the `()` before parameter list. This would make your member function a function template, for which attributes will be inferred

Re: How do I assign attributes of a function to another function?

2021-11-05 Thread Stanislav Blinov via Digitalmars-d-learn
On Friday, 5 November 2021 at 06:19:16 UTC, Li30U wrote: I am creating a templated object that is a storehouse for a heap object and executes their methods and returns an array of results. With the help of a template, I want to achieve this, but I want to assign the same attributes to the

Re: Completing C code with D style

2021-11-03 Thread Stanislav Blinov via Digitalmars-d-learn
On Wednesday, 3 November 2021 at 00:50:51 UTC, Siarhei Siamashka wrote: !text.join("\n").writeln; Ahem... You've turned a program that does not allocate to a program that allocates who knows how much memory? And Ali... associative arrays? For this? What are you trying to teach the

Re: Does associative array change the location of values?

2021-10-30 Thread Stanislav Blinov via Digitalmars-d-learn
On Saturday, 30 October 2021 at 22:47:57 UTC, Elronnd wrote: If the GC were moving, it would also have to move the pointers you took to AA elements. You would never get stale pointers in any event. Who said you would?..

Re: Does associative array change the location of values?

2021-10-30 Thread Stanislav Blinov via Digitalmars-d-learn
On Saturday, 30 October 2021 at 20:19:58 UTC, Imperatorn wrote: https://dlang.org/spec/garbage.html#pointers_and_gc What test could be written to verify the behaviour? Assuming the GC was moving? You'd need a loop allocating different sizes, storing the addresses somewhere the GC won't

Re: Does associative array change the location of values?

2021-10-30 Thread Stanislav Blinov via Digitalmars-d-learn
On Saturday, 30 October 2021 at 18:31:16 UTC, Andrey Zherikov wrote: I did small test and it printed the same values three times so even rehash doesn't change the address of the value: So it seems pretty safe to store a pointer to a value in AA. And I agree that this should definitely be

Re: Does associative array change the location of values?

2021-10-30 Thread Stanislav Blinov via Digitalmars-d-learn
On Saturday, 30 October 2021 at 17:45:57 UTC, Steven Schveighoffer wrote: You said "deallocating unreferenced elements". I thought you meant elements unreferenced by the AA. Yup, I misunderstood you :) What I mean is, the AA isn't going to change implementations where it now deallocates

Re: Does associative array change the location of values?

2021-10-30 Thread Stanislav Blinov via Digitalmars-d-learn
On Saturday, 30 October 2021 at 16:55:03 UTC, Steven Schveighoffer wrote: auto v = k in aa; aa.remove(k); How can the GC/compiler work out that there is still a reference? ??? The same way it does for all other references. I think either you misunderstood me, or I misunderstood you.

Re: Does associative array change the location of values?

2021-10-30 Thread Stanislav Blinov via Digitalmars-d-learn
On Saturday, 30 October 2021 at 11:59:15 UTC, Steven Schveighoffer wrote: It should be documented. There isn't a valid way to remove these requirements, even if they are currently just an implementation detail -- code already depends on these properties. And D is a GC-based language,

Re: Does associative array change the location of values?

2021-10-29 Thread Stanislav Blinov via Digitalmars-d-learn
On Friday, 29 October 2021 at 21:00:48 UTC, Steven Schveighoffer wrote: This is incorrect, the buckets are each heap allocated. Just the array of bucket pointers would change. In addition, AAs do not deallocate the key/value pairs ever. You are safe to obtain a pointer to a value and it

Re: Linker issues with struct postblit

2021-10-29 Thread Stanislav Blinov via Digitalmars-d-learn
On Friday, 29 October 2021 at 11:05:14 UTC, Imperatorn wrote: On Thursday, 28 October 2021 at 01:39:10 UTC, Thomas Gregory wrote: I am a maintainer of the [dhtslib](https://github.com/blachlylab/dhtslib) package and I have been running into issues with a new implementation of reference

Re: Bitfileds Error: no identifier for declarator

2021-10-27 Thread Stanislav Blinov via Digitalmars-d-learn
On Thursday, 28 October 2021 at 05:20:35 UTC, data pulverizer wrote: I am trying to compile the following items: struct sxpinfo_struct { mixin(bitfields!( // ... uint, "debug",1, // ... } ``` But I get the error... `debug` is a language keyword, try a different one, like

Re: What's the point of static arrays ?

2020-07-10 Thread Stanislav Blinov via Digitalmars-d-learn
On Friday, 10 July 2020 at 10:13:23 UTC, wjoe wrote: So many awesome answers, thank you very much everyone! Less overhead, Using/needing it to interface with something else, and Efficiency are very good points. However stack memory needs to be allocated at program start. I don't see a huge

Re: How to ensure template function can be processed during compile time

2020-07-08 Thread Stanislav Blinov via Digitalmars-d-learn
On Wednesday, 8 July 2020 at 20:11:05 UTC, IGotD- wrote: int v; enum sz = mySize!int // works, returns 46 enum sz2 = mySize(v) // doesn't work. Error: variable v cannot be read at compile time Here we have a difference between C++ and D as C++ was able infer the size of v during compile

Re: constructing labels for static foreach inside switch inside foreach

2020-07-08 Thread Stanislav Blinov via Digitalmars-d-learn
On Wednesday, 8 July 2020 at 02:06:01 UTC, Steven Schveighoffer wrote: Seems simple enough, except that this inner portion is unrolled, and if I have more than one type to run this on, I already have an "innerloop" label defined. Is there a way to define a label using a mixin or something?

Re: opApply and attributes

2020-07-07 Thread Stanislav Blinov via Digitalmars-d-learn
On Tuesday, 7 July 2020 at 13:33:41 UTC, Paul Backus wrote: You can make opApply a template: int opApply(Dg)(Dg dg) if (is(Dg : scope int delegate(ref E))) { // etc. } Because `scope int delegate(ref E) @safe` implicitly converts to `scope int delegate(ref E)`,

Re: BetterC Bug? Intended Behavior? Asking Here As Unsure

2020-07-06 Thread Stanislav Blinov via Digitalmars-d-learn
On Monday, 6 July 2020 at 20:06:51 UTC, Kayomn wrote: Something discovered in the D Language Code Club Discord server with the help of Wild is that the following code: struct Test { ~this() {} } void tester(Test test, Test[] tests...) { } extern(C) void main() { tester(Test(), Test()); }

Re: Print only part of a stack trace

2020-07-01 Thread Stanislav Blinov via Digitalmars-d-learn
On Wednesday, 1 July 2020 at 18:30:15 UTC, Dennis wrote: I have a function that checks a global error constant of a C library (OpenGL) like this: ``` void assertNoOpenGLErrors() { if (glGetError() != GL_NO_ERROR) { assert(0); // stack trace points to here instead of caller }

Re: Progress printing with threads?

2020-07-01 Thread Stanislav Blinov via Digitalmars-d-learn
On Wednesday, 1 July 2020 at 07:52:28 UTC, AB wrote: Hello. I am unsure how to proceed about printing progress in my program. Is it a good idea to std.concurrency.spawn a new thread?.. This example code shows my situation: MmFile input = new MmFile(/* ... */); ulong fileSize

Re: idiomatic output given -preview=nosharedaccess ,

2020-06-30 Thread Stanislav Blinov via Digitalmars-d-learn
On Tuesday, 30 June 2020 at 20:04:33 UTC, Steven Schveighoffer wrote: The answer is -- update Phobos so it works with -nosharedaccess :) Yeah... and dip1000. And dip1008. And dip... :)

Re: Privatize a few members to allow messing with them #11353

2020-06-30 Thread Stanislav Blinov via Digitalmars-d-learn
On Tuesday, 30 June 2020 at 19:58:05 UTC, matheus wrote: +loc.linnum = loc.linnum + incrementLoc; This works because it was declared: void linnum(uint rhs) { _linnum = rhs; } Right? Almost. Given these definitions: @safe @nogc pure @property { const uint linnum() { return

Re: Privatize a few members to allow messing with them #11353

2020-06-30 Thread Stanislav Blinov via Digitalmars-d-learn
On Tuesday, 30 June 2020 at 19:42:57 UTC, matheus wrote: in this case this was more a style thing than anything else right? Or is there something I'm not able to see? Before the change, linnum and charnum are public variables, one can do a += on them. After the change, they become properties

Re: scope guard question

2020-06-29 Thread Stanislav Blinov via Digitalmars-d-learn
On Monday, 29 June 2020 at 22:31:12 UTC, Arjan wrote: So when no inner scope is present, the scope exit 'runs' after the return? Is that indeed expected behavior according to the specification? Yes. A scope ends at the '}'. Destructors and scope guards execute then, after the return.

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

2020-06-29 Thread Stanislav Blinov via Digitalmars-d-learn
On Monday, 29 June 2020 at 06:21:43 UTC, ag0aep6g wrote: Since `local` and `writeln` are templates, the attributes for their parameters are inferred from their bodies. `local!(int*)` doesn't do anything with the parameter, so it's inferred as `scope`. `writeln!(int*)` apparently does

Re: reference variables don't exist, but can simulate them

2020-06-28 Thread Stanislav Blinov via Digitalmars-d-learn
On Monday, 29 June 2020 at 02:11:15 UTC, NonNull wrote: Deprecation: Cannot use alias this to partially initialize variable j of type refer. Use j._() This is for the line j=3 What is this about? Where does this hidden rule come from? That one comes from [1]. But there are quite a few more

  1   2   3   >