Using RefCounted in recursive structures and templates

2016-05-10 Thread Lodovico Giaretta via Digitalmars-d-learn
Hi, I'm trying to use std.typecons.RefCounted on recursive structures to emulate garbage-collected classes, but it doesn't work, because the RefCounted implementation ends up creating a cycle in the structure hierarchy. import std.typecons: RefCounted; struct S { RefCounted!S s; // erro

Re: Using RefCounted in recursive structures and templates

2016-05-11 Thread Lodovico Giaretta via Digitalmars-d-learn
On Tuesday, 10 May 2016 at 22:10:06 UTC, ag0aep6g wrote: Am 10.05.2016 um 21:43 schrieb Lodovico Giaretta: import std.typecons: RefCounted; struct S { RefCounted!S s; // error: struct S no size yet for forward reference } This used to work with 2.067. I've filed a phobos regression fo

Struct literals and AA literals

2016-05-23 Thread Lodovico Giaretta via Digitalmars-d-learn
Hi, Today I stumbled upon this weird error: struct ConfigContainer { Config[string] configs; } struct Config { string foo; string bar; } enum ConfigContainer cc = { configs: [// error: not an associative array initializer

Re: Struct literals and AA literals

2016-05-24 Thread Lodovico Giaretta via Digitalmars-d-learn
On Tuesday, 24 May 2016 at 06:59:18 UTC, Jacob Carlborg wrote: What we need is something like this [1]: auto c = Config{ foo: "foo", bar: "bar }; The compiler will know for sure that "c" is of type Config because the right side includes the type. [1] https://issues.dlang.org/show_bug.cgi?id=

@trusting generic functions

2016-05-28 Thread Lodovico Giaretta via Digitalmars-d-learn
Let's say I have a generic function that uses pointers. It will be inferred @system by the compiler, but I know that the pointer usage can be @trusted. The problem is that if I declare the function @trusted, I'm also implicitly trusting any call to @system methods of the template parameter. D

Re: @trusting generic functions

2016-05-28 Thread Lodovico Giaretta via Digitalmars-d-learn
On Saturday, 28 May 2016 at 11:57:09 UTC, Era Scarecrow wrote: Use traits.. https://dlang.org/phobos/std_traits.html#isSafe so your function becomes (i believe) auto doSomethingDumb(T)(ref T t) if(isSafe!(T)) The problem is that T is a type, and I should check for safety of every meth

Re: @trusting generic functions

2016-05-28 Thread Lodovico Giaretta via Digitalmars-d-learn
On Saturday, 28 May 2016 at 12:33:28 UTC, Era Scarecrow wrote: On Saturday, 28 May 2016 at 12:25:14 UTC, Lodovico Giaretta wrote: On Saturday, 28 May 2016 at 11:57:09 UTC, Era Scarecrow wrote: auto doSomethingDumb(T)(ref T t) if(isSafe!(T)) The problem is that T is a type, and I should ch

Re: @trusting generic functions

2016-05-28 Thread Lodovico Giaretta via Digitalmars-d-learn
On Saturday, 28 May 2016 at 12:45:21 UTC, Era Scarecrow wrote: On Saturday, 28 May 2016 at 12:25:14 UTC, Lodovico Giaretta wrote: The problem is that T is a type, and I should check for safety of every method of T that I'm using in my function. This does not scale well, and if I change the body

Re: @trusting generic functions

2016-05-28 Thread Lodovico Giaretta via Digitalmars-d-learn
On Saturday, 28 May 2016 at 12:45:21 UTC, Era Scarecrow wrote: Fourth, you could create a helper function/template that cycles through a struct of your choice and tells you if any of it's methods fail to be safe. This will require a little more work, but it could be used as a full insurance an

Re: @trusting generic functions

2016-05-28 Thread Lodovico Giaretta via Digitalmars-d-learn
On Saturday, 28 May 2016 at 13:03:10 UTC, Adam D. Ruppe wrote: What kind of pointer usage do you have? Remember that basic & and * operations ARE @safe. If you have more internally, you might be able to wrap them up in an @trusted function to again allow inference to work. Ouch! I was under

Re: @trusting generic functions

2016-05-28 Thread Lodovico Giaretta via Digitalmars-d-learn
On Saturday, 28 May 2016 at 14:01:35 UTC, Era Scarecrow wrote: On Saturday, 28 May 2016 at 13:10:56 UTC, Lodovico Giaretta wrote: The only problem is that these structures are parameterized, and the type parameters may have unsafe operations that I use. Do you still want the template i'm buil

Re: @trusting generic functions

2016-05-31 Thread Lodovico Giaretta via Digitalmars-d-learn
On Sunday, 29 May 2016 at 18:02:53 UTC, Steven Schveighoffer wrote: You can create a trusted expression by using a lambda and immediately calling it. ag0aep6g brought it up. I would write it like this (untested, but I think this works): return (()@trusted => &t)().doSomething(); The key is to

Re: Default initialization of structs?

2016-06-17 Thread Lodovico Giaretta via Digitalmars-d-learn
On Friday, 17 June 2016 at 10:50:55 UTC, Gary Willoughby wrote: I have a struct where I need to perform default initialization of some members but the compiler doesn't allow to define a default constructor which allow optional arguments. struct Foo(T) { private int _bar; this(int bar

opDispatch and @property setters

2016-06-21 Thread Lodovico Giaretta via Digitalmars-d-learn
Hi, I'm trying to achieve perfect forwarding of any invocation from the wrapper to the wrapped item, but I'm having a bad time with @property. Suppose this is my wrapper (with all logic stripped): struct Wrapper(T) { private T wrapped; template hasAssignableProperty(

Re: opDispatch and @property setters

2016-06-21 Thread Lodovico Giaretta via Digitalmars-d-learn
On Tuesday, 21 June 2016 at 21:11:39 UTC, ag0aep6g wrote: Works when you change the return type of the the @property opDispatch to auto, so that it can return the result. It's a little weird, but D does support calling functions with assignment syntax. Alternatively, maybe you can actually ch

Re: static switch/pattern matching

2016-06-25 Thread Lodovico Giaretta via Digitalmars-d-learn
On Saturday, 25 June 2016 at 08:46:05 UTC, John wrote: Writing a long series of "static if ... else" statements can be tedious and I'm prone to leaving out the crucial "static" after "else", so I was wondered if it was possible to write a template that would resemble the switch statement, but f

Re: static switch/pattern matching

2016-06-25 Thread Lodovico Giaretta via Digitalmars-d-learn
On Saturday, 25 June 2016 at 09:07:19 UTC, Lodovico Giaretta wrote: Instead of passing functions to match!, pass pairs of arguments, like this: match!(T, int, writeln("Matched int"), is(T : SomeObject), writeln("Derives from SomeObject"); ); Now, in the implementation

Re: static switch/pattern matching

2016-06-25 Thread Lodovico Giaretta via Digitalmars-d-learn
On Saturday, 25 June 2016 at 10:39:09 UTC, John wrote: Thanks for the help, both. This appeared to work, until I realised the lambda isn't static: void match(T, cases...)() { static if (cases.length == 1) cases[0](); else static if (cases.length > 2) { static if (is(typeof(cases

Re: static switch/pattern matching

2016-06-25 Thread Lodovico Giaretta via Digitalmars-d-learn
On Saturday, 25 June 2016 at 12:30:22 UTC, Lodovico Giaretta wrote: If you want this to work, you need your lambdas to take the casted value as a parameter: void test(T)(T value) { int i; string s; match!(value, int, (val) => i = val, string, (val) => s = val

Re: Getting the template name of a template instantiation

2016-06-27 Thread Lodovico Giaretta via Digitalmars-d-learn
On Monday, 27 June 2016 at 16:40:09 UTC, Nordlöw wrote: If I have a template parameter E = S!int where struct S(T) { S x; } how can I extract the template name part `S` from E`? Something like: static assert(is(templateName!(S!int) == S)); Is this already in Phobos somewhere?

Re: What's the secret to static class members

2016-06-29 Thread Lodovico Giaretta via Digitalmars-d-learn
On Wednesday, 29 June 2016 at 17:00:49 UTC, Guido wrote: I have all this business generally working in C++. I just wanted to try D for a production level quick project. So, the language is not ready. I'm really sad about this. I had hoped that I could get some useful work done. C++ is painfully

Re: Implementing a cache

2016-07-02 Thread Lodovico Giaretta via Digitalmars-d-learn
On Saturday, 2 July 2016 at 12:10:28 UTC, qznc wrote: I want to implement some caching for HTTP GET requests. Basically a map of URL to content. A cache needs some additional meta data (size, age, etc). There seem to be two basic data structures available: Associative array (AA) or red black

Re: Implementing a cache

2016-07-03 Thread Lodovico Giaretta via Digitalmars-d-learn
On Sunday, 3 July 2016 at 16:03:51 UTC, qznc wrote: On Saturday, 2 July 2016 at 12:21:14 UTC, Lodovico Giaretta wrote: On Saturday, 2 July 2016 at 12:10:28 UTC, qznc wrote: Alternatively, any better idea to implement the cache? I guess there is no off-the-shelf/dub solution. For now, I settle

Re: Program locked at joinAll and sched_yield

2016-07-03 Thread Lodovico Giaretta via Digitalmars-d-learn
On Friday, 1 July 2016 at 12:02:11 UTC, tcak wrote: I have my own Http Server. Every request is handled by a thread, and threads are reused. I send 35,000 request (7 different terminals are sending 5000 requests each) to the server again and again (each of them lives for short). Anyway, eve

Re: Program locked at joinAll and sched_yield

2016-07-03 Thread Lodovico Giaretta via Digitalmars-d-learn
On Sunday, 3 July 2016 at 18:25:32 UTC, tcak wrote: Well, I actually have found out about the issue, and solved it a different way. I put memory limit on the process for testing. At some point, due to memory limitation, thread.start() method fails. But, this method cannot recover the system c

Re: Properties don't work as expected

2016-07-06 Thread Lodovico Giaretta via Digitalmars-d-learn
On Wednesday, 6 July 2016 at 09:08:11 UTC, zodd wrote: So, I've created a simple wrapper template to achieve what I want. It reminds me of the C++ - a bunch of additional code to solve a simple problem (which shouldn't be an issue at all). I'm a newbie in D thus I could do something wrong or n

Re: Endiannes & Splitting Values

2016-07-06 Thread Lodovico Giaretta via Digitalmars-d-learn
On Wednesday, 6 July 2016 at 21:44:37 UTC, BitGuy wrote: I'm trying to implement a feistel cipher that'll give the same results regardless of the endianness of the machine it runs on. To make the cipher I need to split a 64bit value into two 32bit values, mess with them, and then put them back

Re: Endiannes & Splitting Values

2016-07-07 Thread Lodovico Giaretta via Digitalmars-d-learn
On Thursday, 7 July 2016 at 08:14:40 UTC, Gary Willoughby wrote: What about something like: import std.stdio; union Value { ulong full; static struct Bits { uint high; uint low; } Bits bits; alias bits this; this(ulong value) { this.fu

Re: Strange rbtree behaviour

2016-07-07 Thread Lodovico Giaretta via Digitalmars-d-learn
On Thursday, 7 July 2016 at 09:33:38 UTC, Arafel wrote: Hi! I am seeing what it seems to me a very strange behavior with rbtrees: --- import std.stdio; import std.container.rbtree; public struct A { public int i; public this (int _i) { this.i = _i;

Re: Strange rbtree behaviour

2016-07-07 Thread Lodovico Giaretta via Digitalmars-d-learn
On Thursday, 7 July 2016 at 09:40:57 UTC, Lodovico Giaretta wrote: Initially it looks very surprising, but then if you add `writeln(B.init.col[]);` you can easily find out what's going on. And I'm quite sure it's expected behaviour. An RBTree is just a pointer to the memory containing the ac

Re: Endiannes & Splitting Values

2016-07-07 Thread Lodovico Giaretta via Digitalmars-d-learn
On Thursday, 7 July 2016 at 10:45:12 UTC, Gary Willoughby wrote: On Thursday, 7 July 2016 at 08:21:53 UTC, Lodovico Giaretta wrote: Are you sure that this works in both big-endian and little-endian systems? It shouldn't matter. You're just interested in the high and low 4 byte chunks (which a

Re: Why is ElementType!(char[]) == dchar?

2016-07-09 Thread Lodovico Giaretta via Digitalmars-d-learn
On Saturday, 9 July 2016 at 11:46:14 UTC, Tofu Ninja wrote: On Saturday, 9 July 2016 at 11:35:24 UTC, Tofu Ninja wrote: On Saturday, 9 July 2016 at 11:29:18 UTC, ketmar wrote: On Saturday, 9 July 2016 at 11:24:01 UTC, Tofu Ninja wrote: Seems pretty silly to me... due to universally beloved a

Re: mutable string

2016-07-10 Thread Lodovico Giaretta via Digitalmars-d-learn
On Sunday, 10 July 2016 at 19:50:28 UTC, Adam Sansier wrote: On Sunday, 10 July 2016 at 19:44:01 UTC, Adam D. Ruppe wrote: On Sunday, 10 July 2016 at 19:19:57 UTC, Adam Sansier wrote: Is it possible to turn temporary char/wchar buffer in to a string to be used by string functions rather than ha

Re: sorting std.container

2016-07-11 Thread Lodovico Giaretta via Digitalmars-d-learn
On Monday, 11 July 2016 at 18:54:44 UTC, George M wrote: Hello everybody, sorry for my bad english(nativ german). D is a very nice language and easy to learn because i am a c# (only private) developer. The only bad is to find examples is very hard. My question: How can i sort a slist or dlis

Re: aspects on methods?

2016-07-12 Thread Lodovico Giaretta via Digitalmars-d-learn
On Tuesday, 12 July 2016 at 11:26:20 UTC, jj75607 wrote: I want to use aspect-like annotations to transform @Lockable class Abc { @sync void f() { writeln("f"); } @shared void g() { writeln("g"); } } to something like: class Ab

Re: Simple overloading without complications

2016-07-12 Thread Lodovico Giaretta via Digitalmars-d-learn
On Tuesday, 12 July 2016 at 13:44:02 UTC, Adam Sansier wrote: On Tuesday, 12 July 2016 at 08:52:26 UTC, Kagamin wrote: Extract functions for shared parts: void Do(string name) { DoStuff(); int i = find(name); DoStuffWithIndex(i); } void Do(int name) { DoStuff(); DoStuffWith

Re: C++ interface vs D and com

2016-07-12 Thread Lodovico Giaretta via Digitalmars-d-learn
On Tuesday, 12 July 2016 at 15:09:26 UTC, Adam Sansier wrote: So, com throughs me a interface ptr and I need to map it to an interface. When I do, I get an access violation. I have an (com) ptr and an interface. How do I link them up so I can call the functions? I marked the interface extern

Re: Simple overloading without complications

2016-07-12 Thread Lodovico Giaretta via Digitalmars-d-learn
On Tuesday, 12 July 2016 at 16:30:05 UTC, Adam Sansier wrote: Doesn't matter, it's not what I asked. Trying to provide answers to a question that wasn't asked and was clearly stated I wasn't interested in those types of answers. Every language has its own ways of solving various problems. We a

Re: Simple overloading without complications

2016-07-12 Thread Lodovico Giaretta via Digitalmars-d-learn
On Tuesday, 12 July 2016 at 16:27:52 UTC, Adam Sansier wrote: On Tuesday, 12 July 2016 at 13:54:16 UTC, Lodovico Giaretta Also note that yield semantics as available in various languages is much different from what you are proposing here. Not really. Yield is usually a break in flow, regardles

Re: How to open file with exclusive lock?

2016-07-12 Thread Lodovico Giaretta via Digitalmars-d-learn
On Tuesday, 12 July 2016 at 18:54:18 UTC, Charles Hixson wrote: I want to open a file with an exclusive lock. It would be important that no other thread be able to access the file in write mode, and desirable that no other thread be able to access the file in read mode. (Ditto for other proce

Re: C++ interface vs D and com

2016-07-12 Thread Lodovico Giaretta via Digitalmars-d-learn
On Tuesday, 12 July 2016 at 21:21:04 UTC, Adam Sansier wrote: On Tuesday, 12 July 2016 at 15:12:21 UTC, Lodovico Giaretta wrote: I'm not an expert in this field, but did you read this[1]? [1] https://dlang.org/spec/interface.html#com-interfaces Yes, of course... Well, I asked because you s

Re: I can has @nogc and throw Exceptions?

2016-07-13 Thread Lodovico Giaretta via Digitalmars-d-learn
On Wednesday, 13 July 2016 at 00:57:38 UTC, Adam Sansier wrote: How about simply setting aside a 100kb of memory as a pool for exceptions. Seems like a lot but still under 640kb, hell, even 1MB would still be tiny. After all, it's not like exceptions are common or happen in complex ways. Do

Re: Best way to clear dynamic array for reuse

2016-07-13 Thread Lodovico Giaretta via Digitalmars-d-learn
On Wednesday, 13 July 2016 at 11:59:18 UTC, Miguel L wrote: I am using a temporary dynamic array inside a loop this way: A[] a; for() { a=[]; //discard array contents ... appends thousand of elements to a ... use a for some calculations } I would like to know which would be the best way to c

Re: Best way to clear dynamic array for reuse

2016-07-13 Thread Lodovico Giaretta via Digitalmars-d-learn
On Wednesday, 13 July 2016 at 12:20:07 UTC, cym13 wrote: The best option would be a.clear(). From the language specs: “Removes all remaining keys and values from an associative array. The array is not rehashed after removal, to allow for the existing storage to be reused. This will affect all

Re: Best way to clear dynamic array for reuse

2016-07-13 Thread Lodovico Giaretta via Digitalmars-d-learn
On Wednesday, 13 July 2016 at 12:37:26 UTC, Miguel L wrote: I tried Appender, but for some reason garbage collector still seems to be running every few iterations. I will try to expand a little on my code because maybe there is something i am missing: Appender!(A[]) a; void foo( out Appende

Re: I can has @nogc and throw Exceptions?

2016-07-13 Thread Lodovico Giaretta via Digitalmars-d-learn
On Wednesday, 13 July 2016 at 16:13:21 UTC, Adam Sansier wrote: On Wednesday, 13 July 2016 at 11:39:11 UTC, Lodovico Giaretta wrote: On Wednesday, 13 July 2016 at 00:57:38 UTC, Adam Sansier wrote: [...] You shall use a static per-thread Region allocator[1] backed by Mallocator[2]. Then you

Re: I can has @nogc and throw Exceptions?

2016-07-13 Thread Lodovico Giaretta via Digitalmars-d-learn
On Wednesday, 13 July 2016 at 20:44:52 UTC, Adam Sansier wrote: On Wednesday, 13 July 2016 at 16:28:23 UTC, Lodovico Giaretta wrote: It's actually quite easy. Here's the code (untested): import std.experimental.allocator.buildin

Re: I can has @nogc and throw Exceptions?

2016-07-13 Thread Lodovico Giaretta via Digitalmars-d-learn
On Wednesday, 13 July 2016 at 21:12:29 UTC, Adam Sansier wrote: The advantages over a simple malloc are: 1) You can change between GC allocation, malloc, mmap and other allocators by changing a single line, instead of changing every throw; Ok, I like! 2) you can use very fast allocators, base

Re: I can has @nogc and throw Exceptions?

2016-07-14 Thread Lodovico Giaretta via Digitalmars-d-learn
On Wednesday, 13 July 2016 at 22:42:36 UTC, Adam Sansier wrote: On Wednesday, 13 July 2016 at 21:27:16 UTC, Lodovico Giaretta wrote: At the end, all memory comes from one of these: GC heap, malloc, mmap, sbrk. All other allocators build on top of these (or on top of user supplied buffers, which

Re: Templates args

2016-07-14 Thread Lodovico Giaretta via Digitalmars-d-learn
On Thursday, 14 July 2016 at 19:28:23 UTC, Andrey wrote: On Thursday, 14 July 2016 at 19:27:14 UTC, Andrey wrote: Hi guys! Help a newbie please. Playing with D and trying to understand some features. Here is my try to carry out my code from C++ project to D struct Sigmoid(T) { const T Funct

Iterate all visible symbols, even from imported modules

2016-07-18 Thread Lodovico Giaretta via Digitalmars-d-learn
As per title, is it possible to iterate all visible symbols of the current module and of all imported modules and packages? My aim is to find everything in scope that has a specific UDA. module foo; import std.stdio, std.array, std.algorithm; void bar(){} struct S{} void main() { // pri

Re: Iterate all visible symbols, even from imported modules

2016-07-18 Thread Lodovico Giaretta via Digitalmars-d-learn
On Monday, 18 July 2016 at 18:21:41 UTC, ketmar wrote: short answer: no. there is still no way to write a reliable enumerator like this: too much things to hack around. as for module symbols, it is easy: they has no type. literally: `!is(typeof(...))`. `is(typeof(...))` is a necessary safe

Re: Iterate all visible symbols, even from imported modules

2016-07-18 Thread Lodovico Giaretta via Digitalmars-d-learn
On Monday, 18 July 2016 at 21:12:38 UTC, Meta wrote: On Monday, 18 July 2016 at 13:00:16 UTC, Lodovico Giaretta wrote: As per title, is it possible to iterate all visible symbols of the current module and of all imported modules and packages? My aim is to find everything in scope that has a spe

Re: counting characters

2016-07-19 Thread Lodovico Giaretta via Digitalmars-d-learn
On Tuesday, 19 July 2016 at 09:42:40 UTC, celavek wrote: On Tuesday, 19 July 2016 at 09:41:32 UTC, John wrote: On Tuesday, 19 July 2016 at 09:34:11 UTC, celavek wrote: Hi, I am trying to count characters in a string like: const string dna_chain = "AGCCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGA

Re: counting characters

2016-07-19 Thread Lodovico Giaretta via Digitalmars-d-learn
On Tuesday, 19 July 2016 at 12:23:11 UTC, celavek wrote: On Tuesday, 19 July 2016 at 09:57:27 UTC, Lodovico Giaretta wrote: On Tuesday, 19 July 2016 at 09:42:40 UTC, celavek wrote: Works for me: size_t[char] counts; const string dna_chain = "AGCCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTA

Re: Passing a single tuple or multiple values

2016-07-19 Thread Lodovico Giaretta via Digitalmars-d-learn
On Tuesday, 19 July 2016 at 13:33:41 UTC, jmh530 wrote: On Tuesday, 19 July 2016 at 07:23:52 UTC, John wrote: auto bar(T...)(T x) { static if (T.length == 1 && isTuple!(T[0])) return foo(x.expand); else return foo(x); } Hmm, this actually doesn't seem to be resolving my issue. I'

Re: Passing a single tuple or multiple values

2016-07-19 Thread Lodovico Giaretta via Digitalmars-d-learn
On Tuesday, 19 July 2016 at 15:36:42 UTC, Lodovico Giaretta wrote: As you have to do `isTuple!(T[0])`, you also have to do `x[0].expand`. That's because T... works "as if" it was an array of types, and x, being of type T, it works "as if" it was an array of values. So you have to use an index i

Re: Allowing "fall through" of attributes

2016-07-19 Thread Lodovico Giaretta via Digitalmars-d-learn
On Tuesday, 19 July 2016 at 15:55:02 UTC, Rufus Smith wrote: I have some functions that take other functions. I would like the attributes to be able to "fall" through so I get overload like behavior. I only care that I am passing a function, not if it is shared, extern(C), pure, @nogc, etc. v

Re: Allowing "fall through" of attributes

2016-07-19 Thread Lodovico Giaretta via Digitalmars-d-learn
On Tuesday, 19 July 2016 at 16:50:56 UTC, Rufus Smith wrote: On Tuesday, 19 July 2016 at 16:09:38 UTC, Lodovico Giaretta wrote: On Tuesday, 19 July 2016 at 15:55:02 UTC, Rufus Smith wrote: I have some functions that take other functions. I would like the attributes to be able to "fall" through

Re: Allowing "fall through" of attributes

2016-07-19 Thread Lodovico Giaretta via Digitalmars-d-learn
On Tuesday, 19 July 2016 at 17:05:55 UTC, Rufus Smith wrote: On Tuesday, 19 July 2016 at 16:59:48 UTC, Lodovico Giaretta wrote: On Tuesday, 19 July 2016 at 16:50:56 UTC, Rufus Smith wrote: On Tuesday, 19 July 2016 at 16:09:38 UTC, Lodovico Giaretta wrote: [...] But this doesn't create a func

Re: Why typeof(template) is void?

2016-07-20 Thread Lodovico Giaretta via Digitalmars-d-learn
On Wednesday, 20 July 2016 at 05:54:41 UTC, mogu wrote: On Wednesday, 20 July 2016 at 01:50:37 UTC, Adam D. Ruppe wrote: On Wednesday, 20 July 2016 at 01:14:05 UTC, mogu wrote: Why S's type isn't something like `S: (T) -> S`? Because S isn't a type... think of a template as being like a func

Re: How to search for an enum by values and why enum items aren't unique

2016-07-20 Thread Lodovico Giaretta via Digitalmars-d-learn
On Wednesday, 20 July 2016 at 18:08:14 UTC, stunaep wrote: On Wednesday, 20 July 2016 at 05:45:21 UTC, Jonathan M Davis wrote: On Wednesday, July 20, 2016 04:03:23 stunaep via Digitalmars-d-learn wrote: [...] If you want the list of members in an enum, then use std.traits.EnumMembers and you

Re: Default implementations in inherited interfaces

2016-07-21 Thread Lodovico Giaretta via Digitalmars-d-learn
On Thursday, 21 July 2016 at 09:41:27 UTC, Saurabh Das wrote: I have an interface A which declares a certain function. A second interface B inherits from A and wishes to provide a default implementation for that function. How can I achieve this? I'm facing an error when I try this: interface

Re: Default implementations in inherited interfaces

2016-07-21 Thread Lodovico Giaretta via Digitalmars-d-learn
On Thursday, 21 July 2016 at 09:46:10 UTC, Lodovico Giaretta wrote: Interesting. This is worth a bugzilla issue, IMHO. In fact, if you try the other way (i.e.: you provide an implementation of func in class C), you get the opposite error, that you are overriding a final function (B.func). Su

Re: Building phobos GDC

2016-07-22 Thread Lodovico Giaretta via Digitalmars-d-learn
On Friday, 22 July 2016 at 18:30:13 UTC, Rufus Smith wrote: Trying to compile code that uses GDC, had to import phobos files from dmd in to project since they are not in the GDC's phobo lib(the core.sys.windows stuff). Almost all the errors are related to stuff like PALETTEENTRY* peNew() retu

Re: Building phobos GDC

2016-07-22 Thread Lodovico Giaretta via Digitalmars-d-learn
On Friday, 22 July 2016 at 18:30:13 UTC, Rufus Smith wrote: Trying to compile code that uses GDC, had to import phobos files from dmd in to project since they are not in the GDC's phobo lib(the core.sys.windows stuff). Almost all the errors are related to stuff like PALETTEENTRY* peNew() retu

Re: Building phobos GDC

2016-07-22 Thread Lodovico Giaretta via Digitalmars-d-learn
On Friday, 22 July 2016 at 20:26:50 UTC, Rufus Smith wrote: On Friday, 22 July 2016 at 19:52:59 UTC, Lodovico Giaretta wrote: On Friday, 22 July 2016 at 18:30:13 UTC, Rufus Smith wrote: Trying to compile code that uses GDC, had to import phobos files from dmd in to project since they are not in

Re: Cannot compare object.opEquals is not nogc

2016-07-23 Thread Lodovico Giaretta via Digitalmars-d-learn
On Saturday, 23 July 2016 at 13:18:03 UTC, Rufus Smith wrote: Trying to compare a *ptr value with a value in nogc code results in the error: Error: @nogc function '...' cannot call non-@nogc function 'object.opEquals' Shouldn't object opEquals be marked? If object.opEquals is marked @nog

Re: Cannot compare object.opEquals is not nogc

2016-07-23 Thread Lodovico Giaretta via Digitalmars-d-learn
On Saturday, 23 July 2016 at 14:53:49 UTC, Rufus Smith wrote: Um, this isn't right. GC code can always call non-gc code. If you mark opEquals nogc, it breaks nothing except implementations of opEquals that use the GC. GC code can still call it nogc opequals, it only enforces opEquals code to a

Re: Cannot compare object.opEquals is not nogc

2016-07-23 Thread Lodovico Giaretta via Digitalmars-d-learn
On Saturday, 23 July 2016 at 17:04:42 UTC, Jonathan Marler wrote: On Saturday, 23 July 2016 at 16:46:20 UTC, Jonathan Marler wrote: [...] Actually Im going to disagree with myself. This technique actually wouldn't work with virtual methods:) I don't think we have the big problems with @nogc

Re: Cannot compare object.opEquals is not nogc

2016-07-23 Thread Lodovico Giaretta via Digitalmars-d-learn
On Saturday, 23 July 2016 at 21:44:05 UTC, Rufus Smith wrote: Templates are not the end all be all. They don't allow for run-time polymorphism, which is an important aspect of software. Ok, so you need runtime polymorphism. And you want it in @nogc code. That's not difficult. Just have the bas

Re: Cannot compare object.opEquals is not nogc

2016-07-23 Thread Lodovico Giaretta via Digitalmars-d-learn
On Saturday, 23 July 2016 at 21:44:05 UTC, Rufus Smith wrote: On Saturday, 23 July 2016 at 17:27:24 UTC, Lodovico Giaretta wrote: - we trust what we are doing: e.g. we cannot mark a thing @nogc, but we know it is and the profiler confirms that no allocation happens, so we are happy; our aim

Re: Cannot compare object.opEquals is not nogc

2016-07-24 Thread Lodovico Giaretta via Digitalmars-d-learn
On Sunday, 24 July 2016 at 02:17:27 UTC, Rufus Smith wrote: This just isn't right. What your saying is that because someone screwed up, we must live with the screw up and build everyone around the screw up. This mentality is why everyone is so screwed up in the first place, do you not see that?

Re: Cannot compare object.opEquals is not nogc

2016-07-24 Thread Lodovico Giaretta via Digitalmars-d-learn
On Sunday, 24 July 2016 at 14:54:11 UTC, Jonathan Marler wrote: I believe Rufus was only referring to the virtual methods defined in the object class. That would be: toHash (Note: this is already nothrow, that's intersting and quite restrictive) opCmp opEquals I think all 3 of these are goo

Re: Cannot compare object.opEquals is not nogc

2016-07-24 Thread Lodovico Giaretta via Digitalmars-d-learn
On Sunday, 24 July 2016 at 15:28:53 UTC, Jonathan Marler wrote: Whoa wait a second...I didn't know you could do this. I thought everything had to inherit from the object class. Can you share the syntax to define a class that doesn't derive from object? Currently, you cannot. Everything inhe

Re: Cannot compare object.opEquals is not nogc

2016-07-24 Thread Lodovico Giaretta via Digitalmars-d-learn
On Sunday, 24 July 2016 at 15:31:28 UTC, lqjglkqjsg wrote: Almost off topic but I've recognized a typical error here, I think that many of us have already seen it too. You develop a nice class. You put attributes everywhere @safe pure nothrow @nogc. Yay the unittest pass. Later you use it for

Re: Autodecode in the wild and An Awful Hack to std.regex

2016-07-28 Thread Lodovico Giaretta via Digitalmars-d-learn
On Thursday, 28 July 2016 at 09:10:33 UTC, Kagamin wrote: Create an RFE? Given that regex returns results as slices of the input string, using the replacement character doesn't introduce data corruption. (RFE = Request For Enhancement, right?) Yes, all algorithms that use decode internally sha

Re: Question about destructor of database and multiple use access

2016-07-28 Thread Lodovico Giaretta via Digitalmars-d-learn
On Thursday, 28 July 2016 at 14:33:26 UTC, Dechcaudron wrote: On Thursday, 28 July 2016 at 14:01:45 UTC, Suliman wrote: 2. Should I call destructor and how it's should like? You certainly want to close the connection to the db. Basically, the destructor is intended to free resources such as dy

Re: Question about destructor of database and multiple use access

2016-07-28 Thread Lodovico Giaretta via Digitalmars-d-learn
On Thursday, 28 July 2016 at 15:02:58 UTC, Dechcaudron wrote: On Thursday, 28 July 2016 at 14:43:32 UTC, Lodovico Giaretta wrote: No! Never run important finalization in a class destructor! The GC is not obliged to run the destructors, so you may end up with your objects destroyed but the conne

Re: Question about destructor of database and multiple use access

2016-07-28 Thread Lodovico Giaretta via Digitalmars-d-learn
On Thursday, 28 July 2016 at 15:24:22 UTC, Dechcaudron wrote: On Thursday, 28 July 2016 at 15:18:24 UTC, Lodovico Giaretta wrote: 3) at program end, live objects are not scheduled for finalization; 4) at program end, pending finalizations from previous collections may not be run. I didn't kno

Re: When I should to call destroy?

2016-07-29 Thread Lodovico Giaretta via Digitalmars-d-learn
On Friday, 29 July 2016 at 13:18:00 UTC, Suliman wrote: Use the `destroy` function to finalize an object by calling its destructor. The memory of the object is not immediately deallocated, instead the GC will collect the memory of the object at an undetermined point after finalization: class

Re: Template method in interfaces

2016-08-10 Thread Lodovico Giaretta via Digitalmars-d-learn
On Wednesday, 10 August 2016 at 15:20:37 UTC, Arafel wrote: I'm not sure if the following is even expected to work, since I'm not sure how the vtable for the interface would look like (well, that would be applicable to any overriden templated method, though): --- public interface I {

Re: Template method in interfaces

2016-08-10 Thread Lodovico Giaretta via Digitalmars-d-learn
On Wednesday, 10 August 2016 at 15:39:19 UTC, Arafel wrote: On Wednesday, 10 August 2016 at 15:25:40 UTC, Lodovico Giaretta wrote: Because templated functions cannot be virtual, it follows that I.func is final. Having no body, the compiler thinks that its body will be found by the linker in ano

Re: Template method in interfaces

2016-08-10 Thread Lodovico Giaretta via Digitalmars-d-learn
On Wednesday, 10 August 2016 at 15:48:10 UTC, Lodovico Giaretta wrote: On Wednesday, 10 August 2016 at 15:39:19 UTC, Arafel wrote: Would it even make sense to "force" (deprecation warning) a "final" keyword in any implicitly-final function (I wasn't even aware of those, I have to admit)? It wou

Re: Template method in interfaces

2016-08-10 Thread Lodovico Giaretta via Digitalmars-d-learn
On Wednesday, 10 August 2016 at 15:54:42 UTC, Adam D. Ruppe wrote: On Wednesday, 10 August 2016 at 15:48:10 UTC, Lodovico Giaretta wrote: I read the spec again, and found out that it says interfaces cannot contain templated functions... So either my interpretation is the intended one and the sp

Unexpected foreach lowering

2016-08-10 Thread Lodovico Giaretta via Digitalmars-d-learn
I'm probably missing something stupid but... Why on earth do the two loops in main print a different result? It looks like the foreach lowering is ignoring my definition of front... = import std.stdio, std.container.array; struct RangeWrapper

Re: Unexpected foreach lowering

2016-08-10 Thread Lodovico Giaretta via Digitalmars-d-learn
On Wednesday, 10 August 2016 at 18:08:02 UTC, Lodovico Giaretta wrote: I'm probably missing something stupid but... Why on earth do the two loops in main print a different result? It looks like the foreach lowering is ignoring my definition of front... =

Re: Unexpected foreach lowering

2016-08-10 Thread Lodovico Giaretta via Digitalmars-d-learn
On Wednesday, 10 August 2016 at 18:38:00 UTC, Ali Çehreli wrote: RangeWrapper does not provide the InputRange interface, so the compiler uses 'alias this' and iterates directly on the member range. I tried making RangeWrapper an InputRange but failed. It still uses 'range'. // Still fails w

Re: Unexpected foreach lowering

2016-08-10 Thread Lodovico Giaretta via Digitalmars-d-learn
On Wednesday, 10 August 2016 at 19:37:39 UTC, Ali Çehreli wrote: A quick read reveals popFront() is implemented only for bool Arrays. That explains the issue. I don't know whether it's an oversight. Ali First of all, thank you for spending your time on this issue. I really appreciate that.

Re: Unexpected foreach lowering

2016-08-10 Thread Lodovico Giaretta via Digitalmars-d-learn
On Wednesday, 10 August 2016 at 20:54:15 UTC, Steven Schveighoffer wrote: On 8/10/16 2:08 PM, Lodovico Giaretta wrote: [...] The issue is that it tries using [] on the item to see if it defines a range-like thing. Since you don't define opSlice(), it automatically goes to the subrange. Thi

Re: Unexpected foreach lowering

2016-08-10 Thread Lodovico Giaretta via Digitalmars-d-learn
On Wednesday, 10 August 2016 at 21:00:01 UTC, Lodovico Giaretta wrote: On Wednesday, 10 August 2016 at 20:54:15 UTC, Steven Schveighoffer wrote: [...] Wow. Thanks. I didn't know the compiler would try opSlice. I will file it. Filed on bugzilla: https://issues.dlang.org/show_bug.cgi?id=1637

Re: Template parameters that don't affect template type

2016-08-11 Thread Lodovico Giaretta via Digitalmars-d-learn
On Thursday, 11 August 2016 at 18:11:30 UTC, Engine Machine wrote: [...] If, in your case, it is possible to use one type as the other, then specify it. I mean, implement a templated opAssign that allows you to assign values of one instantiation to values of another. While doing so, remember

Re: Retreive method given object, name and arguments

2016-08-11 Thread Lodovico Giaretta via Digitalmars-d-learn
On Thursday, 11 August 2016 at 20:27:51 UTC, Michael Coulombe wrote: Is there a way to implement "getSymbolOfCall" and "getDelegateOfCall" such that doit is functionally equivalent to calling the method directly? auto doit(C, string methodName, Args...)(C c, Args args) { alias methodSymbol

Re: new XML and JSON libs and replacement of std.net.curl

2016-08-15 Thread Lodovico Giaretta via Digitalmars-d-learn
On Monday, 15 August 2016 at 15:01:13 UTC, Oleg B wrote: Hello. In std.xml docs I read that is deprecated, [...] For XML I found this project https://github.com/lodo1995/experimental.xml. Is this really candidate to std, or author just called it as he want? Hi! I'm the developer of that XML

Re: Converting a Visual Studio Solution with many Projects into DUB package?

2016-08-16 Thread Lodovico Giaretta via Digitalmars-d-learn
On Tuesday, 16 August 2016 at 15:46:23 UTC, WhatMeWorry wrote: I've got a large Visual Studio Solution which contains lots of Projects. Each project is a standalone D/OpenGL tutorial. I want to make it OS and IDE agnostic so it can be easily played with on Windows, Linux, and Mac OS so I th

Re: Template type reduction

2016-08-16 Thread Lodovico Giaretta via Digitalmars-d-learn
On Monday, 15 August 2016 at 19:31:14 UTC, Engine Machine wrote: Suppose I have a templated type like struct S(T) { int x; static if (T is Y) int y; } I would like to be able to create a reference to S(T) for any T, struct Q { S!* s; // Can hold any type of S. } and be able to access s.x, s

Re: Template type reduction

2016-08-16 Thread Lodovico Giaretta via Digitalmars-d-learn
On Tuesday, 16 August 2016 at 19:23:51 UTC, Engine Machine wrote: On Tuesday, 16 August 2016 at 17:39:14 UTC, Lodovico Giaretta wrote: On Monday, 15 August 2016 at 19:31:14 UTC, Engine Machine wrote: [...] I don't know if this is exactly what you want: = i

Re: Sequence separation

2016-08-17 Thread Lodovico Giaretta via Digitalmars-d-learn
On Tuesday, 16 August 2016 at 23:18:28 UTC, Adam D. Ruppe wrote: On Tuesday, 16 August 2016 at 19:17:27 UTC, Engine Machine wrote: alias x = AliasSeq!(a, b, AliasSeq!(c, d)); results in a flat sequence. I would like to be able to keep them separate so I can have sub sequences. wrap them in a

Re: having a trivial anonymous function call in template prevents compilation?

2016-08-17 Thread Lodovico Giaretta via Digitalmars-d-learn
On Wednesday, 17 August 2016 at 13:21:16 UTC, Cauterite wrote: On Wednesday, 17 August 2016 at 13:18:06 UTC, Adam D. Ruppe wrote: Best you can do is use them in an alias argument directly, but you cannot use them in an enum argument. I think you missed the point; it works perfectly fine withou

Re: Sequence separation

2016-08-17 Thread Lodovico Giaretta via Digitalmars-d-learn
On Wednesday, 17 August 2016 at 19:15:48 UTC, ag0aep6g wrote: On 08/17/2016 08:38 PM, Engine Machine wrote: On Wednesday, 17 August 2016 at 08:37:32 UTC, Lodovico Giaretta wrote: [...] You mean something like: struct MySequence(Args...) { enum length = Args.length; alias args = Args;

  1   2   >