Re: Does D has built-in stack structure?

2015-06-22 Thread Adrian Matoga via Digitalmars-d-learn
On Monday, 22 June 2015 at 06:09:48 UTC, Assembly wrote: Does D has built-in stack structure (if so, which module?) or should I implement it myself? AFAIK there's no built-in, but std.array.Appender could be easily wrapped in an interface that makes thinking of it as stack easier: struct

Re: Problem with map, reduce, ..

2015-06-24 Thread Adrian Matoga via Digitalmars-d-learn
On Wednesday, 24 June 2015 at 08:30:29 UTC, Adrian Matoga wrote: input.byLine() yields char[]'s as range elements, while props is (correctly) indexed by strings, i.e. immutable(char)[]. Ooops, more precisely it's because of the second argument of add() being string, but the solution above

Re: Problem with map, reduce, ..

2015-06-24 Thread Adrian Matoga via Digitalmars-d-learn
On Wednesday, 24 June 2015 at 08:18:52 UTC, Stefan wrote: I tried to refactor some existing code to use more of the functional patterns/style (map, filter, reduce, ..). The task is to read in some sort of a simple property file and present the result as an associative array. My attempt is:

Re: Problem with map, reduce, ..

2015-06-24 Thread Adrian Matoga via Digitalmars-d-learn
On Wednesday, 24 June 2015 at 08:58:10 UTC, Stefan wrote: On Wednesday, 24 June 2015 at 08:33:29 UTC, Adrian Matoga wrote: On Wednesday, 24 June 2015 at 08:30:29 UTC, Adrian Matoga wrote: input.byLine() yields char[]'s as range elements, while props is (correctly) indexed by strings, i.e.

Re: How to use std.experimental.logger?

2015-10-01 Thread Adrian Matoga via Digitalmars-d-learn
On Thursday, 1 October 2015 at 08:21:35 UTC, Panke wrote: I tried it on Windows today using the latest DMD installer, all default logger and settings. I get: safe function [...].logImplf cannot call system function 'std.format.formattedWrite!(MsgRange, char, Result!()).formattedWrite' How

Re: How to return user name from vibed session?

2015-12-10 Thread Adrian Matoga via Digitalmars-d-learn
On Thursday, 10 December 2015 at 11:36:20 UTC, Suliman wrote: Vibed have method get for user session http://vibed.org/api/vibe.http.session/SessionStore I set user name for session like this: req.session.set("username", "admin"); But I can't understand how to get user name from it: abstract

Re: Socket - handling large numbers of incoming connections

2015-12-21 Thread Adrian Matoga via Digitalmars-d-learn
On Monday, 21 December 2015 at 21:32:55 UTC, Jakob Jenkov wrote: My server uses "poll" for that. Okay, how does that work? How do I use "poll" in D? Link? Code example? The same as in C [1]. Just change #include to import core.sys.posix.poll; [1] http://linux.die.net/man/2/poll

Re: Parse File at compile time, but not embedded

2016-06-10 Thread Adrian Matoga via Digitalmars-d-learn
On Tuesday, 7 June 2016 at 22:09:58 UTC, Alex Parrill wrote: Not necessarily, You chased that rabbit quite far! The data your reading could contain sensitive information only used at compile time and not meant to embed. For example, the file could contain login and password to an SQL database

is(some template instantiation) is true, but the actual instantiation fails

2016-01-29 Thread Adrian Matoga via Digitalmars-d-learn
Code: struct HasFoo { void foo() {} } struct NoFoo {} struct CallsFoo(T) { T t; void bar() { t.foo(); } } static assert(is(CallsFoo!HasFoo)); alias Bar = CallsFoo!HasFoo; static assert(is(CallsFoo!NoFoo)); // (1) //alias Baz = CallsFoo!NoFoo; // (2) This

Re: is(some template instantiation) is true, but the actual instantiation fails

2016-01-29 Thread Adrian Matoga via Digitalmars-d-learn
On Friday, 29 January 2016 at 16:36:01 UTC, Steven Schveighoffer wrote: On 1/29/16 10:28 AM, Adrian Matoga wrote: Code: struct HasFoo { void foo() {} } struct NoFoo {} struct CallsFoo(T) { T t; void bar() { t.foo(); } } static assert(is(CallsFoo!HasFoo)); alias Bar =

Re: how to allocate class without gc?

2016-01-26 Thread Adrian Matoga via Digitalmars-d-learn
On Tuesday, 26 January 2016 at 01:09:50 UTC, Igor wrote: Is there any examples that shows how to properly allocate an object of a class type with the new allocators and then release it when desired? There's an example of class object allocation in the std.experimental.allocator docs: //

Re: is(some template instantiation) is true, but the actual instantiation fails

2016-01-30 Thread Adrian Matoga via Digitalmars-d-learn
On Friday, 29 January 2016 at 23:44:56 UTC, Basile B. wrote: Haven't you seen my answer about constraint ? If you put a constraint on your function template then invalid instantiations are rejected. I mean... this language feature is not just ornamental... What do you think constraints are

Re: is(some template instantiation) is true, but the actual instantiation fails

2016-01-30 Thread Adrian Matoga via Digitalmars-d-learn
On Saturday, 30 January 2016 at 00:16:21 UTC, Ali Çehreli wrote: > https://issues.dlang.org/show_bug.cgi?id=15623 As I noted on the bug report, they are work when moved from module scope to inside a function (e.g. main()). At least there's that workaround... Ali Thanks a lot! Now I can

