Re: How is opEquals used in toHash

2021-05-18 Thread Simen Kjærås via Digitalmars-d-learn
On Tuesday, 18 May 2021 at 10:14:26 UTC, PinDPlugga wrote: But what I do not understand is why opEquals is necessary and where in the implementation of toHash it plays its role? Since area1 and area2 have different static arrays of Points I understand why `typeid(points).getHash()` would

Re: type of functions

2021-05-10 Thread Simen Kjærås via Digitalmars-d-learn
On Monday, 10 May 2021 at 10:37:51 UTC, Alain De Vos wrote: Can I say that the compiler is intelligent enough to add the attributes "pure nothrow @nogc @safe" ? Yes, in those cases (and some others). The functionality is described here:

Re: Dlang equivalent of #define/#ifdef : not... version

2021-04-20 Thread Simen Kjærås via Digitalmars-d-learn
On Tuesday, 20 April 2021 at 18:57:46 UTC, ichneumwn wrote: So my questions: - is there a module-crossing equivalent of "version"? mw covered this. There's more documentation here: https://dlang.org/spec/version.html#version https://dlang.org/dmd-windows.html#switch-version - if not, is

Re: How can I allocate a int[] array on stack?

2021-03-26 Thread Simen Kjærås via Digitalmars-d-learn
On Friday, 26 March 2021 at 14:27:58 UTC, Jack wrote: On Friday, 26 March 2021 at 06:45:39 UTC, Daniel Kozak wrote: On Fri, Mar 26, 2021 at 7:36 AM Daniel Kozak wrote: On Fri, Mar 26, 2021 at 7:31 AM Daniel Kozak wrote: On Fri, Mar 26, 2021 at 6:50 AM Jack via Digitalmars-d-learn <

Re: Opaque type (struct) with a static immutable fails to compile without constructor - why?

