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

2021-12-23 Thread rumbu 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. Replace: 436 msecs Malloc : 259 msecs */ It seems because MallocReplace is cheating a lot: - it is not called through another function l

Re: what the closest thing we have to racket's check_expect()?

2021-12-22 Thread Rumbu via Digitalmars-d-learn
On Wednesday, 22 December 2021 at 20:14:01 UTC, Dr Machine Code wrote: it differ from assert because it contains the expression, file and line information. See this https://stackoverflow.com/questions/14420857/check-expect-example-in-racket what's the closest thing we have in D? can we make it w

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

2021-12-20 Thread rumbu via Digitalmars-d-learn
On Monday, 20 December 2021 at 10:49:20 UTC, rempas wrote: On Monday, 20 December 2021 at 09:30:30 UTC, rumbu wrote: Thanks a lot for the info. When I try to use this code, I'm getting the following error: ``` Error: expression expected, not `%` Error: expression expected, not `%` ``` My fa

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

2021-12-20 Thread rumbu via Digitalmars-d-learn
On Monday, 20 December 2021 at 08:45:50 UTC, rempas wrote: Here I am having a problem with templates again. No matter how much I read, I can't seem to understand how templates/mixins work. So any ideas why this doesn't work? because you cannot have statements directly in a template (the fac

Re: Immutability and arrays

2021-12-14 Thread rumbu via Digitalmars-d-learn
On Tuesday, 14 December 2021 at 16:21:03 UTC, Steven Schveighoffer wrote: On 12/14/21 11:19 AM, Steven Schveighoffer wrote: Er... scratch that, this isn't construction, it should use opAssign. Again, probably because memcpy+postblit is used by the runtime. If not reported, it should be. Si

Re: Immutability and arrays

2021-12-14 Thread rumbu via Digitalmars-d-learn
On Tuesday, 14 December 2021 at 12:13:23 UTC, Stanislav Blinov wrote: Because is(typeof(immutable(ComplexStruct).x) == immutable(int[])). Can't bind an array of immutable to array of mutable. This would require a deep copy, i.e. copy constructor. This means that the only way to write a gener

Immutability and arrays

2021-12-14 Thread rumbu via Digitalmars-d-learn
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; immutable(SimpleStruct)[] ibuf1; buf1[0 .. 10] = ibuf1[0 .. 10

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

2021-12-11 Thread Rumbu via Digitalmars-d-learn
On Saturday, 11 December 2021 at 14:42:53 UTC, russhy wrote: Here is mine - 0 allocations - configurable - let's you use it how you wish - fast You know that this is already in phobos? ``` "abc;def;ghi".splitter(';').joiner ```

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

2021-12-10 Thread Rumbu via Digitalmars-d-learn
On Friday, 10 December 2021 at 18:47:53 UTC, Stanislav Blinov wrote: Be interesting to see if this thread does evolve into a SIMD http://lemire.me/blog/2017/01/20/how-quickly-can-you-remove-spaces-from-a-string/

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

2021-12-10 Thread Rumbu via Digitalmars-d-learn
On Friday, 10 December 2021 at 11:06:21 UTC, IGotD- wrote: On Friday, 10 December 2021 at 06:24:27 UTC, Rumbu wrote: Since it seems there is a contest here: ```d "abc;def;ghi".split(';').join(); ``` :) Would that become two for loops or not? I thought it's a beauty contest. ```d string

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

2021-12-09 Thread Rumbu via Digitalmars-d-learn
On Wednesday, 8 December 2021 at 11:23:45 UTC, BoQsc wrote: Let's say I want to skip characters and build a new string. The character I want to skip: `;` Expected result: ``` abcdefab ``` Since it seems there is a contest here: ```d "abc;def;ghi".split(';').join(); ``` :)

Re: Mixin template overloads not working

2021-12-07 Thread Rumbu via Digitalmars-d-learn
On Friday, 3 December 2021 at 10:57:34 UTC, Stanislav Blinov wrote: 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 hid

Mixin template overloads not working

2021-12-03 Thread Rumbu via Digitalmars-d-learn
```d class S {} class A:S {} class B:S {} mixin template vmix(T) {    void visit(T t) {} } class Visitor {    void visit(S s) {}    mixin vmix!A;    mixin vmix!B; } class AnotherVisitor: Visitor {    override void visit(A a) {} } ``` This will result in error when I try to override mixin

Re: Attributes (lexical)

2021-11-25 Thread rumbu via Digitalmars-d-learn
On Thursday, 25 November 2021 at 11:25:49 UTC, Ola Fosheim Grøstad wrote: On Thursday, 25 November 2021 at 10:41:05 UTC, Rumbu wrote: I am not asking this questions out of thin air, I am trying to write a conforming lexer and this is one of the ambiguities. I think it is easier to just look at

Re: Attributes (lexical)

2021-11-25 Thread Rumbu via Digitalmars-d-learn
On Thursday, 25 November 2021 at 10:10:25 UTC, Dennis wrote: On Thursday, 25 November 2021 at 08:06:27 UTC, rumbu wrote: Also, this works also for #line, even if the specification tells us that all tokens must be on the same line Where does it say that? Well: ``` #line IntegerLiteral Filesp

Attributes (lexical)

2021-11-25 Thread rumbu via Digitalmars-d-learn
Just playing around with attributes. This is valid D code: ```d @ nogc: //yes, this is @nogc in fact, even some lines are between @ /* i can put some comments */ /** even some documentation */ // single line comments also (12) // yes, comments and newlines are allowed between attribute

Re: Using YMM registers causes an undefined label error

2021-03-06 Thread Rumbu via Digitalmars-d-learn
On Saturday, 6 March 2021 at 12:15:43 UTC, Mike Parker wrote: On Saturday, 6 March 2021 at 11:57:13 UTC, Imperatorn wrote: What... Is this really how it's supposed to be? Makes no sense to not use any of the existing conventions. extern(C) and extern(D) are both documented to be the same as

Re: Using YMM registers causes an undefined label error

2021-03-06 Thread Rumbu via Digitalmars-d-learn
On Friday, 5 March 2021 at 21:47:49 UTC, z wrote: On Friday, 5 March 2021 at 16:10:02 UTC, Rumbu wrote: First of all, in 64 bit ABI, parameters are not passed on stack, therefore a[RBP] is a nonsense. void complement32(simdbytes* a, simdbytes* b) a is in RCX, b is in RDX on Windows a is in RD

Re: Using YMM registers causes an undefined label error

2021-03-05 Thread Rumbu via Digitalmars-d-learn
On Friday, 5 March 2021 at 12:57:43 UTC, z wrote: XMM registers work, but as soon as they are changed into YMM DMD outputs "bad type/size of operands %s" and LDC outputs an "label YMM0 is undefined" error. Are they not supported? To illutrate : https://run.dlang.io/is/IqDHlK By the way, how ca

Re: How can I make this work?

2021-02-28 Thread Rumbu via Digitalmars-d-learn
On Sunday, 28 February 2021 at 09:04:49 UTC, Rumbu wrote: On Sunday, 28 February 2021 at 07:05:27 UTC, Jack wrote: I'm using a windows callback function where the user-defined value is passed thought a LPARAM argument type. I'd like to pass my D array then access it from that callback function.

Re: How can I make this work?

2021-02-28 Thread Rumbu via Digitalmars-d-learn
On Sunday, 28 February 2021 at 07:05:27 UTC, Jack wrote: I'm using a windows callback function where the user-defined value is passed thought a LPARAM argument type. I'd like to pass my D array then access it from that callback function. How is the casting from LPARAM to my type array done in t

Re: fold on empty range

2021-02-17 Thread Rumbu via Digitalmars-d-learn
On Wednesday, 17 February 2021 at 12:58:29 UTC, Mitacha wrote: On Wednesday, 17 February 2021 at 11:38:45 UTC, Rumbu wrote: [...] If you replace `fold` and `splitter` with this, then it doesn't allocate: ``` auto fn() @nogc { return only("k1,k2", "k3,k4") .map!(x => x.splitter(",

Re: fold on empty range

2021-02-17 Thread Rumbu via Digitalmars-d-learn
On Wednesday, 17 February 2021 at 10:15:10 UTC, Mitacha wrote: it'll use empty string as first element in range. BTW perheps you could use `joinner` instead of this `fold` to join values with ",". Thanks for that. I thought to joiner too, but it doesn't work. I need fold to take a list of s

fold on empty range

2021-02-17 Thread Rumbu via Digitalmars-d-learn
In the expression below: return matchAll(content, keywordsPattern) .map!(a => a.hit.stripLeft("[").strip("]")) .fold!((a, b) => a ~ "," ~ b) .splitter(',') .map!(a => a.stripLeft("\" ").strip("\" ")) .filter!(a => !a.any!(b => b == ' ' |

Re: Is there other way to do that?

2021-02-15 Thread Rumbu via Digitalmars-d-learn
On Monday, 15 February 2021 at 07:26:56 UTC, Jack wrote: I need to check if an instance is of a specific type derived from my base class but this class has template parameter and this type isn't available at time I'm checking it. Something like: class B { } class A(T) : B { } class X : B { }

Re: Is this the proper way to do it?

2021-02-13 Thread Rumbu via Digitalmars-d-learn
On Saturday, 13 February 2021 at 05:52:34 UTC, Jack wrote: I have a base class A, where I make specific operator depending on the derived class type. Currently I'm using something like this: c is a class derived from A bool shouldDoX = (cast(X)c) !is null || (cast(Y)c) !is null || (cast(K)c)

Re: Real simple unresolved external symbols question...

2021-02-10 Thread Rumbu via Digitalmars-d-learn
On Tuesday, 9 February 2021 at 19:37:17 UTC, WhatMeWorry wrote: I'm trying to create a super simple dynamic library consisting of two files: file2.d -- extern(D): double addEight(double d) { return (d + 8.0); } fileB.d -

Re: Dimensions in compile time

2021-02-08 Thread Rumbu via Digitalmars-d-learn
On Monday, 8 February 2021 at 12:19:26 UTC, Basile B. wrote: On Monday, 8 February 2021 at 11:42:45 UTC, Vindex wrote: size_t ndim(A)(A arr) { return std.algorithm.count(typeid(A).to!string, '['); } Is there a way to find out the number of dimensions in an array at compile time? yeah. -

Re: Finding position of a value in an array

2021-02-06 Thread Rumbu via Digitalmars-d-learn
On Sunday, 29 December 2019 at 08:26:58 UTC, Daren Scot Wilson wrote: Reading documentation... Array, Algorithms, ... maybe I've been up too late... how does one obtain the index of, say, 55 in an array like this int[] a = [77,66,55,44]; I want to do something like: int i = a.find_va

Re: Ugly c++ syntax

2021-02-06 Thread Rumbu via Digitalmars-d-learn
On Saturday, 6 February 2021 at 00:35:12 UTC, Ali Çehreli wrote: On 2/5/21 1:10 PM, Rumbu wrote: I gave up after reading a lot, but I didn't manage to understand the meaning "&& ..." I think it's the universal reference. Thank you Ali, but nope, it's "parameter pack folding". This allows s

Ugly c++ syntax

2021-02-05 Thread Rumbu via Digitalmars-d-learn
Can some C++ guru translate in D the template below? I gave up after reading a lot, but I didn't manage to understand the meaning "&& ..." template static uint8_t composite_index_size(Tables const&... tables) { return (composite_index_size(tables.size(), impl::bits_needed(sizeof...(tables)

Re: books for learning D

2020-01-29 Thread rumbu via Digitalmars-d-learn
On Wednesday, 29 January 2020 at 08:40:48 UTC, p.shkadzko wrote: Has anyone read "d programming language tutorial: A Step By Step Appoach: Learn d programming language Fast"? https://www.goodreads.com/book/show/38328553-d-programming-language-tutorial?from_search=true&qid=G9QIeXioOJ&rank=3 Be

Re: How to convert this C++ code to Dlang? Please send me Dlang version of this C++ code

2020-01-27 Thread rumbu via Digitalmars-d-learn
On Monday, 27 January 2020 at 11:34:47 UTC, Marcone wrote: #include #include #include #include "resource.h" #include HINSTANCE hInst; BOOL CALLBACK DlgMain(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch(uMsg) { case WM_INITDIALOG: { } return TRUE;

Re: How load icon from resource using LoadImage?

2020-01-05 Thread Rumbu via Digitalmars-d-learn
On Sunday, 5 January 2020 at 13:33:35 UTC, Marcone wrote: I am using this code to load icon from local directory, but I want to load icon from resource.res file: wndclass.hIcon = LoadImage( NULL, "icon.ico", IMAGE_ICON, 0, 0, LR_LOADFROMFILE| LR_SHARED | LR_LOADTRANSPARENT); You cannot load

array of functions/delegates

2019-12-23 Thread Rumbu via Digitalmars-d-learn
I am trying to create an array of functions inside a struct. struct S { void f1() {} void f2() {} alias Func = void function(); immutable Func[2] = [&f1, &f2] } What I got: Error: non-constant expression '&f1' Tried also with delegates (since I am in a struct context but I got: no `t

Re: How add "version.txt" Version File by Command Line or by resources.res using dmd.exe

2019-12-09 Thread rumbu via Digitalmars-d-learn
On Sunday, 8 December 2019 at 20:50:05 UTC, Marcone wrote: I want to add version to my program. I have configurated my version file "version.txt", but I dont know how link this file to my program. If Need spec file, please send the exemple code of spec. Or is is possible add version file by d

Re: why local variables cannot be ref?

2019-11-25 Thread rumbu via Digitalmars-d-learn
On Monday, 25 November 2019 at 08:20:59 UTC, rumbu wrote: On Monday, 25 November 2019 at 08:07:50 UTC, Fanda Vacek wrote: Thanks for answer, I'm coming from C++. But anyway, pointers are not allowed in @safe code, so this is not always solution. Workaround exits even for @safe code, so my ques

Re: why local variables cannot be ref?

2019-11-25 Thread rumbu via Digitalmars-d-learn
On Monday, 25 November 2019 at 08:07:50 UTC, Fanda Vacek wrote: Thanks for answer, I'm coming from C++. But anyway, pointers are not allowed in @safe code, so this is not always solution. Workaround exits even for @safe code, so my question remains the same. What is a rationale for such a lang

Re: why local variables cannot be ref?

2019-11-24 Thread Rumbu via Digitalmars-d-learn
On Monday, 25 November 2019 at 03:07:08 UTC, Fanda Vacek wrote: Maybe I'm missing the thing, but I'm not able to declare local ref variable even if simple workaround exists. Is this preferred design pattern? ``` int main() { int a = 1; //ref int b = a; // Error: variable `tst_ref.main

Re: Proper desctructor for an class containing dynamic array of objects

2019-06-14 Thread rumbu via Digitalmars-d-learn
On Friday, 14 June 2019 at 07:52:24 UTC, Marco de Wild wrote: On Thursday, 13 June 2019 at 16:08:52 UTC, Mike wrote: Opposed to Java, D's member variables are static initialised. Is there any documentation about this? I find it unexpected.

Re: Proper desctructor for an class containing dynamic array of objects

2019-06-13 Thread Rumbu via Digitalmars-d-learn
On Thursday, 13 June 2019 at 16:08:52 UTC, Mike wrote: How would a proper destructor of class Foo look like? Is it enough to set "array" to null? Or do I have to set every element of the array to null and then the array, or nothing of that at all because the garbage collecter collects it, if th

Re: Casting to interface not allowed in @safe code?

2019-05-21 Thread rumbu via Digitalmars-d-learn
On Tuesday, 21 May 2019 at 07:16:49 UTC, Jim wrote: On Tuesday, 21 May 2019 at 07:04:27 UTC, rumbu wrote: On Tuesday, 21 May 2019 at 05:51:30 UTC, Jim wrote: That's because foo is of type Base, not implementing FeatureX. Right, Base isn't implementing FeatureX, but foo is really a Foo That'

Re: Casting to interface not allowed in @safe code?

2019-05-21 Thread rumbu via Digitalmars-d-learn
On Tuesday, 21 May 2019 at 05:51:30 UTC, Jim wrote: Hi, consider this: interface Base { void setup(); } interface FeatureX { void x(); } class Foo: Base, FeatureX { void setup(){}; void x(){}; } void main() { Base foo = new Foo(); // This would be the result of a factory class

Re: [windows] Can't delete a closed file?

2019-05-10 Thread Rumbu via Digitalmars-d-learn
On Friday, 10 May 2019 at 19:10:05 UTC, Machine Code wrote: Well, I've had similar issue. The error message says "access denied" which I believe refers to the tmp directory; i.e, the user that is running your executable has no permissions to delete that file. Well, this has nothing to do with

Re: [windows] Can't delete a closed file?

2019-05-09 Thread Rumbu via Digitalmars-d-learn
On Thursday, 9 May 2019 at 10:09:23 UTC, Cym13 wrote: Hi, this is likely not related to D itself but hopefully someone can help me with this since I'm rather new to windows programming, I mainly work on linux. I'm trying to bundle a DLL in a binary, write it in a temp folder, use it and remov

Re: Idiomatic error handling for ranges

2018-04-05 Thread rumbu via Digitalmars-d-learn
On Thursday, 5 April 2018 at 17:36:56 UTC, Seb wrote: On Thursday, 5 April 2018 at 17:06:04 UTC, rumbu wrote: Is there a standard way to handle errors in a chain of range transformations? [...] Are you aware of ifThrown? https://dlang.org/phobos/std_exception.html#ifThrown It's not perfect

Idiomatic error handling for ranges

2018-04-05 Thread rumbu via Digitalmars-d-learn
Is there a standard way to handle errors in a chain of range transformations? Let's say I want to read some comma separated numbers from a file. auto myArray = file.byLine().splitter().map!(to!int).array(); Now, besides fatal errors (like I/O), let's suppose I want to handle some errors in a

Re: Help with specific template function

2018-03-25 Thread rumbu via Digitalmars-d-learn
On Monday, 26 March 2018 at 06:40:34 UTC, Vladimirs Nordholm wrote: However I do not understand how to use that with my arguments. Eg. I would expect to do something like: void foo(X, Y, Args...)(X x, Y y, Args args) if(isNumeric!(x) && isNumeric!(y) && args.length >= 1) {

Re: Calling Windows Command

2018-03-21 Thread rumbu via Digitalmars-d-learn
On Wednesday, 21 March 2018 at 18:50:38 UTC, Vino wrote: Hi All, Request your help in calling the windows command to delete all file and folders recursively as the D function rmdirRecurse does not delete file in the permission of the file is readonly in windows 2008 R2 import std.process:

Template condition evaluation (shortcircuit)

2018-03-21 Thread rumbu via Digitalmars-d-learn
I tried to define a template: enum isFoo(alias T) = T.stringof.length >= 3 && T.stringof[0..3] == "abc"; int i; pragma(msg, isFoo!i); Error: string slice [0 .. 3] is out of bounds Error: template object.__equals cannot deduce function from argument types !()(string, string), candidates are

Re: Slow start up time of runtime (correction: Windows real-time protection)

2018-03-20 Thread rumbu via Digitalmars-d-learn
On Tuesday, 20 March 2018 at 16:56:59 UTC, Dennis wrote: On Tuesday, 20 March 2018 at 12:18:16 UTC, Adam D. Ruppe wrote: On Tuesday, 20 March 2018 at 09:44:41 UTC, Dennis wrote: I suspect you are seeing the Windows antivirus hitting you. D runtime starts up in a tiny fraction of a second, you

Re: Is there a way to pipeline program with random-access ranges in C#?

2018-03-19 Thread rumbu via Digitalmars-d-learn
On Monday, 19 March 2018 at 11:35:46 UTC, Dukc wrote: This topic is technically in wrong place, since the problem is with C#, not D. But because what I'm asking is more idiomatic in D than elsewhere, I think I have the best changes to get understood here. So, I'm looking for some library, or

Re: signbit question

2018-03-15 Thread rumbu via Digitalmars-d-learn
On Thursday, 15 March 2018 at 17:18:08 UTC, Miguel L wrote: On Thursday, 15 March 2018 at 16:31:56 UTC, Stefan Koch wrote: On Thursday, 15 March 2018 at 15:28:16 UTC, Miguel L wrote: Why does std.math.signbit only work for floating point types? Is there an analogue function for integer types? w

Re: Are there any working instructions about how to build and test dmd on Windows?

2018-03-14 Thread rumbu via Digitalmars-d-learn
On Wednesday, 14 March 2018 at 00:43:52 UTC, Rubn wrote: Yah it's not fun. Some notes: You might need to set MSVC_CC environment variable cause it doesn't use the right format for VS path, depending on your version. https://github.com/dlang/dmd/blob/v2.079.0/src/vcbuild/msvc-dmc.d#L19 You

Are there any working instructions about how to build and test dmd on Windows?

2018-03-13 Thread rumbu via Digitalmars-d-learn
I know that there are contributing guides but I fail to successfully follow any of them: https://wiki.dlang.org/Starting_as_a_Contributor 1. Bash install script will not run under Windows. Using git bash will result in error (Command error: undefined switch '-C') 2. Digger it's not compiling

Re: How to simplify nested ifs

2018-03-13 Thread rumbu via Digitalmars-d-learn
On Tuesday, 13 March 2018 at 12:23:06 UTC, Ozan Süel wrote: Hi I have a construction like the following if (source) { if (source.pool) { if (source.pool.repository) { if (source.pool.repository.directory) { if (source.pool.repository.directory.users) { // do someth

Re: iota to array

2018-02-25 Thread rumbu via Digitalmars-d-learn
On Sunday, 25 February 2018 at 13:33:07 UTC, psychoticRabbit wrote: can someone please design a language that does what I tell it! please!! is that so hard?? print 1.0 does not mean go and print 1 .. it means go and print 1.0 languages are too much like people.. always thinking for themsel

Re: iota to array

2018-02-25 Thread rumbu via Digitalmars-d-learn
On Sunday, 25 February 2018 at 08:08:30 UTC, psychoticRabbit wrote: But umm what happended to the principle of least astonishment? writeln(1.1); (prints 1.1) whereas.. writeln(1.0); (prints 1) I don't get it. Cause it's 'nicer'?? Because writeln(someFloat) is equivalent to writefln("

Re: opCast cannot implicitly convert a.opCast of type X to Y

2018-02-12 Thread rumbu via Digitalmars-d-learn
On Monday, 12 February 2018 at 02:05:16 UTC, aliak wrote: From spec: Cast expression: "cast ( Type ) UnaryExpression" converts UnaryExpresssion to Type. And https://dlang.org/spec/operatoroverloading.html#cast makes no mention of the return type of opCast. One could think that the return type

Re: opUnary with ++ and -- on a struct that has a dynamic array

2018-02-11 Thread rumbu via Digitalmars-d-learn
On Monday, 12 February 2018 at 03:13:43 UTC, aliak wrote: Hi, Is there a way to get post increment and pre increment working properly in this scenario? import std.stdio; struct A { int[] a; this(int a) { this.a = [a]; } auto opUnary(string op)(){ return A(mixin(op ~ "this

Re: Fixed size array initialization

2018-02-11 Thread rumbu via Digitalmars-d-learn
On Sunday, 11 February 2018 at 14:06:32 UTC, rjframe wrote: On Sat, 10 Feb 2018 10:55:30 +, rumbu wrote: If you separate initialization to a static this, you'll get a compile error: ``` immutable uint256[78] pow10_256; static this() { // Error: mismatched array lengths, 78 and 2

Re: Fixed size array initialization

2018-02-10 Thread rumbu via Digitalmars-d-learn
On Sunday, 11 February 2018 at 01:26:59 UTC, psychoticRabbit wrote: On Sunday, 11 February 2018 at 01:13:00 UTC, psychoticRabbit wrote: Well, in C.. I can do: int arr[2] = { [0]=10, [1]=20 }; I cannot work out how to do that in D yet (anyone know??) Oh. just worked it out after reading thi

Re: Fixed size array initialization

2018-02-10 Thread rumbu via Digitalmars-d-learn
On Saturday, 10 February 2018 at 14:55:49 UTC, b2.temp wrote: On Saturday, 10 February 2018 at 14:35:52 UTC, rumbu wrote: In this case, it there any way to be sure that I declared all the elements I intended? Obviously, without counting them by hand. At the level of the library use a templa

Re: Fixed size array initialization

2018-02-10 Thread rumbu via Digitalmars-d-learn
On Saturday, 10 February 2018 at 12:28:16 UTC, b2.temp wrote: On Saturday, 10 February 2018 at 10:55:30 UTC, rumbu wrote: I know that according to language spec (https://dlang.org/spec/arrays.html#static-init-static) you can skip declaring all your elements in a fixed size array. I'm just rec

Fixed size array initialization

2018-02-10 Thread rumbu via Digitalmars-d-learn
I know that according to language spec (https://dlang.org/spec/arrays.html#static-init-static) you can skip declaring all your elements in a fixed size array. I'm just recovering from a bug which took me one day to discover because of this. I have a large static initialized array, let's say

Re: How to proceed with learning to code Windows desktop applications?

2018-01-31 Thread rumbu via Digitalmars-d-learn
On Monday, 29 January 2018 at 22:55:12 UTC, I Lindström wrote: Hello all! I've been doing console apps for about a year and a half now, but my requirements are reaching the limits of easy to use with ASCII-based UI and typed commands so I'm thinking of moving into GUI-era with my projects. I

Re: Cannot initialize associative array

2018-01-19 Thread rumbu via Digitalmars-d-learn
On Friday, 19 January 2018 at 23:27:06 UTC, Adam D. Ruppe wrote: On Friday, 19 January 2018 at 23:16:19 UTC, rumbu wrote: According to this (https://dlang.org/spec/hash-map.html#static_initialization) this is correct static initialization for AA: That only works inside a function, and, ironic

Cannot initialize associative array

2018-01-19 Thread rumbu via Digitalmars-d-learn
According to this (https://dlang.org/spec/hash-map.html#static_initialization) this is correct static initialization for AA: immutable RoundingMode[string] ibmRounding = [ ">" : RoundingMode.towardPositive, "<" : RoundingMode.towardNegative, "0" : RoundingMode.towardZero, "=0":

Re: New integer promotion rules

2018-01-18 Thread rumbu via Digitalmars-d-learn
On Thursday, 18 January 2018 at 18:00:51 UTC, rumbu wrote: On Thursday, 18 January 2018 at 17:54:59 UTC, rumbu wrote: On Thursday, 18 January 2018 at 12:51:48 UTC, Dominikus Dittes target = isNegative ? cast(Unsigned!T)(-c) : cast(Unsigned!T)c; That would have been better even before the

Re: New integer promotion rules

2018-01-18 Thread rumbu via Digitalmars-d-learn
On Thursday, 18 January 2018 at 17:54:59 UTC, rumbu wrote: On Thursday, 18 January 2018 at 12:51:48 UTC, Dominikus Dittes target = isNegative ? cast(Unsigned!T)(-c) : cast(Unsigned!T)c; That would have been better even before the change, because the operator '-' used on unsigned types is li

Re: New integer promotion rules

2018-01-18 Thread rumbu via Digitalmars-d-learn
On Thursday, 18 January 2018 at 12:51:48 UTC, Dominikus Dittes Scherkl wrote: On Thursday, 18 January 2018 at 06:05:08 UTC, rumbu wrote: On Thursday, 18 January 2018 at 02:30:17 UTC, Rubn wrote: On Wednesday, 17 January 2018 at 22:30:11 UTC, rumbu wrote: code like "m = n < 0 ? -n : n" doesn't

Re: New integer promotion rules

2018-01-17 Thread rumbu via Digitalmars-d-learn
On Thursday, 18 January 2018 at 02:30:17 UTC, Rubn wrote: On Wednesday, 17 January 2018 at 22:30:11 UTC, rumbu wrote: code like "m = n < 0 ? -n : n" doesn't worth a wrapper That code is worth a wrapper, it's called "abs"... m = abs(n); Well, since I'm in the learn forum and you seem to have

Re: New integer promotion rules

2018-01-17 Thread rumbu via Digitalmars-d-learn
On Wednesday, 17 January 2018 at 21:12:07 UTC, Rubn wrote: On Wednesday, 17 January 2018 at 20:30:07 UTC, rumbu wrote: And here is why is bothering me: auto max = isNegative ? cast(Unsigned!T)(-T.min) : cast(Unsigned!T)T.max); The generic code above (which worked for all signed integral typ

Re: New integer promotion rules

2018-01-17 Thread rumbu via Digitalmars-d-learn
And here is why is bothering me: auto max = isNegative ? cast(Unsigned!T)(-T.min) : cast(Unsigned!T)T.max); The generic code above (which worked for all signed integral types T in 2.077) must be rewritten like this in 2.078: static if (T.sizeof >= 4) auto max = isNegative ? cast(Unsigned

Re: New integer promotion rules

2018-01-17 Thread rumbu via Digitalmars-d-learn
On Wednesday, 17 January 2018 at 19:54:50 UTC, ag0aep6g wrote: On 01/17/2018 08:40 PM, rumbu wrote: This started in the last DMD version (2.078): byte b = -10; ulong u = b < 0 ? -b : b; //Deprecation: integral promotion not done for `-b`, use '-transition=intpromote' switch or `-cast(int)(b)

New integer promotion rules

2018-01-17 Thread rumbu via Digitalmars-d-learn
This started in the last DMD version (2.078): byte b = -10; ulong u = b < 0 ? -b : b; //Deprecation: integral promotion not done for `-b`, use '-transition=intpromote' switch or `-cast(int)(b) Why do I need a to promote a byte to int to obtain an ulong? Even in the extreme case where b is by

Re: Function hijack on selective import

2018-01-16 Thread rumbu via Digitalmars-d-learn
On Tuesday, 16 January 2018 at 20:30:43 UTC, H. S. Teoh wrote: On Tue, Jan 16, 2018 at 07:14:00PM +, rumbu via Even specialized, now I have another problem: std.math: int signbit(X)(X x) { ... } mylibrary: int signbit(D: Decimal!bits, int bits) { ... } = end user: import

Re: Function hijack on selective import

2018-01-16 Thread rumbu via Digitalmars-d-learn
On Tuesday, 26 December 2017 at 20:21:11 UTC, Adam D. Ruppe wrote: On Tuesday, 26 December 2017 at 19:41:47 UTC, rumbu wrote: "Custom" is a templated struct. I cannot imagine all the instantiations of Custom to write template specialisations for each of them. You can specialize on templated s

Re: private selective import + overload = breaks accessibility rules

2018-01-16 Thread rumbu via Digitalmars-d-learn
On Tuesday, 16 January 2018 at 18:32:46 UTC, H. S. Teoh wrote: Which version of the compiler is this? I'm pretty sure the std.math.isNaN imported by module a should not be visible in module b. The latest compiler should emit a deprecation warning for this. 2.078, but also 2.077. Deprecation

private selective import + overload = breaks accessibility rules

2018-01-16 Thread rumbu via Digitalmars-d-learn
module a; private import std.math: isNaN; //custom overload public bool isNaN(int i) { return false; } = module b; import a; void foo() { bool b = isNaN(float.nan); //compiles successfully calling std.math.isNaN even it should not be visible. } Is this

Filling up a FormatSpec

2018-01-02 Thread rumbu via Digitalmars-d-learn
Is there any way to parse a format string into a FormatSpec? FormatSpec has a private function "fillUp" which is not accessible. I need to provide formatting capabilities to a custom data type, I've already written the standard function: void toString(C)(scope void delegate(const(C)[]) sink

float.max + 1.0 does not overflow

2017-12-27 Thread rumbu via Digitalmars-d-learn
Is that normal? use std.math; float f = float.max; f += 1.0; assert(IeeeFlags.overflow) //failure assert(f == float.inf) //failure, f is in fact float.max On the contrary, float.max + float.max will overflow. The behavior is the same for double and real.

Re: Function hijack on selective import

2017-12-26 Thread rumbu via Digitalmars-d-learn
On Tuesday, 26 December 2017 at 20:21:11 UTC, Adam D. Ruppe wrote: On Tuesday, 26 December 2017 at 19:41:47 UTC, rumbu wrote: "Custom" is a templated struct. I cannot imagine all the instantiations of Custom to write template specialisations for each of them. You can specialize on templated s

Re: Function hijack on selective import

2017-12-26 Thread rumbu via Digitalmars-d-learn
On Tuesday, 26 December 2017 at 16:15:55 UTC, Adam D. Ruppe wrote: The mistake you're making is using a constraint when you should try a specialization: int signbit(T:Custom)(T x) { return 0; } That means to use this specialized function when T is Custom. Now, you just need to merge the

Function hijack on selective import

2017-12-26 Thread rumbu via Digitalmars-d-learn
Is there anyway to extend an existing function to accept custom data types? Option 1 - global import of std.math import std.math; struct Custom {} int signbit(T)(T x) if (is(T == Custom)) { return 0; } Custom c; assert(signbit(c) == 0); assert(signbit(-1.0) == 1); Er

Overloading float operators

2017-12-11 Thread rumbu via Digitalmars-d-learn
Is there any way to overload specific floating point operators? https://dlang.org/spec/expression.html#floating-point-comparisons I'm using a decimal data type (a struct) and one of the possible values is NaN, that's why I need these operators. I know also that this also was discussed, but is

Re: Reflection in D

2017-01-28 Thread rumbu via Digitalmars-d-learn
On Saturday, 28 January 2017 at 07:03:51 UTC, medhi558 wrote: public static NetworkMessage GetInstance(string id) { auto v = (id in ProtocolMessageManager.m_types); if (v !is null) return cast(NetworkMessage)ProtocolMessageManager.m_types[id].create(); else

Re: Reflection in D

2017-01-28 Thread rumbu via Digitalmars-d-learn
On Saturday, 28 January 2017 at 08:18:15 UTC, medhi558 wrote: On Saturday, 28 January 2017 at 07:39:51 UTC, rumbu wrote: On Saturday, 28 January 2017 at 07:10:27 UTC, medhi558 wrote: I have a last question, currently i use : if(lc.name.indexOf("protocol.messages") != -1) To know if the class i

Re: Reflection in D

2017-01-27 Thread rumbu via Digitalmars-d-learn
On Saturday, 28 January 2017 at 07:10:27 UTC, medhi558 wrote: I have a last question, currently i use : if(lc.name.indexOf("protocol.messages") != -1) To know if the class is a NetworkMessage, Would be possible to do this if(lc is NetworkMessage) Sorry for my English, i speak french. if (

Re: Parsing a UTF-16LE file line by line, BUG?

2017-01-05 Thread rumbu via Digitalmars-d-learn
I'm not sure if this works quite as intended, but I was at least able to produce a UTF-16 decode error rather than a UTF-8 decode error by setting the file orientation before reading it. import std.stdio; import core.stdc.wchar_ : fwide; void main(){ auto file = File("UTF-

Re: Issue with dmd, linker, visualD on windows 10

2016-12-14 Thread rumbu via Digitalmars-d-learn
On Wednesday, 14 December 2016 at 11:06:10 UTC, aberba wrote: I am trying to get a fellow to try D but just setting up on windows 10 has been headache. He's currently remote. Here's the problem. (Note I'm a Linux user and haven't used windows 10) 1. He installed dmd 2 but the command "dmd" is

Re: How can I concatenate a string, a char array and an int

2016-11-29 Thread rumbu via Digitalmars-d-learn
On Tuesday, 29 November 2016 at 10:21:24 UTC, Anders S wrote: Hi guys, just started to get into Dlang, comming from C and C++ I like to use methods like there if possible. Now I want to catenate something like this, but don't get it to work in standard C i code: char str[80]; sprintf(

Re: Is there a way to identfy Windows version?

2016-11-22 Thread rumbu via Digitalmars-d-learn
On Tuesday, 22 November 2016 at 11:00:52 UTC, Bauss wrote: On Monday, 21 November 2016 at 09:11:39 UTC, Jonathan M Davis wrote: On Monday, November 21, 2016 08:57:11 Bauss via Digitalmars-d-learn wrote: [...] Phobos doesn't have anything like that, but you can use the C functions from the Wi

Re: How to muldiv in D?

2016-11-22 Thread rumbu via Digitalmars-d-learn
On Tuesday, 22 November 2016 at 08:54:36 UTC, Kagamin wrote: Yep, I need muldiv for long values on x86-64. Quick and dirty assembler: version(D_InlineAsm_X86_64): long muldiv(long a, long b, long c) { //windows RCX, RDX, R8 //linux RDI, RSI, RDX version(Windows) { asm

Symbol lookup failed in imported module

2016-10-02 Thread rumbu via Digitalmars-d-learn
module module1; void foo(string s) {} -- module module2; import module1; void foo(int i) { foo("abc"); //error - function foo(int) is not callable using argument types(string) } Ok, this can be easily solved using "alias foo = module1.foo", but according to the documenta

Re: Shallow copy object when type is know

2016-04-21 Thread rumbu via Digitalmars-d-learn
On Wednesday, 20 April 2016 at 12:32:48 UTC, Tofu Ninja wrote: Is there a way to shallow copy an object when the type is known? I cant seem to figure out if there is a standard way. I can't just implement a copy function for the class, I need a generic solution. extern (C) Object _d_newclass(

Custom type creation guidelines

2016-01-06 Thread rumbu via Digitalmars-d-learn
Let's suppose that I want to implement a custom arithmetic type. Looking through phobos at Complex, BigInt, HalfFloat, Variant, etc, there is no consistent or idiomatic way to implement various operators or functions on custom types. 1) Regarding unary operator overloading, what's the best way

Re: Why isn't field-wise constructor automatic for structs and not classes?

2016-01-02 Thread rumbu via Digitalmars-d-learn
On Saturday, 2 January 2016 at 14:57:58 UTC, Shriramana Sharma wrote: John Colvin wrote: Strictly speaking you aren't calling a constructor there, you're writing a struct literal. Why do you say I'm not calling a constructor? A class constructor is written as: auto s = *new* Timespan(1, 2

Re: Variable below zero but if statement doesn't grab?

2015-12-28 Thread rumbu via Digitalmars-d-learn
On Sunday, 27 December 2015 at 23:24:55 UTC, TheDGuy wrote: On Sunday, 27 December 2015 at 22:51:27 UTC, Ali Çehreli wrote: On 12/27/2015 07:53 AM, TheDGuy wrote: Any idea what i am doing wrong? https://www.youtube.com/watch?v=j_VCa-5VeP8 YouTube says that the video has been removed by the us

Re: Graphics/font/platform backends with common interfaces?

2015-12-23 Thread rumbu via Digitalmars-d-learn
On Wednesday, 23 December 2015 at 19:22:01 UTC, Taylor Hillegeist wrote: So I have seen alot of projects that need the same sort of stuff. graphics libraries gui libraries game libraries ploting libaries they would all benefit from a backend solution with a common interface for color fonts

  1   2   >