Re: Member Access Based On A Runtime String

2016-03-01 Thread Adrian Matoga via Digitalmars-d-learn
On Tuesday, 1 March 2016 at 05:05:40 UTC, Jack Stouffer wrote: In Python, I can do this: my_obj = Obj() string_from_func = func() setattr(my_obj, string_from_func, 100) Say func() returns "member1" or "member2", the setattr would then set either one of those to 100. Is there any

Re: Member Access Based On A Runtime String

2016-03-01 Thread Adrian Matoga via Digitalmars-d-learn
On Tuesday, 1 March 2016 at 08:53:20 UTC, Adrian Matoga wrote: static if (is(Q : T)) { Oops, should be T : Q

Re: Template mixins and struct constructors

2016-03-02 Thread Adrian Matoga via Digitalmars-d-learn
On Wednesday, 2 March 2016 at 12:48:47 UTC, Daniel Kozak wrote: On Wednesday, 2 March 2016 at 12:27:04 UTC, Adrian Matoga wrote: (...) You can use string mixins: template AddField(T) { enum AddField = T.stringof ~ ` b; this(Args...)(` ~ T.stringof ~ ` b, auto ref Args args)

Re: Template mixins and struct constructors

2016-03-02 Thread Adrian Matoga via Digitalmars-d-learn
On Wednesday, 2 March 2016 at 14:36:59 UTC, Daniel Kozak wrote: OK maybe this one: template AddField(T) { T b; this(Args...)(T b, auto ref Args args) { this.b = b; this(args); } this(int a) { this.a = a; } } struct Bar { int a; mixin

Template mixins and struct constructors

2016-03-02 Thread Adrian Matoga via Digitalmars-d-learn
I can do this: struct Foo { int a; string b; this(int a) { this.a = a; } this(Args...)(string b, auto ref Args args) { this.b = b; this(args); } } unittest { auto foo1 = Foo(5); auto foo2 = Foo("foo", 15); } However, the following code is invalid:

Re: Template mixins and struct constructors

2016-03-03 Thread Adrian Matoga via Digitalmars-d-learn
On Wednesday, 2 March 2016 at 20:39:57 UTC, Adam D. Ruppe wrote: On Wednesday, 2 March 2016 at 12:27:04 UTC, Adrian Matoga wrote: Is it by design or is it a bug? And, if it is by design, what is the reason for that? That's by design. It allows you to override names from a template mixin like

Re: Joining AliasSeq/TypeTuple s

2016-03-30 Thread Adrian Matoga via Digitalmars-d-learn
On Tuesday, 29 March 2016 at 10:06:43 UTC, Adrian Matoga wrote: (...) Another version that doesn't misbehave if first and second are of different lengths: import std.meta : AliasSeq; template RR(A...) { template With(B...) { static if (A.length == 0 || B.length ==

Re: Joining AliasSeq/TypeTuple s

2016-03-29 Thread Adrian Matoga via Digitalmars-d-learn
On Tuesday, 29 March 2016 at 09:33:40 UTC, Voitech wrote: Hi, i want to join two or more tupples in to one, with mixing the indexes like roundRobin but in compile time. unittest{ import std.meta; alias first=AliasSeq!(int, string,bool); alias second=AliasSeq!("abc","def","ghi"); alias

Re: Anonymous structure

2016-04-19 Thread Adrian Matoga via Digitalmars-d-learn
On Monday, 18 April 2016 at 15:59:11 UTC, Steven Schveighoffer wrote: I wonder if it makes a difference for layout. So for example: struct T { struct { int x; ubyte y; } ubyte z; } If there is padding inserted between y and z. There isn't. T.init.z.offsetof -

Re: RAII

2017-02-23 Thread Adrian Matoga via Digitalmars-d-learn
On Thursday, 23 February 2017 at 09:52:26 UTC, Arun Chandrasekaran wrote: I'm trying to write an RAII wrapper on Linux. I understand struct in D doesn't have default constructor (for .init reasons). I don't want to use `scope`. Is there an elegant way to achieve this in D? static opCall()

Re: Why can't static arrays be sorted?

2016-10-06 Thread Adrian Matoga via Digitalmars-d-learn
On Thursday, 6 October 2016 at 09:17:08 UTC, pineapple wrote: On Wednesday, 5 October 2016 at 19:30:01 UTC, Jonathan M Davis wrote: Would just like to point out that this is design weirdness on Phobos' part - the library I've been writing does not have this problem. It doesn't even make

Re: Why can't static arrays be sorted?

2016-10-04 Thread Adrian Matoga via Digitalmars-d-learn
On Tuesday, 4 October 2016 at 20:05:15 UTC, TheGag96 wrote: I was writing some code today and ran into this oddity that I'd never come across before: import std.algorithm : sort; int[10] arr = [0, 3, 4, 6, 2, 1, 1, 4, 6, 9]; thing.sort(); This doesn't compile. Obviously the .sort

Re: Is it possible to avoid call to destructor for structs?

2017-09-25 Thread Adrian Matoga via Digitalmars-d-learn
On Sunday, 24 September 2017 at 19:52:52 UTC, bitwise wrote: On Sunday, 24 September 2017 at 17:11:26 UTC, Haridas wrote: In the following code, Bar is an element of struct Foo. Is there a way to avoid a call to ~Bar when ~Foo is getting executed? Don't construct it to begin with. struct