2021-03-04 Thread Simen Kjærås via Digitalmars-d-learn
On Thursday, 4 March 2021 at 13:58:48 UTC, frankp wrote: Hi all, I want to make an opaque type that simply contains an integer with some immutable constants and toString pretty printing. Like this: struct Foo_t { private long foo; alias foo this; static immutable long Inf =

Re: Templated delegate as template argument for structs

2021-02-20 Thread Simen Kjærås via Digitalmars-d-learn
On Saturday, 20 February 2021 at 09:16:46 UTC, Simon van Bernem wrote: I have the following struct declaration: struct Hash_Table(Key, Value, u32 delegate(ref Key) custom_hash_function = null) [snip] I take it from the error that the problem is not actually the delegate that I am passing,

Re: Creating 1000 instances

2021-02-19 Thread Simen Kjærås via Digitalmars-d-learn
On Friday, 19 February 2021 at 10:02:05 UTC, Siemargl wrote: On Friday, 19 February 2021 at 08:29:36 UTC, Ferhat Kurtulmuş wrote: Since classes are reference types all instances of files will be the same reference of "new File()", which you probably don't want. Is any differences between x

Re: Two "references" to dynamic array, why not change both when reallocating?

2020-11-11 Thread Simen Kjærås via Digitalmars-d-learn
On Wednesday, 11 November 2020 at 10:17:09 UTC, zack wrote: I am new to D. Appending to an array can lead to reallocation, that's clear. But why is the "reference" b not changed accordingly to the new position and still points to "old" memory? Why is b not also changed when reallocating array

Re: How add class or struct member after construction?

2020-11-05 Thread Simen Kjærås via Digitalmars-d-learn
On Thursday, 5 November 2020 at 22:48:38 UTC, Marcone wrote: How add class or struct member after construction? Is it possible in D? How? This depends a lot on what you mean. The short answer is no - you cannot. However, given some limitations, it is possible. What sort of members do you

Re: this T / variadic template and interfaces

2020-10-26 Thread Simen Kjærås via Digitalmars-d-learn
On Monday, 26 October 2020 at 11:14:47 UTC, frame wrote: Did not find this topic: I have an interface and some wrapper classes that use it. The wrapper's methods should accept variadic arguments. The runtime should only work with the interface, trying casting to a wrapper is not an option,

Re: Call method of object variable

2020-10-16 Thread Simen Kjærås via Digitalmars-d-learn
On Friday, 16 October 2020 at 08:12:59 UTC, Andrey wrote: Hi, I have got: struct Qaz { wstring read() {return null;} wstring hear() {return "";} } void main() { // ... static if(some_condition) alias method = Qaz.hear; else alias method = Qaz.read; // ... Qaz

Re: Why is "delete" unsafe?

2020-09-23 Thread Simen Kjærås via Digitalmars-d-learn
On Wednesday, 23 September 2020 at 04:15:51 UTC, mw wrote: It's there because there _are_ times when it makes sense and is useful, but it's definitely not safe, so you have to be careful and know what you're doing. What do you mean by saying "it's definitely not safe" here? I mean: if I'm

Re: Why private methods cant be virtual?

2020-09-22 Thread Simen Kjærås via Digitalmars-d-learn
On Tuesday, 22 September 2020 at 13:19:10 UTC, Daniel Kozak wrote: So final private functions can be overriden? It seems not, but the sentence is definitely confusing if not just plain wrong. Yeah. I've seen this called hiding, shadowing and overwriting earlier, but never overriding - that's

Re: Why is dtor called for lazy parameter?

2020-09-18 Thread Simen Kjærås via Digitalmars-d-learn
On Friday, 18 September 2020 at 14:14:31 UTC, Andrey Zherikov wrote: It seems that dtor is called at exit from lazy delegate, not at exit form create(): == create() .do_something() .do_lazy() .do_something(); == Output: == -> void test.main() -> test.do_lazy(lazy S

Re: Why is dtor called for lazy parameter?

2020-09-18 Thread Simen Kjærås via Digitalmars-d-learn
On Friday, 18 September 2020 at 12:32:49 UTC, Andrey Zherikov wrote: == The output is: == -> void test.main() -> test.do_lazy(lazy S s) -> test.create() 1 S test.S.this(int n) <- test.create() 1 void test.S.~this() ===-1 (2) <- test.do_lazy(lazy S s) -> 1703096

Re: Why is dtor called for lazy parameter?

2020-09-18 Thread Simen Kjærås via Digitalmars-d-learn
On Friday, 18 September 2020 at 10:43:47 UTC, Andrey Zherikov wrote: Why is dtor called before returning from do_lazy function - see (1)? It seems cause uninitialized parameter in do_something call after it in (2)-(3). As ikod mentions, it's because of scoped!S. As for why it does this,

Re: Type inference for constructors

2020-09-18 Thread Simen Kjærås via Digitalmars-d-learn
On Friday, 18 September 2020 at 05:43:56 UTC, data pulverizer wrote: I’d like to know if constructors of classes and structs can have type inference. So far, I am using a separate function for this purpose, for example: ``` import std.stdio: writeln; struct Pair(T, U) { T first; U

Re: another question on hidden mixin names

2020-09-17 Thread Simen Kjærås via Digitalmars-d-learn
On Thursday, 17 September 2020 at 21:05:59 UTC, 60rntogo wrote: struct V { int x; mixin assign!"+"; // mixin assign!"-"; } However, if I uncomment the second mixin, there is an error "v is not a scalar, it is a V". I guess I somehow need to merge these overloads, but I don't know how.

Re: enum and const or immutable ‘variable’ whose value is known at compile time

2020-09-17 Thread Simen Kjærås via Digitalmars-d-learn
On Thursday, 17 September 2020 at 10:56:28 UTC, Mike Parker wrote: On Thursday, 17 September 2020 at 09:44:20 UTC, claptrap wrote: Seriously how it's implemented is irrelevant. And to be clear, my point wasn't about how it's implemented. My point was that: enum { foo = 10; } and enum

Re: Neater "not version (...)" ?

2020-09-16 Thread Simen Kjærås via Digitalmars-d-learn
On Wednesday, 16 September 2020 at 19:04:24 UTC, Vladimirs Nordholm wrote: On Wednesday, 16 September 2020 at 18:54:45 UTC, Jacob Carlborg wrote: version (Windows) enum windows = true; else enum windows = false; static if (!windows) { // ... my code } Ah, I guess it boils down to

Re: Why does compose from std.functional return a templated function

2020-09-16 Thread Simen Kjærås via Digitalmars-d-learn
On Wednesday, 16 September 2020 at 09:59:59 UTC, Jan Hönig wrote: I have toyed with the compose template in std.functional and ran into some problems. rikki_cattermole on discord helped me a lot to solve my problem. However, what still remains (for me) to understand is why. Source code for

Re: Get enum value name as string at compile time?

2020-09-14 Thread Simen Kjærås via Digitalmars-d-learn
On Monday, 14 September 2020 at 03:48:51 UTC, Steven Schveighoffer wrote: Consider the enum: enum Foo { a, b } Foo.a.stringof => "a" enum x = Foo.a; x.stringof => "cast(Foo)0" Is there another way I can take an enum value that's known at compile time (but not the actual identifier), and get

Re: sending the address of a struct

2020-09-06 Thread Simen Kjærås via Digitalmars-d-learn
On Sunday, 6 September 2020 at 09:58:54 UTC, Johann Lermer wrote: pointer. The error message says: std.concurrency.MessageMismatch@std/concurrency.d(237): Unexpected message type: expected 'shared(Env*)', got 'shared(test.Env)*' The error message gives you all the information you need -

Re: tupleof seems to break encapsulation

2020-09-04 Thread Simen Kjærås via Digitalmars-d-learn
On Friday, 4 September 2020 at 10:16:47 UTC, 60rntogo wrote: Consider the following code. foo.d --- module foo; struct Foo { private int i; } --- main.d --- void main() { import std.stdio; import foo; auto x = Foo(); writeln(x); // ++x.i; ++x.tupleof[0]; writeln(x); } --- As

Re: Tuple poilerplate code

2020-09-01 Thread Simen Kjærås via Digitalmars-d-learn
On Tuesday, 1 September 2020 at 02:08:54 UTC, JG wrote: Is there anyway to remove the boilerplate code of dealing with tuples: I find myself having to write things like this fairly often auto someRandomName = f(...); //where f returns a tuple with two parts auto firstPart =

Re: Wrong selection of opEquals for objects.

2020-08-28 Thread Simen Kjærås via Digitalmars-d-learn
On Friday, 28 August 2020 at 13:35:43 UTC, Alexandru Ermicioi wrote: On Friday, 28 August 2020 at 12:29:20 UTC, Simen Kjærås wrote: Seems that these methods should be rooted out from Object, and placed in respective interfaces like: - interface Equatable(T) { bool opEquals(T

Re: Wrong selection of opEquals for objects.

2020-08-28 Thread Simen Kjærås via Digitalmars-d-learn
On Friday, 28 August 2020 at 10:42:09 UTC, Alexandru Ermicioi wrote: No that is not a solution at all, in template code that requires safety. You basically will have to sacrifice safety for rest of types, such as structs, unions & enums for the sake of objects being able to compare. Yup.

Re: Wrong selection of opEquals for objects.

2020-08-28 Thread Simen Kjærås via Digitalmars-d-learn
On Friday, 28 August 2020 at 08:16:01 UTC, Alexandru Ermicioi wrote: Hi everyone, there is https://issues.dlang.org/show_bug.cgi?id=21180 bug, anyone knows how to avoid it? Test case: - import std; class Silly { bool opEquals(const Silly silly) const @safe { return

Re: Can a call to pragma(msg, __FILE__, ...) be mixin templatized?

2020-08-18 Thread Simen Kjærås via Digitalmars-d-learn
On Tuesday, 18 August 2020 at 08:05:20 UTC, Per Nordlöw wrote: On Tuesday, 18 August 2020 at 08:03:04 UTC, Per Nordlöw wrote: Forgot to mention that I want to support variadic arguments to `ctLog` similar to what is done with And these arguments should be of any template argument kind, not

Re: Can a call to pragma(msg, __FILE__, ...) be mixin templatized?

2020-08-17 Thread Simen Kjærås via Digitalmars-d-learn
On Monday, 17 August 2020 at 21:18:41 UTC, Per Nordlöw wrote: I'm using pragma(msg, __FILE__, "(", __LINE__, ",1): Debug: ", "A useful debug message"); to print compile-time information formatted as standard compiler diagnostics. These are picked up by Emacs Flycheck and overlayed in

Re: Template: get function name

2020-08-17 Thread Simen Kjærås via Digitalmars-d-learn
On Monday, 17 August 2020 at 08:07:32 UTC, novice3 wrote: Hello. I have wrapping Windows API functions, wich return 0 on success and erroro code on failure. I copy wenforce template as: ``` private T denforce(T, S)(T value, lazy S msg = null, string file = __FILE__, size_t line = __LINE__)

Re: Cannot call @system funciton (stdout)

2020-08-16 Thread Simen Kjærås via Digitalmars-d-learn
On Saturday, 15 August 2020 at 23:59:36 UTC, Joel wrote: ../../JMiscLib/source/jmisc/base.d(176,2): Error: @safe function jmisc.base.upDateStatus!string.upDateStatus cannot call @system function std.stdio.makeGlobal!"core.stdc.stdio.stdout".makeGlobal

Re: can't access an alias created inside an if statement

2020-08-05 Thread Simen Kjærås via Digitalmars-d-learn
On Wednesday, 5 August 2020 at 09:32:58 UTC, Flade wrote: Thanks! You see it should work but the thing is. I'm using it inside a function. I'm checking for one of the function's parameter (if parameter == false) and it says that "the variable `parameter` cannot be read at compile time. Do you

Re: can't access an alias created inside an if statement

2020-08-05 Thread Simen Kjærås via Digitalmars-d-learn
On Wednesday, 5 August 2020 at 09:05:36 UTC, Flade wrote: I have used an if-else statement to create an alias to avoid code duplication but it doesn't let me access it outside the if statement. Is there a way to solve this? You're probably looking for static if: static if (useAlias) {

Re: miscellaneous array questions...

2020-07-21 Thread Simen Kjærås via Digitalmars-d-learn
On Tuesday, 21 July 2020 at 13:42:15 UTC, Steven Schveighoffer wrote: On 7/21/20 8:34 AM, Adam D. Ruppe wrote: The others aren't wrong about stack size limits playing some role, but the primary reason is that it is a weird hack for @safe, believe it or not. ... I don't recall exactly when

Re: What's the point of static arrays ?

2020-07-10 Thread Simen Kjærås via Digitalmars-d-learn
On Friday, 10 July 2020 at 10:13:23 UTC, wjoe wrote: However stack memory needs to be allocated at program start. I don't see a huge benefit in allocation speed vs. heap pre-allocation, or is there? I mean 1 allocation vs 2 isn't going to noticeably improve overall performance. You seem to

Re: What's the point of static arrays ?

2020-07-09 Thread Simen Kjærås via Digitalmars-d-learn
On Thursday, 9 July 2020 at 12:12:06 UTC, wjoe wrote: I'm not considering supposed performance benefits/penalties because these need to be profiled. Considering the many downsides why would I ever want to choose a static over a dynamic array ? Simply put: static arrays are not dynamic

Re: Progress printing with threads?

2020-07-01 Thread Simen Kjærås 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. Suppose the program is processing a very big file and is iterating the file's bytes using a for loop. The processing takes several minutes and I want a progress

Re: Generating struct members from c structs

2020-07-01 Thread Simen Kjærås via Digitalmars-d-learn
On Wednesday, 1 July 2020 at 07:26:44 UTC, Anthony wrote: When doing interop with a c library, is there a way to automatically generate the fields that are needed for a struct? [snip] Is there an easier way though? Dstep is probably what you're looking for:

Re: scope guard question

2020-07-01 Thread Simen Kjærås via Digitalmars-d-learn
On Tuesday, 30 June 2020 at 12:18:14 UTC, Steven Schveighoffer wrote: I can see where it would be confusing, and it could probably contain an example and clarification. https://issues.dlang.org/show_bug.cgi?id=20997

Re: How to implement Canceleable spawn() from parent

2020-06-30 Thread Simen Kjærås via Digitalmars-d-learn
On Tuesday, 30 June 2020 at 13:44:38 UTC, aberba wrote: On Tuesday, 30 June 2020 at 12:48:32 UTC, Simen Kjærås wrote: On Tuesday, 30 June 2020 at 08:15:54 UTC, aberba wrote: On Tuesday, 30 June 2020 at 00:33:41 UTC, Ali Çehreli wrote: On 6/29/20 4:34 PM, aberba wrote: > So with this, without

Re: How to implement Canceleable spawn() from parent

2020-06-30 Thread Simen Kjærås via Digitalmars-d-learn
On Tuesday, 30 June 2020 at 08:15:54 UTC, aberba wrote: On Tuesday, 30 June 2020 at 00:33:41 UTC, Ali Çehreli wrote: On 6/29/20 4:34 PM, aberba wrote: > So with this, without the Thread.sleep() to block main from exiting, the > spawned thread will terminate immediately. You can call

Re: Unused template arguments; what type to use?

2020-06-26 Thread Simen Kjærås via Digitalmars-d-learn
On Friday, 26 June 2020 at 13:21:25 UTC, drathier wrote: How can I tell the compiler that I will never create a value of type X, while still being able to write code that uses it? Using void as a template parameter is where I started, but I still need to be able to declare variables inside

Re: Flagging special conditions on return from a function call

2020-06-23 Thread Simen Kjærås via Digitalmars-d-learn
On Tuesday, 23 June 2020 at 04:01:45 UTC, Denis wrote: (1) Assign an unused value for the flag (e.g. -1 when the function returns an int), and return the combined value/flag. This happens in some Phobos algorithms, and might be the most common on this list. (2) Return a tuple with the

Re: Parallel array append using std.parallelism?

2020-06-19 Thread Simen Kjærås via Digitalmars-d-learn
On Thursday, 18 June 2020 at 14:43:54 UTC, H. S. Teoh wrote: I have an array of input data that I'm looping over, and, based on some condition, generate new items that are appended onto a target array (which may already contain data). Since the creation of new items is quite expensive, I'm

Re: Should a parser type be a struct or class?

2020-06-17 Thread Simen Kjærås via Digitalmars-d-learn
On Wednesday, 17 June 2020 at 11:50:27 UTC, Per Nordlöw wrote: Should a range-compliant aggregate type realizing a parser be encoded as a struct or class? In dmd `Lexer` and `Parser` are both classes. In general how should I reason about whether an aggregate type should be encoded as a

Re: `this` template params for struct not expressing constness.

2020-06-08 Thread Simen Kjærås via Digitalmars-d-learn
On Monday, 8 June 2020 at 09:08:40 UTC, adnan338 wrote: On Monday, 8 June 2020 at 08:10:19 UTC, Simen Kjærås wrote: On Monday, 8 June 2020 at 07:35:12 UTC, adnan338 wrote: Self* searchTree(this Self)(auto in ref T item) const { if ( is null) return null; if

Re: `this` template params for struct not expressing constness.

2020-06-08 Thread Simen Kjærås via Digitalmars-d-learn
On Monday, 8 June 2020 at 07:35:12 UTC, adnan338 wrote: Self* searchTree(this Self)(auto in ref T item) const { if ( is null) return null; if (this.item == item) return return (this.item < item) ? this.right.searchTree(item) :

Re: how to append (ref) int[] to int[][]?

2020-06-08 Thread Simen Kjærås via Digitalmars-d-learn
On Monday, 8 June 2020 at 06:13:36 UTC, mw wrote: Hi, I have this program: import std.stdio; void f(ref int[] arr) { arr ~= 3; } void main() { int[][] arrs; int[] arr; foreach (i; 0 .. 3) {

Re: Fastest way to check using if identifier has already been defined, using static if or similar?

2020-06-04 Thread Simen Kjærås via Digitalmars-d-learn
On Wednesday, 3 June 2020 at 15:25:51 UTC, Paul Backus wrote: On Wednesday, 3 June 2020 at 13:24:17 UTC, Basile B. wrote: This is because the template parameter must be resolved to a valid symbol or type. This version other version bypass the problem: --- enum Exists(string s) =

Re: Fastest way to check using if identifier has already been defined, using static if or similar?

2020-06-03 Thread Simen Kjærås via Digitalmars-d-learn
On Wednesday, 3 June 2020 at 09:39:34 UTC, Basile B. wrote: You can use this template: enum Exists(alias T) = is(typeof(T)); I don't know if there's a faster way bu this technic is used, notatbly in phobos, to workaroud issues of double declaration in `static foreach` enum Exists(alias

Re: Unable to access a variable declared inside an if statement (Error: is shadowing variable)

2020-05-27 Thread Simen Kjærås via Digitalmars-d-learn
On Wednesday, 27 May 2020 at 11:03:51 UTC, BoQsc wrote: I'm lacking knowledge on how to achieve what I want and getting an error. What is the correct way to do what I tried to achieve in this code? Everything was intuitive until I started to add notice variable to the writeln. Rdmd says

Re: opEquals @safe is ignored

2020-05-24 Thread Simen Kjærås via Digitalmars-d-learn
On Sunday, 24 May 2020 at 08:57:28 UTC, Luis wrote: dmd ignores @trusted or @safe on opEquals, throwing this error : onlineapp.d(27): Error: @safe function onlineapp.__unittest_L24_C7 cannot call @system function object.opEquals An override @system or @trusted function can't be @safe, or I

Re: Assignment of tuples

2020-05-20 Thread Simen Kjærås via Digitalmars-d-learn
On Wednesday, 20 May 2020 at 13:51:05 UTC, Steven Schveighoffer wrote: Please file an issue. https://issues.dlang.org/show_bug.cgi?id=20850 -- Simen

Re: Bug?

2020-05-11 Thread Simen Kjærås via Digitalmars-d-learn
On Monday, 11 May 2020 at 12:44:45 UTC, Jack Applegame wrote: On Monday, 11 May 2020 at 12:30:22 UTC, Adam D. Ruppe wrote: UFCS is only defined to work with global scope functions. A restricted import (module : symbol, symbols) puts things in local scope so ufcs doesn't apply. But in this

Re: What could this be?

2020-05-11 Thread Simen Kjærås via Digitalmars-d-learn
On Monday, 11 May 2020 at 11:20:51 UTC, Joel wrote: I'm gotten stuck with this error - "..is not visible from module.." Without some code it's hard to say exactly, but this generally means you're referencing a private symbol in a different module: module foo; private struct S {} module

Re: How does a free list work?

2020-05-09 Thread Simen Kjærås via Digitalmars-d-learn
On Saturday, 9 May 2020 at 19:54:44 UTC, Pavel Shkadzko wrote: I have been reading about memory management in D on https://wiki.dlang.org/Memory_Management and found an example of a free list (pattern?): "Free lists are a great way to accelerate access to a frequently allocated and discarded

Re: XMM Intrinsics

2020-05-08 Thread Simen Kjærås via Digitalmars-d-learn
On Friday, 8 May 2020 at 13:09:49 UTC, kinke wrote: On Friday, 8 May 2020 at 12:49:00 UTC, Simen Kjærås wrote: How would I go about calling _mm_* functions in D in a way that is portable between D compilers? You would use core.simd: Nope one wouldn't, because that horrible interface isn't

Re: XMM Intrinsics

2020-05-08 Thread Simen Kjærås via Digitalmars-d-learn
On Friday, 8 May 2020 at 12:38:51 UTC, Marcio Martins wrote: Hi, I am building a CRC32C implementation using SSE for D, because I couldn't find any readily available :[ However, I am unable to find any documentation regarding which SSE instructions are available and how I could use them in

Re: Is there a way to benchmark/profile portably?

2020-05-07 Thread Simen Kjærås via Digitalmars-d-learn
On Thursday, 7 May 2020 at 10:21:07 UTC, Dukc wrote: Is there some way to measure the performance of a function so that the results will be same in different computers (all x86, but otherwise different processors)? I'm thinking of making a test suite that could find performance regressions

Re: variant visit not pure?

2020-05-07 Thread Simen Kjærås via Digitalmars-d-learn
On Thursday, 7 May 2020 at 09:22:28 UTC, learner wrote: Good morning, Is there a reason why std.variant.visit is not inferring pure? ``` void test() pure { Algebraic!(int, string) alg; visit!( (string) => 0, (int) => 0)(alg); } Error: pure function test cannot call impure function

Re: Bug?

2020-05-04 Thread Simen Kjærås via Digitalmars-d-learn
On Tuesday, 5 May 2020 at 04:02:06 UTC, RazvanN wrote: truct K { ~this() nothrow {} } void main() { static class C { this(K, int) {} } static int foo(bool flag) { if (flag) throw new Exception("hello"); return 1; } try {

Re: Aliasing current function template instance

2020-05-01 Thread Simen Kjærås via Digitalmars-d-learn
On Friday, 1 May 2020 at 20:28:58 UTC, Jean-Louis Leroy wrote: Is it possible, inside a function template, to create an alias to the instantiated function? IOW the equivalent of __FUNCTION__, but yielding an alias? The closest I came is: import std.string; import std.traits; void

Re: Can't recreate a range?

2020-04-30 Thread Simen Kjærås via Digitalmars-d-learn
On Thursday, 30 April 2020 at 13:23:25 UTC, Paul Backus wrote: On Thursday, 30 April 2020 at 13:04:47 UTC, Casey wrote: Here's a minimal code example that duplicates the issue: import std.array, std.range, std.stdio, std.traits, std.string; auto readStream(Range)(auto ref Range r) if

Re: Can't recreate a range?

2020-04-29 Thread Simen Kjærås via Digitalmars-d-learn
On Wednesday, 29 April 2020 at 20:43:20 UTC, Casey wrote: void popFront() { } I mean, it might be you messed up in posting this, but having an empty popFront and expecting it to do something is a tad optimistic. Apart from that, it seems like

Re: Can’t use UFCS to create InputRange?

2020-04-29 Thread Simen Kjærås via Digitalmars-d-learn
On Wednesday, 29 April 2020 at 09:16:58 UTC, user1234 wrote: The static checker doesn't see your free funcs because to do so it would have to import the whole module. (is it possible to do that ? no idea.) Of course it's possible! :) We can find the context of R (in this case, the module)

Re: Can’t use UFCS to create InputRange?

2020-04-29 Thread Simen Kjærås via Digitalmars-d-learn
On Wednesday, 29 April 2020 at 08:34:53 UTC, Ogi wrote: struct R {} int front(R r) { return 42; } void popFront(R r) {} bool empty(R r) { return false; } void main() { import std.range.primitives : isInputRange; static assert(isInputRange!R); } Error: static assert:

Re: How convert String to Hex?

2020-04-18 Thread Simen Kjærås via Digitalmars-d-learn
On Saturday, 18 April 2020 at 15:47:38 UTC, Marcone wrote: How convert String to Hex? Example: string text = "Hello World"; // Converted to Hex = 48656c6c6f20576f726c64 import std.format : format; string hex = format("%(%2x%)", "Hello World"); import std.stdio : writeln;

Re: Extracting user defined attributes on function parameters

2020-04-18 Thread Simen Kjærås via Digitalmars-d-learn
On Saturday, 18 April 2020 at 09:19:48 UTC, Simen Kjærås wrote: On Wednesday, Friday, 17 Apr 2020 17:45:47 UTC, H. S. Teoh wrote: I wonder if the ultimate cause of the above case is ultimately caused by the change to import semantics that hid private symbols from outside the module. Perhaps

Re: Extracting user defined attributes on function parameters

2020-04-18 Thread Simen Kjærås via Digitalmars-d-learn
On Wednesday, Friday, 17 Apr 2020 17:45:47 UTC, H. S. Teoh wrote: I wonder if the ultimate cause of the above case is ultimately caused by the change to import semantics that hid private symbols from outside the module. Perhaps something, somewhere, is triggering an illegal access of a

Re: Extracting user defined attributes on function parameters

2020-04-17 Thread Simen Kjærås via Digitalmars-d-learn
On Friday, 17 April 2020 at 16:54:42 UTC, Adam D. Ruppe wrote: This part seems fine... pragma(msg, ParameterDefaults!f.stringof); It is this, specifically, that causes the problem. Replace it with: void main() { import std.stdio; writeln(ParameterDefaults!f.stringof); }

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

2020-04-17 Thread Simen Kjærås via Digitalmars-d-learn
On Friday, 17 April 2020 at 08:59:19 UTC, kdevel wrote: 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;

Re: Find the heir.

2020-03-29 Thread Simen Kjærås via Digitalmars-d-learn
On Sunday, 29 March 2020 at 14:04:53 UTC, TodNaz wrote: Hello! class A { ... } class B : A { ... } class C : A { ... } A example1; B example2 = new B(...); A = example2; auto heir = A.whoheir(); /// The question in this code is: is it possible to track the class inheritor? Or is

Re: Get symbols (and/or UDAs) of subclass from superclass

2020-03-15 Thread Simen Kjærås via Digitalmars-d-learn
On Sunday, 15 March 2020 at 20:18:03 UTC, James Blachly wrote: I would like to programmatically retrieve members of a subclass to create a self-documenting interface. I am afraid that my approach is not possible due to need for compile time __traits / std.traits, and runtime typeinfo. My

Re: A set type implemented as an AA wrapper

2020-03-12 Thread Simen Kjærås via Digitalmars-d-learn
On Thursday, 12 March 2020 at 08:51:24 UTC, mark wrote: I use sets a lot and since I believe that D's rbtree is O(lg n) for add/remove/in and that D's AA is O(1) for these, I want to implement a set in terms of an AA. Below is the code I've got so far. It allows for add and remove. However,

Re: Aliases to mutable thread-local data not allowed [testable source code]

2020-03-11 Thread Simen Kjærås via Digitalmars-d-learn
On Wednesday, 11 March 2020 at 12:43:28 UTC, mark wrote: On Wednesday, 11 March 2020 at 12:22:21 UTC, Simen Kjærås wrote: On Wednesday, 11 March 2020 at 09:29:54 UTC, mark wrote: [snip] Fascinating. It works just fine when compiling for 32-bit targets with DMD on Windows, but not for 64-bit

Re: Aliases to mutable thread-local data not allowed [testable source code]

2020-03-11 Thread Simen Kjærås via Digitalmars-d-learn
On Wednesday, 11 March 2020 at 09:29:54 UTC, mark wrote: Hi Simen, I think you must have done something else but didn't mention to get it to compile. I did the exact changes you said and it wouldn't compile. Here's what I get with changes mentioned below (with new full source):

Re: Aliases to mutable thread-local data not allowed [testable source code]

2020-03-11 Thread Simen Kjærås via Digitalmars-d-learn
On Tuesday, 10 March 2020 at 20:03:21 UTC, mark wrote: I've managed to make a cut-down version that's < 170 LOC. It needs to be run on Debian or a Debian-based Linux (e.g., Ubuntu). Hopefully this will help someone understand and be able to help! This took some time figuring out. Turns out,

Re: Aliases to mutable thread-local data not allowed

2020-03-10 Thread Simen Kjærås via Digitalmars-d-learn
On Tuesday, 10 March 2020 at 08:13:19 UTC, mark wrote: I have this struct: struct Deb { string name; ... Unit[string] tags; // set of tags Deb dup() const { Deb deb; deb.name = name; ... foreach (key; tags.byKey) deb.tags[key] = unit;

Re: @property with opCall

2020-03-09 Thread Simen Kjærås via Digitalmars-d-learn
On Monday, 9 March 2020 at 09:25:31 UTC, Calvin P wrote: Is this a bugs ? == struct A { ref auto opCall(string tmp) scope return { return this; } } struct B { A _a; @property ref auto a() scope return { return _a;

Re: Idiomatic way to express errors without resorting to exceptions

2020-03-09 Thread Simen Kjærås via Digitalmars-d-learn
On Saturday, 7 March 2020 at 15:44:38 UTC, Arine wrote: The case when there isn't a value should be handled explicitly, not implicitly. Propogating a None value isn't useful Except when it is useful, and shouldn't be handled explicitly. I have code in D, C and C++ that looks like this:

Re: What does assigning void mean?

2020-03-05 Thread Simen Kjærås via Digitalmars-d-learn
On Thursday, 5 March 2020 at 08:35:52 UTC, drug wrote: On 3/5/20 10:47 AM, mark wrote: In Adam Ruppe's D Cookbook there're these lines in a ref counting example: RefCountedObject o = void; // What does this mean/do? o.data = new Implementation(); o.data.refcount = 1; I don't understand the

Re: Call method if declared only

2020-02-28 Thread Simen Kjærås via Digitalmars-d-learn
On Friday, 28 February 2020 at 10:33:11 UTC, Виталий Фадеев wrote: Thanks all ! I happy ! Check this one: void On( T, M )( T o, M message ) { [snip] void main() { auto a = new A(); a.Send( a, WM_KEYUP ); a.Send( a, WM_KEYDOWN ); } That does mostly

Re: Call method if declared only

2020-02-28 Thread Simen Kjærås via Digitalmars-d-learn
On Friday, 28 February 2020 at 09:25:58 UTC, Виталий Фадеев wrote: Yes. Thank ! I read it. Problem is - OS has many messages + user messages... It mean what interfaces like IKeyDown must me declared. All. Dream on write less code... So let's create a template for that: interface

Re: Call method if declared only

2020-02-28 Thread Simen Kjærås via Digitalmars-d-learn
On Friday, 28 February 2020 at 06:12:37 UTC, Виталий Фадеев wrote: Searching solution for idea ! For whatever reason, it seems my attempts at answering this earlier has disappeared into the void. Here: import core.sys.windows.windows; import std.stdio; class Base { LRESULT On(UINT

Re: Call method if declared only

2020-02-28 Thread Simen Kjærås via Digitalmars-d-learn
On Friday, 28 February 2020 at 08:08:59 UTC, Виталий Фадеев wrote: On Friday, 28 February 2020 at 06:12:37 UTC, Виталий Фадеев wrote: Searching solution for idea ! Goal is to get System message, dispatch/route to method ! If method implemented only ! I dream on in future write clean code of a

Re: How to copy const object?

2020-02-27 Thread Simen Kjærås via Digitalmars-d-learn
On Thursday, 27 February 2020 at 11:28:11 UTC, Mitacha wrote: I've a const struct object and I'd like to make a mutable copy of it. Struct definition contains string and an array of structs. ``` struct A { string a; B[] b; } struct B { string a; string b; } ``` As far as I can

Re: String switch is odd using betterC

2020-02-26 Thread Simen Kjærås via Digitalmars-d-learn
On Wednesday, 26 February 2020 at 08:32:50 UTC, Abby wrote: On Wednesday, 26 February 2020 at 08:25:00 UTC, Abby wrote: Any idea why? Ok so this is enough to produce the same result, it seems that there is a problem in string switch when there is more the 6 cases. extern(C) void main() {

Re: Alternative to friend functions?

2020-02-18 Thread Simen Kjærås via Digitalmars-d-learn
On Tuesday, 18 February 2020 at 12:43:22 UTC, Adnan wrote: class Wife(uint N) : Female { FemaleID engagedTo = -1; const MaleID[N] preferences; this(MaleID[N] preferences) { this.preferences = preferences; } } void engage(N)(ref Wife!N, wife, ref Husband!N husband) {

Re: How to declare a virtual member (not a function) in a class

2020-02-18 Thread Simen Kjærås via Digitalmars-d-learn
On Tuesday, 18 February 2020 at 12:37:45 UTC, Adnan wrote: I have a base class that has a couple of constant member variables. These variables are abstract, they will only get defined when the derived class gets constructed. class Person { const string name; const int id; } class

Re: Why can't I pass a const array to a function that takes scope const arrays?

2020-02-17 Thread Simen Kjærås via Digitalmars-d-learn
On Monday, 17 February 2020 at 14:04:34 UTC, Adnan wrote: cdsa ~master: building configuration "cdsa-test-library"... source/strassens_matmul.d(22,16): Error: cannot implicitly convert expression [row][column] of type const(uint)* to uint* source/strassens_matmul.d(37,36): Error: template

Re: operator overload for sh-like scripting ?

2020-02-17 Thread Simen Kjærås via Digitalmars-d-learn
On Monday, 17 February 2020 at 13:03:38 UTC, Basile B. wrote: eg Sh(echo) < "meh"; struct Sh { // you see the idea we have op overload for < here } You can't overload < separately - all the comparison operators (<, <=, >, >=) are handled via opCmp. Even if you choose to go down

Re: From [Tuple!(A,B), ...] to Tuple!(A[], B[])

2020-02-17 Thread Simen Kjærås via Digitalmars-d-learn
On Monday, 17 February 2020 at 11:51:52 UTC, FeepingCreature wrote: Here you go: import std; // extract the types that make up the tuple auto transposeTuple(T : Tuple!Types[], Types...)(T tuples) { // templated function that extracts the ith field of an array of tuples as an array

Re: From [Tuple!(A,B), ...] to Tuple!(A[], B[])

2020-02-17 Thread Simen Kjærås via Digitalmars-d-learn
On Monday, 17 February 2020 at 11:51:52 UTC, FeepingCreature wrote: On Monday, 17 February 2020 at 11:07:33 UTC, foozzer wrote: Hi all, There's something in Phobos for that? Thank you Here you go: import std; // extract the types that make up the tuple auto transposeTuple(T :

Re: From [Tuple!(A,B), ...] to Tuple!(A[], B[])

2020-02-17 Thread Simen Kjærås via Digitalmars-d-learn
On Monday, 17 February 2020 at 11:07:33 UTC, foozzer wrote: Hi all, There's something in Phobos for that? Thank you import std.meta : staticMap; import std.typecons : Tuple; // Turn types into arrays alias ToArray(T) = T[]; // Leave everything else the same alias ToArray(T...) = T; // Now

Re: Global version/debug statements in file?

2020-02-12 Thread Simen Kjærås via Digitalmars-d-learn
On Wednesday, 12 February 2020 at 08:44:24 UTC, cc wrote: Is there some way to globally declare version= or debug= statements in a file and have them apply to the entire project being compiled? As the documentation says these only apply to the module scope they exist in, and need to be added

Re: Custom separator in array format

2020-01-28 Thread Simen Kjærås via Digitalmars-d-learn
On Tuesday, 28 January 2020 at 07:36:25 UTC, Malte wrote: I want to format an array using the %(...%) syntax. How can I change the separator? I tried to use ? and add it as additional parameter, but that doesn't seem to work on arrays: import std; void main() { writeln("This works:");

Re: @disable("reason")

2020-01-08 Thread Simen Kjærås via Digitalmars-d-learn
On Wednesday, 8 January 2020 at 07:03:26 UTC, Jonathan M Davis wrote: you could just document that no one should ever use its init value explicitly, and that they will have bugs if they do You also create a static init member marked @disable: struct S { @disable this(); @disable

Re: @disable("reason")

2020-01-08 Thread Simen Kjærås via Digitalmars-d-learn
On Wednesday, 8 January 2020 at 08:26:51 UTC, user1234 wrote: class Example { @disable this() { pragma(msg, "not allowed..."); } } void main() { new Example(); } outputs: not allowed... /tmp/temp_7F8C65489550.d(12,5): Error: constructor `runnable.Example.this` cannot be used because

Re: Should I stop being interested in D language if I don't like to see template instantiation in my code?

2019-11-14 Thread Simen Kjærås via Digitalmars-d-learn
On Thursday, 14 November 2019 at 09:30:23 UTC, user9876 wrote: A good thing is that in many cases the template instance parameters can be deduced from the arguments used: --- import std; void main() { assert(max(0,1) == 1); // same as assert(max!(int,int)(0,1) == 1); } --- This

  1   2   3   4   >