Re: Implicit conversion by return

2018-08-08 Thread Alex via Digitalmars-d-learn
On Wednesday, 8 August 2018 at 08:15:16 UTC, Hakan Aras wrote: Given this: struct Num { this(int a) {} } Is there any reason why this works: Num n = 5; but this doesnt: Num funk() { return 5; } I understand that I can construct it explicitely, but that gets annoying quickly, espec

Re: if(int a = 0) lowered to "if (int a = (int a = 1;) , a)" ?

2018-08-08 Thread Alex via Digitalmars-d-learn
On Wednesday, 8 August 2018 at 11:58:50 UTC, aliak wrote: Found this out while just looking at lowerings. How do you "look at lowerings"? Is there a list, I'm not aware of? ;)

Re: if(int a = 0) lowered to "if (int a = (int a = 1;) , a)" ?

2018-08-08 Thread Alex via Digitalmars-d-learn
On Wednesday, 8 August 2018 at 13:13:24 UTC, aliak wrote: Go here https://run.dlang.io/is/tJ4vXm and click on the AST button :) It shows you what the code turns in to after all the semantic passes. Yeah... no... I'm aware of this cool thing )) I thought you have a hidden source of knowledge,

@nogc with opApply

2018-08-11 Thread Alex via Digitalmars-d-learn
Hi all, maybe I misunderstand something but having this: ´´´ import std.experimental.all; static assert(isIterable!S); void main() { S s; s.each!(el => el.writeln); } struct S { private Nullable!uint member = 0; Nullable!uint front() @nogc { return member; } //void popFront

Re: @nogc with opApply

2018-08-12 Thread Alex via Digitalmars-d-learn
On Sunday, 12 August 2018 at 01:39:21 UTC, ag0aep6g wrote: On 08/11/2018 12:00 PM, Alex wrote: [...] [...] [...] [...] [...] [...] [...] You can provide to overloads: one with @nogc, one without it. To keep it somewhat DRY, you can let them forward to a template implementation:

Re: write a function template specialisation that tests if an argument is known at compile time

2018-08-12 Thread Alex via Digitalmars-d-learn
On Saturday, 11 August 2018 at 05:17:51 UTC, Cecil Ward wrote: T myfunc(T)( T x, uint mask ) if ( mask == 3 ) { return fast_func( x, mask ); } [...] Is it the volcano pattern you are looking for? https://p0nce.github.io/d-idioms/#Is-this-available-at-compile-time-or-runtime?

A devil self reference

2018-08-15 Thread Alex via Digitalmars-d-learn
Hi all. Finally, I arrived at something like this: ´´´ void main() { S!(sarr)[] sarr; } struct S(alias Reference) { size_t id() in { // not static assert, only because a pointer is never known in advance assert(Reference.ptr <= &this);

Re: A devil self reference

2018-08-15 Thread Alex via Digitalmars-d-learn
On Wednesday, 15 August 2018 at 16:40:49 UTC, Alex wrote: Hi all. Finally, I arrived at something like this: ´´´ void main() { S!(sarr)[] sarr; } struct S(alias Reference) { size_t id() in { // not static assert, only because a pointer is never known in advanc

Re: A devil self reference

2018-08-15 Thread Alex via Digitalmars-d-learn
On Wednesday, 15 August 2018 at 21:42:11 UTC, Jonathan M Davis wrote: What are you actually trying to do? Aside from the circular reference issues, using the address of a struct like that is very risky, because if the struct is ever moved, it will change. Yeah... my functions are all ref. Or

Re: Cast to original type each argument in template pack

2018-08-21 Thread Alex via Digitalmars-d-learn
On Tuesday, 21 August 2018 at 08:08:58 UTC, Andrey wrote: Hello, I have a function: string format(string pattern, T...)(T value) { auto writer = appender!string(); writer.formattedWrite!pattern(convertToUnderlyingType(value)); //Tuple!T(value).expand.to!(OriginalType!T) return write

Re: Coreect way to create delegate for struct method.

2018-08-21 Thread Alex via Digitalmars-d-learn
On Tuesday, 21 August 2018 at 21:29:38 UTC, Andrey wrote: Hello, This is a code: import std.stdio; struct Test { static Test opCall() { Test test; test.handler = &test.one; return test; } void one() const { writeln("In handler: Address = ", &this, "; Text = "

Re: Coreect way to create delegate for struct method.

2018-08-22 Thread Alex via Digitalmars-d-learn
On Wednesday, 22 August 2018 at 07:03:02 UTC, Andrey wrote: On Tuesday, 21 August 2018 at 22:52:31 UTC, Alex wrote: Maybe, like this: Thank you but here you use heap to create ab object. I want only on stack. I know that one can do this: test_handler.ptr = null; and in place of call this:

Re: How to map elements of a tuple?

2018-08-22 Thread Alex via Digitalmars-d-learn
On Wednesday, 22 August 2018 at 10:36:32 UTC, Andrey wrote: Hello, Is there a template/function/mixin... in the library that I can use to map elements of a tuple? object.foo(Mapper!myMapFunction(1, bool, "Qwerty", EnumedColor.Red)); where "Mapper" is this mapper and "myMapFunction" is a tem

Re: Nested template arguments

2018-08-22 Thread Alex via Digitalmars-d-learn
On Wednesday, 22 August 2018 at 14:30:39 UTC, XavierAP wrote: Why foo!bar!x is not understood as foo!(bar!x) but instead gives an error "multiple ! arguments are not allowed"? Precisely because multiple "!" can never belong to the same instantiation, why does the parser not

Re: Nested template arguments

2018-08-22 Thread Alex via Digitalmars-d-learn
On Wednesday, 22 August 2018 at 15:18:29 UTC, XavierAP wrote: On Wednesday, 22 August 2018 at 14:48:57 UTC, Alex wrote: Because it could be meant as the argument to some templates to the left. Like (foo!bar)!x Sure, it would be a coincidence, if both will work. However, templates are not so

Re: Is there a simple way to check if value is null for every case?

2018-08-27 Thread Alex via Digitalmars-d-learn
On Monday, 27 August 2018 at 19:36:29 UTC, aliak wrote: Then Nullable!(int*) would be the same as int*. Or even better maybe is to give a compiler error when you try and stuff a nullable type inside a Nullable. Because ... why? Isn't it arguable, whether this is desired? I mean, in the pr

Re: tupleof function parameters?

2018-08-27 Thread Alex via Digitalmars-d-learn
On Tuesday, 28 August 2018 at 06:11:35 UTC, Jon Degenhardt wrote: I'd like to create a Tuple alias representing a function's parameter list. Is there a way to do this? [...] Are you aware of https://dlang.org/phobos/std_traits.html#Parameters

Re: Create constraint for each parameter in template arg pack

2018-08-28 Thread Alex via Digitalmars-d-learn
On Tuesday, 28 August 2018 at 13:05:15 UTC, bauss wrote: On Tuesday, 28 August 2018 at 12:28:19 UTC, Andrey wrote: Hello, Let we have two variadic templates: template Qwerty(Values...) {} template Qaz(alias type, Data...) {} Now I want to add a constraint to "Qwerty" so that each type in "Va

Re: Can you get typeof(this) in a mixin template - trying to mimic a Kotlin feature here.

2018-08-28 Thread Alex via Digitalmars-d-learn
On Tuesday, 28 August 2018 at 20:39:16 UTC, aliak wrote: Hi, I'm trying to do something similar to what Kotlin allows with assigning to member variables from a map. The syntax is very readable and looks like: class User(val map: Map) { val name: String by map val age: Int by map

Re: Structures and CTFE

2018-09-03 Thread Alex via Digitalmars-d-learn
On Monday, 3 September 2018 at 14:00:23 UTC, agorkvmh wrote: There is a way to do print the two values at compile time? Yes. Put a pragma where you static assert for Foo(1).pos equality with 2: -- static assert(Foo(1).pos == 2); pragma(msg, Foo(1).pos); struct Foo { this(int i)

Re: Struct immutable data and dict

2018-09-04 Thread Alex via Digitalmars-d-learn
On Tuesday, 4 September 2018 at 10:30:24 UTC, Timoses wrote: However, of course this also fails because randomly assigning the array elements will overwrite it. So the associative array seems like the better idea. However, not being able to INITIALIZE an assoc array element disallows its usag

Re: Error: expression `update` of type `void` does not have a boolean value

2018-09-07 Thread Alex via Digitalmars-d-learn
On Saturday, 8 September 2018 at 03:12:56 UTC, Josphe Brigmo wrote: auto foo(bool update = false)() { static if(update) { } } and the compiler, after upgrading to 2.082 from 2.080 now says: Error: expression `update` of type `void` does not have a boolean value when update is clearly

Re: Error: expression `update` of type `void` does not have a boolean value

2018-09-08 Thread Alex via Digitalmars-d-learn
On Saturday, 8 September 2018 at 06:56:40 UTC, Josphe Brigmo wrote: My project does not use the term update at all in any other context except that one. But I did find: void update(K, V, C, U)(ref V[K] aa, K key, scope C create, scope U update) Ok... found something here: https://dlang.or

Re: remove file access denied(remove broke)

2018-09-14 Thread Alex via Digitalmars-d-learn
On Friday, 14 September 2018 at 08:32:48 UTC, Josphe Brigmo wrote: No, I use read, there is no file handles. Pointless to post code because it won't offer much. Also, I have security privileges. I simply read the file to compare it's contents then I try to remove the file if it had the same c

Re: Is there a way to use Object.factory with templated classes? Or some way to construct templated classes given RTTI of an instance?

2018-09-27 Thread Alex via Digitalmars-d-learn
On Wednesday, 26 September 2018 at 20:41:38 UTC, Chad Joan wrote: class Root(T) { T x; } class Extended(T) : Root!T { T y; } Sorry for a technical aside, but would this be something for you? https://forum.dlang.org/post/vtaxcxpufrovwfrkb...@forum.dlang.org I mean... In eithe

Re: Delegates with stackpointers

2018-09-29 Thread Alex via Digitalmars-d-learn
On Saturday, 29 September 2018 at 06:01:50 UTC, Ritchie wrote: How does a delegate with a stackpointer work? e.g. in this example: https://run.dlang.io/is/XviMSl Does the second call to foo not overwrite the stack of the first call and thereby the data pointed to by bar1? How is that data pr

Re: New With Struct and Getting Class Object Pointers

2018-09-30 Thread Alex via Digitalmars-d-learn
On Sunday, 30 September 2018 at 09:30:38 UTC, Vijay Nayar wrote: Is there a way to either have a constant reference to a class that can be set to a new value, or is there a way to convert the class variable to a class pointer? For example: void main() { class Thing {} class Th

Re: contracts in interfaces: do they work, do I have to do something to enable checking of contracts ?

2018-10-01 Thread Alex via Digitalmars-d-learn
On Monday, 1 October 2018 at 13:49:53 UTC, Emil wrote: I am trying my hand at contracts and they work fine in plain functions and in methods, but I can't make them work in interfaces. https://dlang.org/spec/interface.html#interface-contracts $ dmd --version DMD64 D Compiler v2.081.1 Copyright

Re: Data structures and algorithms in D?

2018-10-08 Thread Alex via Digitalmars-d-learn
On Sunday, 7 October 2018 at 20:27:47 UTC, eastanon wrote: Are there reading resources on Data structures and Algorithms in D? There are several such books in the C/C++ and Java world and many senior/experienced D users might have come across them in C. But for people who join D after reading A

Re: std.regex is fat

2018-10-12 Thread Alex via Digitalmars-d-learn
On Friday, 12 October 2018 at 13:25:33 UTC, Chris Katko wrote: Like, insanely fat. All I wanted was a simple regex. The second include a regex function, my program would no longer compile "out of memory for fork". /usr/bin/time -v reports it went from 150MB of RAM for D, DAllegro, and Alleg

Re: ported a sortable list from my old C code

2018-10-13 Thread Alex via Digitalmars-d-learn
On Saturday, 13 October 2018 at 11:11:41 UTC, Codifies wrote: https://run.dlang.io/gist/b8b03ce3246951b5356db064ab68b22e its a bit fugly at the moment and I want to use something other than a void pointer (any?) (the whole thing was very pointer centric as everything was malloc'd...) I'm not

Re: How can I induce implicit type convesion with alias this on calling template function?

2018-10-14 Thread Alex via Digitalmars-d-learn
On Monday, 15 October 2018 at 04:51:39 UTC, Sobaya wrote: void func(T : int)(T value) if (is(T == int)) { } struct S { int x; alias x this; } void main() { func(S()); // error } In above code, 'func' can accept only int as its argument type, so when 'S', which can be implicitly co

Re: Can opApply be made @nogc?

2018-10-19 Thread Alex via Digitalmars-d-learn
On Friday, 19 October 2018 at 23:32:44 UTC, solidstate1991 wrote: Since it's a bit difficult to make tree traversal through range (especially if someone wants to make it @nogc), I thought I'll make it through opApply override, however the delegate passed by it doesn't have the @nogc attribute,

Re: assigment to null class object member compiled? is this a bug?

2018-10-22 Thread Alex via Digitalmars-d-learn
On Monday, 22 October 2018 at 01:39:48 UTC, dangbinghoo wrote: On Friday, 19 October 2018 at 09:08:32 UTC, Vijay Nayar wrote: Technically the code you have is syntactically correct. You are permitted to create a class variable without assigning it to a class object. (Assigning it to a class o

updated mir interface

2018-11-07 Thread Alex via Digitalmars-d-learn
I'm referring to the example http://docs.random.dlang.io/latest/mir_random_algorithm.html#.sample Could somebody tell me, why ´´´ import mir.random.algorithm; import std.range; //import mir.range; void main() { // line 5 size_t[] arr; arr.length = 42; arr = arr.length.io

Re: updated mir interface

2018-11-07 Thread Alex via Digitalmars-d-learn
On Wednesday, 7 November 2018 at 14:07:32 UTC, 9il wrote: This is a regression. It is fixed in mir-random v2.1.2. Thanks. But I have another one: ´´´ import mir.random.algorithm; import std.experimental.all; void main() { S[] arr; arr.length = 42; arr.each!((i, ref el)

Re: updated mir interface

2018-11-07 Thread Alex via Digitalmars-d-learn
On Wednesday, 7 November 2018 at 17:05:31 UTC, 9il wrote: I have updated template constraints. http://docs.random.dlang.io/latest/mir_random_algorithm.html#.sample The problem that looks like Phobos map does not define all required primitives like popFrontExactly. Ok... didn't have this on my

Re: updated mir interface

2018-11-07 Thread Alex via Digitalmars-d-learn
Ok... sorry for being penetrant, but there is still something strange. Having dependencies as you had, ´´´ import mir.random.algorithm; import mir.algorithm.iteration; import mir.ndslice; import mir.random; void fun(size_t s){} void main() { size_t[] arr; arr.length = 42;

Re: updated mir interface

2018-11-07 Thread Alex via Digitalmars-d-learn
On Wednesday, 7 November 2018 at 19:40:57 UTC, 9il wrote: On Wednesday, 7 November 2018 at 19:09:50 UTC, Alex wrote: Ok... sorry for being penetrant, but there is still something strange. Having dependencies as you had, [...] Well, fixed in v2.1.3 Thanks again! Works for now.

Re: scoped classes and dependency inversion

2018-11-08 Thread Alex via Digitalmars-d-learn
On Thursday, 8 November 2018 at 11:04:19 UTC, Sjoerd Nijboer wrote: I'm trying to invert the dependency from the classes `Bar -> Foo` to `Foo -> IFoo <- Bar` at compile time. I do want `Foo's` to be embedded into `Bar` So silly me tried something like this: [...] So how can I delay the constr

Re: scoped classes and dependency inversion

2018-11-08 Thread Alex via Digitalmars-d-learn
On Thursday, 8 November 2018 at 15:11:16 UTC, Sjoerd Nijboer wrote: Except if you want to pass a parameter to TFoo it'll become a mess. And I expecially don't want it to become messy. I thought of this case... But passing the argument to TFoo directly while constructing Bar is messier, I thin

Re: Exception slipping through the catch block?

2018-11-08 Thread Alex via Digitalmars-d-learn
On Thursday, 8 November 2018 at 15:50:38 UTC, helxi wrote: Thanks. Although it's pretty frustrating, isn't it? Now not only I have to think about catching exceptions but also about Errors, and have no guarantee that I have everything under control. Isn't it rather the case, that you have to

Re: Creating InputRanges from strings, files etc.

2018-11-08 Thread Alex via Digitalmars-d-learn
On Thursday, 8 November 2018 at 16:15:25 UTC, Vinay Sajip wrote: On Thursday, 8 November 2018 at 14:38:37 UTC, Paul Backus wrote: To pass these ranges around using the `InputRange` interface, use `inputRangeObject` to wrap them: InputRange!ubyte r3 = inputRangeObject(r1); InputRange!(i

Re: scoped classes and dependency inversion

2018-11-09 Thread Alex via Digitalmars-d-learn
On Friday, 9 November 2018 at 09:13:56 UTC, Sjoerd Nijboer wrote: On Thursday, 8 November 2018 at 21:16:32 UTC, Sjoerd Nijboer wrote: I tried tom make a lazyscoped!T but I'm stuck at creating a constructor and determining the arguments from the Type. Unfortunately I can't find a way in D to ge

Re: How does calling function pointers work?

2018-11-12 Thread Alex via Digitalmars-d-learn
On Monday, 12 November 2018 at 16:29:24 UTC, helxi wrote: On Monday, 12 November 2018 at 16:25:13 UTC, Rene Zwanenburg wrote: Idk where you got that syntax from, but there's no syntactic difference between calling normal functions and function pointers: import std.stdio; import std.concurrenc

Re: passing subclass to superclass where parameter is a delegate for the superclass

2018-11-14 Thread Alex via Digitalmars-d-learn
On Wednesday, 14 November 2018 at 16:06:21 UTC, Chris Bare wrote: If I have: class base { void delegate(base) stored_dg; void add_function (void delegate (base) dlg) { stored_dg = dlg; } } class A : base { this () { super (); add_function (&th

Re: passing subclass to superclass where parameter is a delegate for the superclass

2018-11-14 Thread Alex via Digitalmars-d-learn
On Wednesday, 14 November 2018 at 16:39:52 UTC, Alex wrote: Are you looking for this? https://dlang.org/phobos/std_traits.html#TransitiveBaseTypeTuple It matches however not exactly your needs: As all objects are derived from the Object class, you will always get it as the common parent. So...

Re: what are the rules for @nogc and @safe attributes inference?

2018-11-16 Thread Alex via Digitalmars-d-learn
On Friday, 16 November 2018 at 10:25:26 UTC, ikod wrote: On Thursday, 15 November 2018 at 21:55:18 UTC, Steven Schveighoffer wrote: On 11/15/18 4:09 PM, Adam D. Ruppe wrote: On Thursday, 15 November 2018 at 21:00:48 UTC, ikod wrote: what are the rules for @nogc inference? It attempts it if a

interrupting a function

2018-11-16 Thread Alex via Digitalmars-d-learn
I wished I never come across the nightmare of such a question. And maybe, there is still a bug in my code, which I'm not aware of (which I strongly suppose :/ ). But nevertheless, and for learning purposes, assume I have something like this: ´´´ auto foo(/*input params*/) { //some long cal

Re: interrupting a function

2018-11-17 Thread Alex via Digitalmars-d-learn
On Saturday, 17 November 2018 at 08:17:36 UTC, Paul Backus wrote: You could run the calculation in another thread and use std.concurrency.receiveTimeout [1] to stop waiting for the result after a certain amount of time. [1] https://dlang.org/phobos/std_concurrency.html#.receiveTimeout Ah.

Re: D money data type compatible with postgresql money

2018-11-17 Thread Alex via Digitalmars-d-learn
On Saturday, 17 November 2018 at 11:48:56 UTC, Václav Kozák wrote: Hello, I have a column of type money in my database. I need to pull the data from the db in my vibe.d backend, but it can't handle such data type. How can I do it? Should I use some library (which?)? Thanks. At code.dlang.org

Re: Throwing constructors and member destructors

2018-11-20 Thread Alex via Digitalmars-d-learn
On Tuesday, 20 November 2018 at 13:01:40 UTC, Boris-Barboris wrote: https://run.dlang.io/is/LdylJX Notice no "B destructor" line in stdout. Just got bitten by the assumption that my Buffer struct that transactionally aquires multiple external resources in constructor will rollback via member

Re: Why does nobody seem to think that `null` is a serious problem in D?

2018-11-21 Thread Alex via Digitalmars-d-learn
On Wednesday, 21 November 2018 at 10:47:35 UTC, NoMoreBugs wrote: On Monday, 19 November 2018 at 21:39:22 UTC, Adam D. Ruppe wrote: On Monday, 19 November 2018 at 21:23:31 UTC, Jordi Gutiérrez Hermoso wrote: What's the reasoning for allowing this? The mistake is immediately obvious when you r

Re: Why does nobody seem to think that `null` is a serious problem in D?

2018-11-21 Thread Alex via Digitalmars-d-learn
On Wednesday, 21 November 2018 at 14:21:44 UTC, Kagamin wrote: A value passed to ref parameter is assumed to be initialized. C# would reject to call function foo. This was not my point. I wonder, whether the case, where the compiler can't figure out the initialization state of an object is

Re: Why does nobody seem to think that `null` is a serious problem in D?

2018-11-21 Thread Alex via Digitalmars-d-learn
On Wednesday, 21 November 2018 at 17:09:54 UTC, Neia Neutuladh wrote: On Wed, 21 Nov 2018 17:00:29 +, Alex wrote: C# wouldn't reject the case above, would it? C# *would* reject that (you can't call any methods on a null object), but in D, it compiles and runs and doesn't segfault. No, i

Re: Why does nobody seem to think that `null` is a serious problem in D?

2018-11-21 Thread Alex via Digitalmars-d-learn
On Wednesday, 21 November 2018 at 21:05:37 UTC, aliak wrote: On Wednesday, 21 November 2018 at 17:46:29 UTC, Alex wrote: compiled against 4.6.1 Framework. However, of course, there is a NullReferenceException, if c happens to be null, when calling baz. So the difference is not the compiler b

Re: how to remove duplicate code in functional style

2018-11-23 Thread Alex via Digitalmars-d-learn
On Friday, 23 November 2018 at 14:33:40 UTC, berni wrote: I've got the following code, which works, but obviously contains duplication. Is there a way to move that "dissection_available?...:..." to the place, where it should be? return dissection_available ?solution.dup .tran

Re: Cannot build project due to Derelict package

2018-11-26 Thread Alex via Digitalmars-d-learn
On Monday, 26 November 2018 at 11:57:40 UTC, Andrey wrote: Hello, I try to build my project using command "dub build" but I can\t because there is an error: Fetching derelict-util 3.0.0-beta.2 (getting selected version)... SSL connect error on handle 1F19AC0 And this happens every time... As I

handling shared objects

2018-11-26 Thread Alex via Digitalmars-d-learn
Hi all! Can somebody explain to me, why the example below is not working in a way I'm expecting it to work? My example is a little bit longer this time, however the half of it is taken from https://dlang.org/library/std/concurrency/receive_only.html ´´´ import std.experimental.all; struct D

Re: handling shared objects

2018-11-26 Thread Alex via Digitalmars-d-learn
On Monday, 26 November 2018 at 14:28:33 UTC, Steven Schveighoffer wrote: Some problems arose: 1. Obviously, this is not the case, as the output is different, depending on the thread I start the model function. Yes, unless you declare the model to be shared, there is a copy made for each threa

Re: handling shared objects

2018-11-26 Thread Alex via Digitalmars-d-learn
On Monday, 26 November 2018 at 15:26:43 UTC, Steven Schveighoffer wrote: Well, if you want to run calculations in another thread, then send the result back to the original, you may be better off sending the state needed for the calculation to the worker thread, and receiving the result back v

Re: handling shared objects

2018-11-26 Thread Alex via Digitalmars-d-learn
On Monday, 26 November 2018 at 16:27:23 UTC, Steven Schveighoffer wrote: On 11/26/18 10:37 AM, Alex wrote: On Monday, 26 November 2018 at 15:26:43 UTC, Steven Schveighoffer wrote: Well, if you want to run calculations in another thread, then send the result back to the original, you may be be

Re: interrupting a function

2018-11-26 Thread Alex via Digitalmars-d-learn
On Saturday, 17 November 2018 at 08:17:36 UTC, Paul Backus wrote: You could run the calculation in another thread and use std.concurrency.receiveTimeout [1] to stop waiting for the result after a certain amount of time. Ok... would you say the following is a feasible alternative? ´´´ import s

Re: Why pow() won't go beyond 2^31?

2018-11-29 Thread Alex via Digitalmars-d-learn
On Thursday, 29 November 2018 at 07:07:06 UTC, Murilo wrote: I am using the function pow() from std.math but if I try pow(2, 32) it returns 0, it doesn't compute beyond the maximum value of an int(2^31) and I am working with long. What should I do? what exactly is your input? ´´´ import std.s

Re: Best Way to Pass Template Typed Alias Parameters for Functions?

2018-12-23 Thread Alex via Digitalmars-d-learn
On Sunday, 23 December 2018 at 17:13:49 UTC, Vijay Nayar wrote: I have a few cases where I would like to pass in a function as a value to a template, but I want to ensure that the function takes certain kinds of parameters, is a const function, or matches any other set of conditions. What is

Re: Best Way to Pass Template Typed Alias Parameters for Functions?

2018-12-23 Thread Alex via Digitalmars-d-learn
On Sunday, 23 December 2018 at 18:13:25 UTC, Vijay Nayar wrote: I've been playing with the idea of specifying the constraints or using "static assert" in the constructor. They are good options, but there's a few cases where they fall a bit short. For example, imagine you have a container class

Re: Best Way to Pass Template Typed Alias Parameters for Functions?

2018-12-23 Thread Alex via Digitalmars-d-learn
On Sunday, 23 December 2018 at 18:53:15 UTC, Vijay Nayar wrote: You're right, it does compile. I'm a bit surprised. I wonder if this is a relatively recent improvement in the language, because last time I ran into this I had no such luck. But after seeing that your example did work, I figured o

Re: Subtypes with tighter constraints

2019-01-01 Thread Alex via Digitalmars-d-learn
On Tuesday, 1 January 2019 at 14:05:43 UTC, Victor Porton wrote: In Ada2012 there are "subtypes". Subtypes can have tighter constraints (such as type invariants) than their base types. I have a struct X in D. Is it possible to define a type equivalent to X except that having tighter invariants

Re: reimplementing an interface in a derived class

2019-01-03 Thread Alex via Digitalmars-d-learn
On Thursday, 3 January 2019 at 23:23:12 UTC, Neia Neutuladh wrote: On Thu, 03 Jan 2019 22:30:48 +, kdevel wrote: class A : D { int foo() { return 1; } } class B : A, D { [...] What is the meaning of the ", D"? It does not seem to make a difference if it is omitted. B must provide i

Re: reimplementing an interface in a derived class

2019-01-03 Thread Alex via Digitalmars-d-learn
On Friday, 4 January 2019 at 00:15:28 UTC, Neia Neutuladh wrote: On Thu, 03 Jan 2019 23:44:15 +, Alex wrote: I assume that is another bug and has nothing to do with interfaces... B.foo is both overriding A.foo and implementing D.foo, so that's not a bug. I don't have any interfaces in m

Re: reimplementing an interface in a derived class

2019-01-04 Thread Alex via Digitalmars-d-learn
On Friday, 4 January 2019 at 02:13:27 UTC, Neia Neutuladh wrote: I can't think of a single class system that works like that. C++, Java, C#, Dart, and TypeScript all work like D here. GObject in C works like D. In the example below, the "2" of B.foo is printed only once. Independently of the

Re: reimplementing an interface in a derived class

2019-01-04 Thread Alex via Digitalmars-d-learn
On Friday, 4 January 2019 at 07:37:43 UTC, bauss wrote: No, because you OVERRIDE A's foo(). A does not exist. A is B and when you cast B to A you just tell the compiler that the reference should only have A's signature available. You're not assigning B to A. Let's assume this is right. How

Re: reimplementing an interface in a derived class

2019-01-04 Thread Alex via Digitalmars-d-learn
On Friday, 4 January 2019 at 09:19:48 UTC, Simen Kjærås wrote: On Friday, 4 January 2019 at 08:40:04 UTC, Alex wrote: class A { public: int foo(){return 1;} }; class B : public A { public: int foo(){return 2;} }; In C++, methods are non-virtual by default. In D, they are virtual by de

Re: reimplementing an interface in a derived class

2019-01-04 Thread Alex via Digitalmars-d-learn
On Friday, 4 January 2019 at 09:30:32 UTC, bauss wrote: Your C++ example is not the same as in D because in C++ functions aren't virtual by default, they are in D. Mark your functions as virtual in your C++ example and see what happens. All functions in D are virtual by default! Yep. Got i

Re: reimplementing an interface in a derived class

2019-01-04 Thread Alex via Digitalmars-d-learn
On Friday, 4 January 2019 at 09:58:59 UTC, bauss wrote: On Friday, 4 January 2019 at 09:53:18 UTC, Alex wrote: I assume the move method of an Animal is not abstract, and therefore I supposed, casting to this type explicitly should restore this very non-abstract behavior. But this is not the ca

Re: reimplementing an interface in a derived class

2019-01-04 Thread Alex via Digitalmars-d-learn
On Friday, 4 January 2019 at 21:08:24 UTC, Ali Çehreli wrote: [...] In this case, casting is using the B object through it's A interface. The overridden behavior does not change. Yeah... This was my mistake. (Actually, that is possible in languages that support multiple inheritance through m

Re: reimplementing an interface in a derived class

2019-01-04 Thread Alex via Digitalmars-d-learn
On Friday, 4 January 2019 at 21:47:59 UTC, Neia Neutuladh wrote: On Fri, 04 Jan 2019 08:46:24 +, Alex wrote: Let's assume this is right. How to force a B object to behave like an A object? I thought casting is a possible approach... It requires a bit of surgery: :) import std.stdi

Re: Co-developing application and library

2019-01-05 Thread Alex via Digitalmars-d-learn
On Saturday, 5 January 2019 at 13:01:24 UTC, Russel Winder wrote: Dub seems to have the inbuilt assumption that libraries are dependencies that do not change except via a formal release when you developing an application. Clearly there is the workflow where you want to amend the library but not

Re: Bitwise rotate of integral

2019-01-07 Thread Alex via Digitalmars-d-learn
On Monday, 7 January 2019 at 14:43:29 UTC, Per Nordlöw wrote: On Monday, 7 January 2019 at 14:39:07 UTC, Per Nordlöw wrote: What's the preferred way of doing bitwise rotate of an integral value in D? Are there intrinsics for bitwise rotation available in LDC? I just found this ulong rot

Re: static foreach not working with this

2019-01-07 Thread Alex via Digitalmars-d-learn
On Monday, 7 January 2019 at 16:16:57 UTC, Michelle Long wrote: On Monday, 7 January 2019 at 16:01:50 UTC, Michelle Long wrote: static foreach(k, p; AliasSeq!(this, s)) {{ p.foo(); // Fails even if this line is removed }} this not known at compile time. replace s with this a

Re: static foreach not working with this

2019-01-07 Thread Alex via Digitalmars-d-learn
On Monday, 7 January 2019 at 16:31:49 UTC, Steven Schveighoffer wrote: On 1/7/19 11:16 AM, Michelle Long wrote: On Monday, 7 January 2019 at 16:01:50 UTC, Michelle Long wrote: [...] static foreach(k, p; AliasSeq!(Alias!this, s)) {{     p.foo(); // Fails even if this line is removed }} To e

Re: Filter and sort associative array

2019-01-11 Thread Alex via Digitalmars-d-learn
On Friday, 11 January 2019 at 16:02:27 UTC, Head Scratcher wrote: Thank you. This works great. What I don't understand is how a key-value pair ends up being a set of strings. Where did the value of the key-value pair get removed? According to the library documentation, the array function "allo

Re: Interfacing with C libs: weeding through C/C++ macros and such in header files

2019-01-13 Thread Alex via Digitalmars-d-learn
On Sunday, 13 January 2019 at 22:40:57 UTC, Alec Stewart wrote: Example without code; for some reason a macro is defined for the stdlib functions `malloc`, `realloc`, and `free`. Maybe it's just because I don't have any pro experience with C or C++, but that seems a bit excessive. Or I could ju

Re: uniq and array of enum members (That are all strings)

2019-01-16 Thread Alex via Digitalmars-d-learn
On Wednesday, 16 January 2019 at 16:21:12 UTC, bauss wrote: On Wednesday, 16 January 2019 at 16:12:28 UTC, H. S. Teoh wrote: On Wed, Jan 16, 2019 at 03:57:49PM +, bauss via Digitalmars-d-learn wrote: Is there a way to achieve the following: [...] enum Foo : string { a = "aa", b =

Re: uniq and array of enum members (That are all strings)

2019-01-16 Thread Alex via Digitalmars-d-learn
On Wednesday, 16 January 2019 at 16:52:50 UTC, bauss wrote: The problem with sorting is that the following: [3,5,6,6,2,1,2,5,3] will then become [1,2,3,5,6] or [6,5,3,2,1] and not: [3,5,6,2,1] which would be what you'd wanna use in some situations. The important thing to know here is tha

Re: Runtime heterogeneous collections?

2019-01-18 Thread Alex via Digitalmars-d-learn
On Friday, 18 January 2019 at 13:31:28 UTC, Steven Schveighoffer wrote: To answer the OP, what he wants is an array of different RedBlackTrees. Since RedBlackTree is a class, his code is not far off from something that works. This does compile, and produces an Object[]: auto arr = [ redB

Re: Runtime heterogeneous collections?

2019-01-18 Thread Alex via Digitalmars-d-learn
On Friday, 18 January 2019 at 15:07:41 UTC, Steven Schveighoffer wrote: On 1/18/19 9:58 AM, Alex wrote: On Friday, 18 January 2019 at 13:31:28 UTC, Steven Schveighoffer wrote: [...] In this case, I would say Phobos lacks an appropriate interface definition, what do you think? But what is t

Re: preconditions and interfaces

2019-01-20 Thread Alex via Digitalmars-d-learn
On Sunday, 20 January 2019 at 15:39:49 UTC, Antonio Corbi wrote: Hi all, Playing with interfaces and preconditions in methods I get strange results with dmd-2.0.84.0 but also with dmd-nightly. My code is like this: - import std.stdio; interface Thing2D { void width(int w) i

recursive tagging pointer structure

2019-01-23 Thread Alex via Digitalmars-d-learn
Is there a possibility to create a recursive structure with a tagged pointer? As this does not compile, even without tagging bits. ´´´ import std.experimental.all; void main(){} struct A { size_t dummy; mixin(taggedPointer!( A*, "x" /*, bool, "b1", 1, b

Re: How to disable/hide constructor when using factory method?

2019-01-23 Thread Alex via Digitalmars-d-learn
On Wednesday, 23 January 2019 at 19:26:37 UTC, JN wrote: class Foo { static Foo makeFoo() { Foo f = new Foo(); return f; } } void main() { Foo f = Foo.makeFoo(); } For a code like this. I'd like all users of the class to be forced to create instances using the s

GC options

2019-01-25 Thread Alex via Digitalmars-d-learn
I'm experimenting with GC, and reading https://dlang.org/spec/garbage.html#gc_config There is an option setting possible via ´´´ extern(C) __gshared string[] rt_options = [ "gcopt=gc:precise" ]; //gc:conservative|precise|manual ´´´ conservative and manual seem to work, while setting gc to precis

Re: GC options

2019-01-25 Thread Alex via Digitalmars-d-learn
On Friday, 25 January 2019 at 13:39:53 UTC, Radu wrote: On Friday, 25 January 2019 at 13:33:25 UTC, Alex wrote: I'm experimenting with GC, and reading https://dlang.org/spec/garbage.html#gc_config There is an option setting possible via ´´´ extern(C) __gshared string[] rt_options = [ "gcopt=gc:

Re: Why isn't intended class constructor called?

2019-01-28 Thread Alex via Digitalmars-d-learn
On Monday, 28 January 2019 at 18:34:44 UTC, Zak wrote: I have defined a class that's meant to represent a data series, which has an index and a set of values. Sometimes the user wants to specify a particular index of custom type, other times they don't care and we want to default to an array o

Re: Why isn't intended class constructor called?

2019-01-28 Thread Alex via Digitalmars-d-learn
On Monday, 28 January 2019 at 19:24:21 UTC, Zak wrote: On Monday, 28 January 2019 at 19:15:04 UTC, Zak wrote: On Monday, 28 January 2019 at 18:50:18 UTC, Alex wrote: On Monday, 28 January 2019 at 18:34:44 UTC, Zak wrote: [...] As the error states: you are trying to append an int to a string

Range with an alias parameter

2019-01-30 Thread Alex via Digitalmars-d-learn
Given this: ´´´ import std.experimental.all; void main(){} static assert(isInputRange!(ReturnType!(produceS!(42))[])); auto produceS(size_t param)() { return S!param(); } struct S(size_t param) { //@disable this(this); auto opIndex() { return produceRange!(this); } } auto produceRange

Re: Range with an alias parameter

2019-01-30 Thread Alex via Digitalmars-d-learn
On Wednesday, 30 January 2019 at 20:13:56 UTC, Alex wrote: Given this: ´´´ import std.experimental.all; void main(){} static assert(isInputRange!(ReturnType!(produceS!(42))[])); auto produceS(size_t param)() { return S!param(); } struct S(size_t param) { //@disable this(this); auto op

Re: Range with an alias parameter

2019-01-31 Thread Alex via Digitalmars-d-learn
On Thursday, 31 January 2019 at 02:41:00 UTC, Steven Schveighoffer wrote: Apples and oranges :) ReturnType!(produceS!(42)) is a TYPE, not a variable. When you apply the brackets, it's not calling your opindex, but rather changing it to an array. So let's make it clearer by saying: alias T =

Re: Filter out consecutive elements based on comparison between adiacent two

2019-01-31 Thread Alex via Digitalmars-d-learn
On Thursday, 31 January 2019 at 13:18:39 UTC, Langer wrote: Hi all, Ditto... something like: filter!((a,b) => a.foo != b.foo) Thank you! I would say: ´´´ arr.group.map!(el => el[0]) ´´´

Re: Filter out consecutive elements based on comparison between adiacent two

2019-01-31 Thread Alex via Digitalmars-d-learn
On Thursday, 31 January 2019 at 13:18:39 UTC, Langer wrote: Hi all, Ditto... something like: filter!((a,b) => a.foo != b.foo) Thank you! but... why not ´´´ arr.uniq ´´´

Re: Singleton in Action?

2019-02-03 Thread Alex via Digitalmars-d-learn
On Sunday, 3 February 2019 at 09:46:20 UTC, Ron Tarrant wrote: On Saturday, 2 February 2019 at 20:30:15 UTC, Neia Neutuladh wrote: And consider putting the class in its own source file. Yes, by all means. Speaking of which... Considering the nature of a singleton such the one in the top p

<    1   2   3   4   5   6   >