Re: Mixin operator 'if' directly

2018-12-21 Thread Timoses via Digitalmars-d-learn
On Wednesday, 19 December 2018 at 15:40:50 UTC, Neia Neutuladh wrote: On Wed, 19 Dec 2018 15:12:14 +, bauss wrote: Or while instantiating it: mixin template foo() { int _ignoreme() { if (readln.strip == "abort") throw new AbortException; return 1; } int _alsoIgnoreMe =

Re: Shared static this() not executed for unittest

2018-12-15 Thread Timoses via Digitalmars-d-learn
A look into `dub test --vverbose` showed that ./source/app.d is not even included in the compilcation step...

Shared static this() not executed for unittest

2018-12-15 Thread Timoses via Digitalmars-d-learn
Spec 27.5 states: "Unit tests, when enabled, are run after all static initialization is complete and before the main() function is called. " (https://dlang.org/spec/unittest.html) main.d: --- import std.stdio; shared static this() { import vibe.core.log;

Re: Is it's correct to say that ALL types that can grow are place on heap?

2018-09-12 Thread Timoses via Digitalmars-d-learn
On Wednesday, 12 September 2018 at 14:46:22 UTC, rikki cattermole wrote: On 13/09/2018 2:34 AM, drug wrote: 12.09.2018 15:14, Timoses пишет: On Tuesday, 11 September 2018 at 12:07:14 UTC, drug wrote: If data size is less or equal to total size of available registers (that can be used to

Re: DMD32 compiling gtkd out of memory on 32bit Windows 7 machine

2018-09-12 Thread Timoses via Digitalmars-d-learn
On Wednesday, 12 September 2018 at 06:06:15 UTC, dangbinghoo wrote: hi , When compiling gtkd using dub, dmd32 reported "Out for memory" and exit. OS: Windows 7 32bit. RAM : 3GB DMD version: v2.0.82.0 32bit. No VC or Windows SDK installed, when setting up dmd, I selected install vc2010 and

Re: Is it's correct to say that ALL types that can grow are place on heap?

2018-09-12 Thread Timoses via Digitalmars-d-learn
On Tuesday, 11 September 2018 at 12:07:14 UTC, drug wrote: If data size is less or equal to total size of available registers (that can be used to pass values) than passing by value is more efficient. Passing data with size less than register size by reference isn't efficient because you

Re: "immutable string" vs "const string*"

2018-09-11 Thread Timoses via Digitalmars-d-learn
On Sunday, 9 September 2018 at 08:41:37 UTC, Christian Mayer wrote: On Sunday, 9 September 2018 at 08:14:41 UTC, rikki cattermole wrote: Are you aware that a string is just an alias of immutable(char)[]? Yes, I'm aware of that. But it's the same, for example, with just one char. "immutable

Re: Is it's correct to say that ALL types that can grow are place on heap?

2018-09-11 Thread Timoses via Digitalmars-d-learn
On Saturday, 8 September 2018 at 22:51:17 UTC, Ali Çehreli wrote: On 09/08/2018 02:19 AM, Suliman wrote: > Is it's correct to say that ALL types that can grow are place on heap > and types that not growing (int, char, pointer) are place on stack? The question is not that simple. :) First,

Re: traits getOverload of a template method

2018-09-10 Thread Timoses via Digitalmars-d-learn
On Thursday, 6 February 2014 at 23:06:03 UTC, QAston wrote: How do i get aliases to overloads of a template method like Class A { int a(T)(T tq,T tw); int a(T)(T tq); } __traits(getOverloads, A, "a(int)")doesnt work Is there any way to "select" overloaded template functions? I

Re: Mutable ForwardRange save() method not callable using const object

2018-09-04 Thread Timoses via Digitalmars-d-learn
On Tuesday, 4 September 2018 at 14:26:44 UTC, Steven Schveighoffer wrote: [...] As general advice, I wouldn't expect const to work well with Ranges anyway -- const ranges are useless (you can't iterate them). So not much code is expecting to handle const, including the wrappers that Phobos

Mutable ForwardRange save() method not callable using const object

2018-09-04 Thread Timoses via Digitalmars-d-learn
Hey, I'm fiddling around with ranges a bit and am wondering why save is not callable on a const object: class Range { ForwardRange!(const uint) offsets; this(const S s) { this.offsets = s.s.map!(e => e.i).inputRangeObject; }

Re: Struct immutable data and dict

2018-09-04 Thread Timoses via Digitalmars-d-learn
On Tuesday, 4 September 2018 at 12:27:47 UTC, nkm1 wrote: I also had this problem recently. I think aa.require() should allow to add immutables (feature request). Anyway, my workaround was along the lines of: final class AA(Key, Value) { Value[] _storage; size_t[Key] _aa; void

Re: Struct immutable data and dict

2018-09-04 Thread Timoses via Digitalmars-d-learn
On Thursday, 6 October 2016 at 02:09:44 UTC, Adam D. Ruppe wrote: On Thursday, 6 October 2016 at 01:23:35 UTC, Patric Dexheimer wrote: Why? Because you'd be overwriting that immutable member. Structs just put structure around their contents, but it doesn't change their nature. That struct

Re: Concat enum of strings into one string

2018-08-14 Thread Timoses via Digitalmars-d-learn
On Tuesday, 14 August 2018 at 14:37:33 UTC, Andrey wrote: Thank you. Hmm, I thought that standard library already has this stuff. There might be more elegant solutions and I'd be happy to see some more. I'm always just digging into std.traits [1] and Traits spec part [2] and try to fumble

Re: Concat enum of strings into one string

2018-08-14 Thread Timoses via Digitalmars-d-learn
On Tuesday, 14 August 2018 at 13:42:04 UTC, Andrey wrote: Hello, I have a enum: enum Type : string { One = "Q1", Two = "W2", Three = "R3" } I want to concat it in compile-time: enum result = doConcat!Type(); And get this result: writeln(result); // output: "Q1 W2 R3" Delimiter

Re: How to declare static compile-time assoc array inside struct?

2018-08-13 Thread Timoses via Digitalmars-d-learn
On Monday, 13 August 2018 at 13:21:45 UTC, Andrey wrote: On Monday, 13 August 2018 at 11:53:06 UTC, rikki cattermole wrote: You must use a module constructor to initialize it. Tried this: static this() { Test.DESCRIPTION = [Test.Type.One: "One!", Test.Type.Two: "It's Two...",

Re: Importing struct

2018-08-13 Thread Timoses via Digitalmars-d-learn
On Monday, 13 August 2018 at 14:16:47 UTC, Mike Parker wrote: On Monday, 13 August 2018 at 13:09:24 UTC, Andrey wrote: On Monday, 13 August 2018 at 13:05:28 UTC, evilrat wrote: however the best option is simply avoid naming anything with same name as module. Hmm, I thought that name of class

Re: vibe.d: Finding out if currently in webinterface request

2018-08-10 Thread Timoses via Digitalmars-d-learn
On Thursday, 9 August 2018 at 21:59:24 UTC, Johannes Loher wrote: I already posted this in the vibe.d forums (https://forum.rejectedsoftware.com/groups/rejectedsoftware.vibed/thread/58891/), but it seems, there is not a lot of activity over there, so I am cross posting this here: [...] Do

Re: How do you put log calls in constructors when they may be created in a static context?

2018-08-10 Thread Timoses via Digitalmars-d-learn
On Wednesday, 8 August 2018 at 21:54:34 UTC, aliak wrote: I'm trying to debug stuff, so I want to add verbose logging struct S(T) { this() { writeln("created S(T) with properties and ID"); } } static a = S!int(); // bah I guess users can call this code from any context, but when i'd

Re: Why does templated interface function return something different than final function?

2018-08-08 Thread Timoses via Digitalmars-d-learn
On Monday, 6 August 2018 at 14:27:01 UTC, Timoses wrote: On Thursday, 2 August 2018 at 20:35:57 UTC, Steven Schveighoffer wrote: Looking at the AST, it appears that toImpl doesn't recognize what inout(iface) is: toImpl!(string, inout(iface)) { @system string toImpl(ref inout(iface)

Re: Why does templated interface function return something different than final function?

2018-08-06 Thread Timoses via Digitalmars-d-learn
On Thursday, 2 August 2018 at 20:35:57 UTC, Steven Schveighoffer wrote: Looking at the AST, it appears that toImpl doesn't recognize what inout(iface) is: toImpl!(string, inout(iface)) { @system string toImpl(ref inout(iface) value) { import std.array :

Re: hasUDA with this

2018-07-26 Thread Timoses via Digitalmars-d-learn
On Wednesday, 25 July 2018 at 21:17:38 UTC, jmh530 wrote: On Friday, 20 July 2018 at 18:24:11 UTC, Timoses wrote: [snip] It works in module scope https://run.dlang.io/is/OQKYag I don't know why though... This was reported in 2013. IMO, it should be mentioned in the spec if they don't plan

Re: How to avoid inout type constructor with Optional type wrapper undoing string type

2018-07-25 Thread Timoses via Digitalmars-d-learn
On Tuesday, 24 July 2018 at 14:11:51 UTC, Ali Çehreli wrote: On 07/24/2018 02:47 AM, Timoses wrote: > Why does this fail while it works when replacing T with U in struct > W(T)?? It's so odd. Both T and U seem to resolve to "string". > > struct W(T) { > const T value; >

Re: trait to get the body code of a function?

2018-07-24 Thread Timoses via Digitalmars-d-learn
On Tuesday, 24 July 2018 at 04:43:33 UTC, Guillaume Lathoud wrote: Hello, __traits and std.traits already offer access to function information like input parameters, e.g. in std.traits: ParameterIdentifierTuple ParameterStorageClassTuple Even if that might sound strange, is there a compile

Re: How to avoid inout type constructor with Optional type wrapper undoing string type

2018-07-24 Thread Timoses via Digitalmars-d-learn
On Monday, 23 July 2018 at 18:39:59 UTC, aliak wrote: Hi, I'm playing around with an Optional wrapper type. It stores a type T and a bool that defines whether a value is defined or not: struct Optional(T) { T value; bool defined = false; this(U : T)(auto ref inout(U) value) inout {

Re: How to get an inout constructor working with a template wrapper

2018-07-23 Thread Timoses via Digitalmars-d-learn
On Monday, 23 July 2018 at 12:02:58 UTC, aliak wrote: Thank you Ali! That helped :) I've gotten most of it sorted out now, and the factory wrap is definitely the way to go, it also turned out that inout(T) and inout T (so inout without parens) was surprisingly different (maybe it's a bug? -

Re: hasUDA with this

2018-07-20 Thread Timoses via Digitalmars-d-learn
On Friday, 20 July 2018 at 16:53:12 UTC, jmh530 wrote: Hmm, on that part about the attributes copying their values, I suppose it would be sufficient if I could apply the attributes to a group of declarations. However, it didn't seem to work properly for me with UDAs, and I noticed that even

Re: hasUDA with this

2018-07-20 Thread Timoses via Digitalmars-d-learn
On Thursday, 19 July 2018 at 19:18:43 UTC, jmh530 wrote: I wanted to create a struct with a member function whose behavior was different depending on whether the struct instance had a particular UDA. However, it seems like hasUDA doesn't seem to produce the result I would have expected here.

Re: Member function passed through template alias only requiring `this` in certain conditions?

2018-07-19 Thread Timoses via Digitalmars-d-learn
On Thursday, 19 July 2018 at 22:16:22 UTC, Ali Çehreli wrote: On 07/19/2018 08:12 AM, Emma wrote: > [...] > If I try to compile it, dmd complains, which I guess makes sense: > > --- > Error: need this for bar of type void() > Error: need this for baz of type void() > --- > > [...] I think it's

Re: Implicit conversion of struct with methods to immutable in pure function fails

2018-07-19 Thread Timoses via Digitalmars-d-learn
On Thursday, 19 July 2018 at 06:35:36 UTC, Simen Kjærås wrote: On Wednesday, 18 July 2018 at 11:28:54 UTC, Timoses wrote: But why is a context pointer a problem? Is it problematic because the context pointer to the main scope can not guarantee `immutable`? E.g. if I happened to use data from

Re: Why does templated interface function return something different than final function?

2018-07-18 Thread Timoses via Digitalmars-d-learn
On Wednesday, 18 July 2018 at 11:09:12 UTC, Timoses wrote: Why is the interface templated function not also returning the class C toString return value "in C"?? interface iface { void toString(scope void delegate(const(char)[]) sink) const;

Re: Implicit conversion of struct with methods to immutable in pure function fails

2018-07-18 Thread Timoses via Digitalmars-d-learn
On Tuesday, 17 July 2018 at 06:24:12 UTC, Simen Kjærås wrote: That makes sense. The problem is F has a context pointer to the main() block, since it's a non-static struct with methods inside a block. It doesn't actually use the context pointer for anything, so it possibly shouldn't have one,

Why does templated interface function return something different than final function?

2018-07-18 Thread Timoses via Digitalmars-d-learn
Why is the interface templated function not also returning the class C toString return value "in C"?? interface iface { void toString(scope void delegate(const(char)[]) sink) const; final string convert() inout {

Re: Is it feasible to slowly rewrite a C++ codebase in D?

2018-07-16 Thread Timoses via Digitalmars-d-learn
On Monday, 16 July 2018 at 11:31:32 UTC, Seb wrote: On Monday, 16 July 2018 at 11:12:20 UTC, Dukc wrote: On Saturday, 14 July 2018 at 03:08:50 UTC, Vladimir Panteleev wrote: I'll follow up with Alawain. Regardless, dscripten-tools borrows very little from the redistributable parts of

Re: Implicit conversion of struct with methods to immutable in pure function fails

2018-07-16 Thread Timoses via Digitalmars-d-learn
On Monday, 16 July 2018 at 12:00:57 UTC, Simen Kjærås wrote: On Monday, 16 July 2018 at 11:43:03 UTC, Timoses wrote: Why does this fail? It doesn't. Not using DMD 2.081.1 under Windows, at least. I tried adding a bitfield since you mentioned it, but it compiles nicely for me. Which version

Implicit conversion of struct with methods to immutable in pure function fails

2018-07-16 Thread Timoses via Digitalmars-d-learn
Why does this fail? struct F { int i; ushort _x; void x(ushort v) pure {_x = v;} ushort x() const { return _x; } } immutable F f1 = () pure { F lf = F(); return lf; }(); // Error: cannot implicitly convert expression

Re: Is there any tool that will auto publish my changes.

2018-07-16 Thread Timoses via Digitalmars-d-learn
On Sunday, 15 July 2018 at 00:25:22 UTC, Venkat wrote: I am writing a simple vibe.d app. The following is what I do right now. - I make changes. - build - Restart the server. Is there any tool that will auto publish my changes as I save them ? I am using Visual Studio Code. Thanks Venkat

Re: Find out druntime/import and phobos folder on Linux

2018-07-15 Thread Timoses via Digitalmars-d-learn
On Saturday, 14 July 2018 at 19:04:01 UTC, Andre Pany wrote: On Saturday, 14 July 2018 at 19:00:56 UTC, Anonymouse wrote: On Saturday, 14 July 2018 at 17:19:20 UTC, Andre Pany wrote: Is there a way to find out both paths based on the dmd executable folder? What I found out so far, these

Re: Call method with Variant array as parameters

2018-07-14 Thread Timoses via Digitalmars-d-learn
On Saturday, 14 July 2018 at 11:08:21 UTC, Andre Pany wrote: Hi, I have a class with methods and I want to call a method by using a variant array. The length of the array and the types exactly fits the method signature. In the last line of main you see the coding which should be generated.

Re: @safe - why does this compile?

2018-07-14 Thread Timoses via Digitalmars-d-learn
On Friday, 13 July 2018 at 22:17:59 UTC, Dukc wrote: On Friday, 13 July 2018 at 13:52:27 UTC, Timoses wrote: I suppose this is another good example of how casting can be dangerous? E.g. also: immutable int i = 3; int* j = cast(int*) assert(i == 3); *j = 4; assert(j ==

Re: Orange not working?

2018-07-14 Thread Timoses via Digitalmars-d-learn
On Friday, 13 July 2018 at 21:38:18 UTC, JN wrote: I'm curious, are the tests in any way OS specific? I see the tests are passing, but trying the latest DMD on Windows and orange v2.0.0, when I add "@nonSerialized" to a struct member, I get this: C:\Users\jacek\Desktop\test_orange>dub run

Re: @safe - why does this compile?

2018-07-13 Thread Timoses via Digitalmars-d-learn
On Friday, 13 July 2018 at 11:04:40 UTC, Piotr Mitana wrote: This code: import std.stdio; class X1 {} class X2 : X1 { void run() @safe { writeln("DONE"); } } void main() @safe { X1 x1 = new X1; X2 x2 = cast(X2)

Re: Orange not working?

2018-07-13 Thread Timoses via Digitalmars-d-learn
On Friday, 13 July 2018 at 05:39:24 UTC, JN wrote: On Friday, 13 July 2018 at 05:29:58 UTC, Timoses wrote: On Thursday, 12 July 2018 at 20:44:43 UTC, JN wrote: I am trying to make use of the Orange package, I added the latest version from dub to my project: "orange": "~>1.0.0" and copy pasted

Re: Orange not working?

2018-07-12 Thread Timoses via Digitalmars-d-learn
On Thursday, 12 July 2018 at 20:44:43 UTC, JN wrote: I am trying to make use of the Orange package, I added the latest version from dub to my project: "orange": "~>1.0.0" and copy pasted the "simple usage" code from https://github.com/jacob-carlborg/orange , but I am getting a long list of

Re: Troubles creating templated inout objects

2018-07-12 Thread Timoses via Digitalmars-d-learn
On Thursday, 12 July 2018 at 12:22:34 UTC, Steven Schveighoffer wrote: On 7/11/18 8:55 AM, Timoses wrote: class TestA(T : T[]) {     Test!T[] arr;     // ERROR: Can't initialize inout variable in a for loop...     this(inout(T[]) arr) inout     {    

Re: Troubles creating templated inout objects

2018-07-12 Thread Timoses via Digitalmars-d-learn
On Tuesday, 10 July 2018 at 14:34:55 UTC, Timoses wrote: `Unqual` in this case just turns `inout(int[])` into `inout(int)[]`, which is why it complains. That's a side effect of this example [...] See also: https://issues.dlang.org/show_bug.cgi?id=3567

Re: Troubles creating templated inout objects

2018-07-12 Thread Timoses via Digitalmars-d-learn
On Wednesday, 11 July 2018 at 12:55:35 UTC, Timoses wrote: On Tuesday, 10 July 2018 at 18:01:59 UTC, Steven Schveighoffer wrote: You are overthinking :) inout typically is much easier than you expect, until you need to create temporary structs or types with inout members, then it becomes

Re: Using dub and rdmd together?

2018-07-11 Thread Timoses via Digitalmars-d-learn
On Wednesday, 11 July 2018 at 16:43:24 UTC, Seb wrote: I don't know of an easy way to do out of the box. However, with dmd's new -i option, it could be as easy as: --- dub fetch requests cat > test.d << EOF import std.stdio; import requests; void main() { auto content =

Re: Troubles creating templated inout objects

2018-07-11 Thread Timoses via Digitalmars-d-learn
On Tuesday, 10 July 2018 at 18:01:59 UTC, Steven Schveighoffer wrote: You are overthinking :) inout typically is much easier than you expect, until you need to create temporary structs or types with inout members, then it becomes problematic. https://run.dlang.io/is/kosYuC I had to put in a

Re: taskPool.reduce vs algorithm.reduce

2018-07-11 Thread Timoses via Digitalmars-d-learn
On Wednesday, 11 July 2018 at 08:31:30 UTC, Dorian Haglund wrote: Hi. I'm trying to use taskPool.reduce with a delegate, for example: import std.parallelism; int main(string[] args) { int f(int a, int b) { if (args.length > 1) return a+b; else return a-b; } auto

Re: Passing function(whose parameter would be dynamic and the type is unknown) as a parameter to another function.

2018-07-10 Thread Timoses via Digitalmars-d-learn
On Tuesday, 10 July 2018 at 14:58:42 UTC, vino.B wrote: Hi Alex, I am getting the output as tuples of multiple arrays, but the requirement is to get the all the tuple in a single array like the below so that we can perform sorting and printing the output is easy. Something along the way

Troubles creating templated inout objects

2018-07-10 Thread Timoses via Digitalmars-d-learn
How do I create an inout object with template parameters? Take following code: import std.stdio; import std.traits; struct S { int[] arr; } interface I { inout(I) opIndex(size_t idx) inout; }

Re: guard clause style static if

2018-07-10 Thread Timoses via Digitalmars-d-learn
On Tuesday, 10 July 2018 at 12:10:27 UTC, Jonathan M Davis wrote: On Tuesday, 10 July 2018 05:38:33 MDT kdevel via Digitalmars-d-learn wrote: I would like to suggest an extension of the language by introducing static return Expression_opt; which shall have the effect of a return plus

Re: guard clause style static if

2018-07-10 Thread Timoses via Digitalmars-d-learn
On Tuesday, 10 July 2018 at 12:05:11 UTC, kdevel wrote: On Saturday, 7 July 2018 at 13:12:59 UTC, Alex wrote: The site you cited for the guard clause above (c2.com) works at runtime. ? static if works at compile team and only inserts code into the final code for run-time depending on the

Re: Passing function(whose parameter would be dynamic and the type is unknown) as a parameter to another function.

2018-07-09 Thread Timoses via Digitalmars-d-learn
On Monday, 9 July 2018 at 05:54:27 UTC, vino.B wrote: On Sunday, 8 July 2018 at 19:22:32 UTC, Timoses wrote: Perhaps you could tell us what your goal is. People here might come up with a nice solution. Why do you feel like having to use templated functions in the first place? That is, what is

Re: Passing function(whose parameter would be dynamic and the type is unknown) as a parameter to another function.

2018-07-08 Thread Timoses via Digitalmars-d-learn
On Sunday, 8 July 2018 at 18:46:31 UTC, vino.B wrote: Hi All, Request you help, in the below code we pass the function "Testfun" as a parameter to another function "process" in order for the function "process" to work we have to specify the type of the parameter that is passed to the

Re: Outside array bounds

2018-07-07 Thread Timoses via Digitalmars-d-learn
On Saturday, 7 July 2018 at 15:25:51 UTC, vino.B wrote: Hi All, If we replace the statement as args[$ -1] the program works are expected, if we apply the same logic in different approach it does not work, in the below code if we command the first block "if (fnID == "ListFilesNames") {} "

Re: Outside array bounds

2018-07-07 Thread Timoses via Digitalmars-d-learn
On Saturday, 7 July 2018 at 08:35:27 UTC, Alex wrote: On Saturday, 7 July 2018 at 08:24:21 UTC, Timoses wrote: Interesting.. Looks like the compiler does some boundschecking during compile time. You could circumvent this: void process(T ...)(string ID, T args) { if (ID == "I1") {

Re: Outside array bounds

2018-07-07 Thread Timoses via Digitalmars-d-learn
On Saturday, 7 July 2018 at 08:09:51 UTC, vino.B wrote: Hi All, Request you help, on the below code import std.stdio: writeln; void process(T ...)(string ID, T args) { if (ID == "I1") { writeln(args.length, "\t", args[0]); } else if (ID == "I2") { writeln(args.length, "\t", args[1]);} }

Re: how to link self made lib using dub

2018-07-06 Thread Timoses via Digitalmars-d-learn
On Friday, 6 July 2018 at 17:08:48 UTC, Flaze07 wrote: [...] then, I made a project, with this main in this path : Z:\programming\D\experimentLib\source\main.d it contains this module main; import std.stdio; import source.output; Shouldn't this be 'import output'? void main( string[]

Re: immutable / inout / pure headaches

2018-07-06 Thread Timoses via Digitalmars-d-learn
On Friday, 6 July 2018 at 15:44:28 UTC, Steven Schveighoffer wrote: I'm long overdue for an inout article... I can point you at my talk from 2016: https://www.youtube.com/watch?v=UTz55Lv9FwQ Thanks, will definitely take a look when I get home. I never really used 'pure' and just now

Re: Passing a reference to a returned reference

2018-07-06 Thread Timoses via Digitalmars-d-learn
On Friday, 6 July 2018 at 15:51:34 UTC, Michael wrote: Also, yes, I am using the setter method to play around with the precision of the double values, and do some normalising. While writing I realized that the following is even the case without the 'ref' parameter: The caller of the setter will

Re: Passing a reference to a returned reference

2018-07-06 Thread Timoses via Digitalmars-d-learn
On Friday, 6 July 2018 at 15:33:18 UTC, Michael wrote: This is definitely to do with my use of the setter syntax, which maybe I am misunderstanding? Because if I change it to a normal function call like so: a.beliefs(Operator.create()); then it complains if I use ref, and doesn't complain

Re: Passing a reference to a returned reference

2018-07-06 Thread Timoses via Digitalmars-d-learn
On Friday, 6 July 2018 at 15:14:01 UTC, Michael wrote: class Agent { private { double[int] mDict; } // Setter: copy void beliefs(ref double[int] dict) { import std.stdio : writeln; writeln("Setter function."); this.mDict = dict; }

Re: immutable / inout / pure headaches

2018-07-06 Thread Timoses via Digitalmars-d-learn
On Friday, 6 July 2018 at 14:28:39 UTC, Steven Schveighoffer wrote: inout is not a compile-time wildcard, it's a runtime one. So it doesn't know how to convert an immutable to an inout. Essentially, inside this function, the compiler has no idea whether the real thing is an immutable, const,

Re: Passing a reference to a returned reference

2018-07-06 Thread Timoses via Digitalmars-d-learn
On Friday, 6 July 2018 at 13:13:43 UTC, Michael wrote: static auto ref consensus( ... ) `auto ref` infers the return type from the return statement [1]. So it's not necessarily returning a ref type. However, I don't think this matters if the only concern you have is that the setter

immutable / inout / pure headaches

2018-07-06 Thread Timoses via Digitalmars-d-learn
I dared once again getting into immutable by adding an "immutable" keyword which causes a chain of actions to be taken. I feel like I'm lost in a jungle of immutable, inout and pure (perhaps more will join the party...). To start off, why does this not work? class Test {

Re: Function Template for Dynamic Parameter

2018-07-06 Thread Timoses via Digitalmars-d-learn
On Thursday, 5 July 2018 at 16:23:36 UTC, vino.B wrote: Hi All, Request your help on the below code auto coCleanFiles(T ...) (T FFs) { auto dFiles = Array!(Tuple!(string, SysTime))(dirEntries(FFs, SpanMode.depth).map!(a => tuple(a.name, a.timeCreated))); return dFiles; } void

Re: Safe to cast to immutable and return?

2018-07-05 Thread Timoses via Digitalmars-d-learn
On Thursday, 5 July 2018 at 12:15:35 UTC, vit wrote: Try pure functions: class A {} A getA()pure @safe //pure whitout mutable parameters guarantees that function doesn't leak data. { A a; // .. do stuff with a // not leaking a to any functions // is this safe

Re: 'is(T==return)' How does is expression with return keyword as TypeSpecialization

2018-07-05 Thread Timoses via Digitalmars-d-learn
On Thursday, 5 July 2018 at 10:32:01 UTC, Timoses wrote: int fun(T)(T i) { static assert(is(typeof(return) == T)); //true pragma(msg, is(T == return)); // false static if (is(T ReturnType == return)) pragma(msg, ReturnType); // does not enter

Re: 'is(T==return)' How does is expression with return keyword as TypeSpecialization

2018-07-05 Thread Timoses via Digitalmars-d-learn
On Thursday, 5 July 2018 at 11:37:16 UTC, Timoses wrote: I think it refers to this section: https://dlang.org/spec/expression.html#is_expression should mention that I mean the 6th paragraph.

Re: 'is(T==return)' How does is expression with return keyword as TypeSpecialization

2018-07-05 Thread Timoses via Digitalmars-d-learn
On Thursday, 5 July 2018 at 11:21:41 UTC, Alex wrote: On Thursday, 5 July 2018 at 10:32:01 UTC, Timoses wrote: int fun(T)(T i) { static assert(is(typeof(return) == T)); //true pragma(msg, is(T == return)); // false static if (is(T ReturnType == return))

Safe to cast to immutable and return?

2018-07-05 Thread Timoses via Digitalmars-d-learn
Is this safe? class A {} immutable(A) getA() { A a; // .. do stuff with a // not leaking a to any functions // is this safe return cast(immutable A)a; } What if A is replaced with A[] or A[int]? If it's not safe, what would be the proper way to return an immutable

'is(T==return)' How does is expression with return keyword as TypeSpecialization

2018-07-05 Thread Timoses via Digitalmars-d-learn
int fun(T)(T i) { static assert(is(typeof(return) == T)); //true pragma(msg, is(T == return)); // false static if (is(T ReturnType == return)) pragma(msg, ReturnType); // does not enter return i; } unittest { fun(3); }

Re: ranges.chunks and map! does not work

2018-07-05 Thread Timoses via Digitalmars-d-learn
On Thursday, 5 July 2018 at 09:47:32 UTC, Andre Pany wrote: Hi, the purpose of this code is to generate CSV based on 3 double arrays. I wonder why map cannot directly use the result of the chunks function. import std.experimental.all; void main() { double[] timestamps = [1.1];

Re: how to import file from another path in dub ?

2018-07-05 Thread Timoses via Digitalmars-d-learn
On Thursday, 5 July 2018 at 05:38:29 UTC, Flaze07 wrote: I have a dub project, and I put the importPath to the path of the file I want to import and the source file to the source folder, and it appears that I have succeeded at importing the module, but there's one problem, it appears like I

Re: Inference of auto storage classes for interface function return type

2018-07-04 Thread Timoses via Digitalmars-d-learn
On Wednesday, 4 July 2018 at 15:12:15 UTC, Jonathan M Davis wrote: You can make opIndex inout instead of const. That way, inout applies to the invisible this reference, just like it would with const. Awww, thanks! I was kinda hovering around this[1] section and didn't quite see the

Inference of auto storage classes for interface function return type

2018-07-04 Thread Timoses via Digitalmars-d-learn
How can I return inferred storage class from interface functions? I can't use auto as return value in interface. Neither can I use "inout" as I don't pass a parameter. // Ref Type interface IRef { Ref opIndex(size_t idx) const; } class

Re: template alias that includes a parameter

2018-07-01 Thread Timoses via Digitalmars-d-learn
On Sunday, 1 July 2018 at 13:01:20 UTC, Timoses wrote: Aw, okay, then that won't work. Still, this looks like it should work: void foo(F, T)(T param) { writeln("Called with type: ", T.stringof); } alias tfoo = ApplyLeft!(foo, int); tfoo!string("hi"); // tfoo("hi"); // Error

Re: template alias that includes a parameter

2018-07-01 Thread Timoses via Digitalmars-d-learn
On Sunday, 1 July 2018 at 11:55:15 UTC, Simen Kjærås wrote: On Sunday, 1 July 2018 at 09:46:55 UTC, Timoses wrote: Would be nice if std.meta.ApplyLeft did the job here.. Is there no way of achieving that? [snip] Would have to find a way to determine whether Template would resolve to a

Re: Function Template for Dynamic Parameter

2018-07-01 Thread Timoses via Digitalmars-d-learn
On Sunday, 1 July 2018 at 11:58:30 UTC, vino.B wrote: On Sunday, 1 July 2018 at 11:52:19 UTC, Alex wrote: NewType.d(19): Error: function declaration without return type. (Note that constructors are always named this) [...] auto coCleanFiles(T ...)(T args) { auto dFiles =

Re: Function Template for Dynamic Parameter

2018-07-01 Thread Timoses via Digitalmars-d-learn
On Sunday, 1 July 2018 at 11:19:50 UTC, vino.B wrote: On Sunday, 1 July 2018 at 09:55:34 UTC, Timoses wrote:> Hi Timoses, Thank you very much, can you help me on how to rewrite the below using Variadic template Passing function as a parameter to another function: void ptFun(T)(T

Re: Function Template for Dynamic Parameter

2018-07-01 Thread Timoses via Digitalmars-d-learn
On Sunday, 1 July 2018 at 09:46:32 UTC, vino.B wrote: All, Request your help, the D document states that "Template functions are useful for avoiding code duplication - instead of writing several copies of a function, each with a different parameter type, a single function template can be

Re: template alias that includes a parameter

2018-07-01 Thread Timoses via Digitalmars-d-learn
On Sunday, 1 July 2018 at 01:48:15 UTC, Simen Kjærås wrote: I'd send you straight to std.meta.ApplyLeft, but it seems to do the wrong thing here, in that it doesn't handle IFTI. This thing does: void fooImpl(int n, T)(const T line) { } unittest { alias fun = applyLeft!(fooImpl, 3);

Re: Call different member functions on object sequence with a generic handler function?

2018-07-01 Thread Timoses via Digitalmars-d-learn
On Sunday, 1 July 2018 at 06:55:35 UTC, Robert M. Münch wrote: The looping needs to be done in the handler because there are two loops running one after the other and the range to loop over is detected in the handler too. Otherwise a lot of code duplication would happen. Maybe an

Re: template alias that includes a parameter

2018-06-30 Thread Timoses via Digitalmars-d-learn
On Saturday, 30 June 2018 at 21:11:54 UTC, Anonymouse wrote: I have a template that I want to provide easy aliases for, where the aliases includes (partially applies?) a template parameter. void fooImpl(char token, T)(const T line) { // ... } alias quoteFoo(T) = fooImpl!('"', T);

Re: Call different member functions on object sequence with a generic handler function?

2018-06-29 Thread Timoses via Digitalmars-d-learn
On Friday, 29 June 2018 at 20:28:55 UTC, Timoses wrote: On Friday, 29 June 2018 at 16:44:36 UTC, Robert M. Münch wrote: Trying to fiddle around a bit with delegates.. But why is the context for delegates not working for classes?? Aw.. Class = reference type so class A { } struct B { } void

Re: Call different member functions on object sequence with a generic handler function?

2018-06-29 Thread Timoses via Digitalmars-d-learn
On Friday, 29 June 2018 at 16:44:36 UTC, Robert M. Münch wrote: I hope this is understandable... I have: class C { void A(); void B(); void C(); } I'm iterating over a set of objects of class C like: foreach(obj; my_selected_objs){ ... } The iteration and code

Re: Call different member functions on object sequence with a generic handler function?

2018-06-29 Thread Timoses via Digitalmars-d-learn
On Friday, 29 June 2018 at 20:08:56 UTC, Robert M. Münch wrote: On 2018-06-29 18:05:00 +, Ali ‡ehreli said: On 06/29/2018 09:44 AM, Robert M. Münch wrote: void handler(alias func)(C[] cs) { foreach (c; cs) { func(c); } } Is it possible to make C[] a template type so

Re: Issues with undefined symbols when using Vibe on Windows

2018-06-29 Thread Timoses via Digitalmars-d-learn
On Friday, 29 June 2018 at 19:25:42 UTC, Chris M. wrote: This doesn't appear to specifically be a Vibe issue, just noticing this error when I use eventcore from it (trying to use async). C:\dmd2\windows\bin\lld-link.exe: warning: eventcore.lib(sockets_101f_952.obj): undefined symbol:

Re: Why tuples are not ranges?

2018-06-28 Thread Timoses via Digitalmars-d-learn
On Thursday, 28 June 2018 at 14:35:33 UTC, Mr.Bingo wrote: Seems like it would unify things quite a bit. import std.typecons, std.range, std.array, std.algorithm, std.stdio; void main() { auto t = tuple(3,4,5,6); //auto t = [3,4,5,6]; writeln(t.map!(a =>

Re: Getting Source code from complied code.

2018-06-28 Thread Timoses via Digitalmars-d-learn
On Thursday, 28 June 2018 at 08:01:42 UTC, vino.B wrote: Hi All, Request your help on how to get the source code, i wrote a program named clean.d, complied it and by mistake deleted the source code(clean.d), so can we get back the source using the complied program(clean), if yes, can you

Re: anyway to pass the context of an inner type to a template so it can be constructed?

2018-06-27 Thread Timoses via Digitalmars-d-learn
On Wednesday, 27 June 2018 at 12:02:10 UTC, aliak wrote: This currently fails unless you mark the class as static: auto construct(T)() { return new T; } void main() { class C {} auto s = construct!C; } So wondering if there's anything that can be done to get the above working?

Re: Making sense of recursion

2018-06-26 Thread Timoses via Digitalmars-d-learn
On Monday, 25 June 2018 at 17:45:01 UTC, zbr wrote: Hi, this question is not specifically D related but I'll just ask anyway. Consider the following snippet: void mergeSort(int[] arr, int l, int r) { if (l < r) // 1 { int m = l+(r-l)/2;// 2

Re: Using systemDependencies in DUB

2018-06-24 Thread Timoses via Digitalmars-d-learn
On Sunday, 24 June 2018 at 11:44:06 UTC, Dechcaudron wrote: Hi, I'm trying to use dub to compile a quick experiment that uses Deimos libclang bindings, which of course requires linking against an installed libclang. I believe this is what I need to include in dub.json:

Re: Can I parse this kind of HTML with arsd.dom module?

2018-06-24 Thread Timoses via Digitalmars-d-learn
On Sunday, 24 June 2018 at 03:46:09 UTC, Dr.No wrote: string html = get(page, client).text; auto document = new Document(); document.parseGarbage(html); Element attEle = document.querySelector("span[id=link2]"); Element aEle = attEle.querySelector("a"); string

Re: Is HibernateD dead?

2018-06-23 Thread Timoses via Digitalmars-d-learn
On Thursday, 3 May 2018 at 10:27:47 UTC, Pasqui23 wrote: Last commit on https://github.com/buggins/hibernated was almost a year ago So what is the status of HibernateD?Should I use it if I need an ORM? Or would I risk unpatched security risks? Okay... wall of text. TLDR: project definition /

Re: Convert path to file system path on windows

2018-06-21 Thread Timoses via Digitalmars-d-learn
On Thursday, 21 June 2018 at 18:46:05 UTC, Dr.No wrote: How can I do that with D? In C# you can do that: var filename = @"C:\path\to\my\file.txt"; var file = new Uri(filename).AbsoluteUri; // file is "file:///C:/path/to/my/file.txt" How can I do that in D? I don't know of a specific

Re: scope(success) lowered to try-catch ?

2018-06-17 Thread Timoses via Digitalmars-d-learn
On Sunday, 17 June 2018 at 10:58:29 UTC, Cauterite wrote: Hello, I'm not sure whether I'm missing something obvious here, but is there a reason for scope(success) being lowered to a try-catch statement? I would have expected only scope(exit) and scope(failure) to actually interact with

Re: foreach DFS/BFS for tree data-structure?

2018-06-16 Thread Timoses via Digitalmars-d-learn
On Thursday, 14 June 2018 at 11:31:50 UTC, Robert M. Münch wrote: I have a simple tree C data-structure that looks like this: node { node parent: vector[node] children; } I would like to create two foreach algorthims, one follwing the breadth first search pattern and one the

  1   2   >