Error: module `hello` is in file 'hello.d' which cannot be read

2018-05-04 Thread Alex via Digitalmars-d-learn
Hi I just installed D on my windows 10 and want to try to compile a hello world. My source is a classical import std.stdio; void main() { writeln("Hello, World!"); } And I try to compile and get C:\D>dmd hello.d Error: module `hello` is in file 'hello.d' which cannot be read import path[0]

Re: Template to retrieve compile-time enum member from run-time enum member?

2018-04-27 Thread Alex via Digitalmars-d-learn
On Friday, 27 April 2018 at 13:43:47 UTC, Timoses wrote: `instantiateWith` gets called in three variations (menum.A, menum.B and menum.C). This causes instantiateWith to return TempStruct for each case of Temp... However, I was under the impression that a templated function will exist

Re: Troubles with template constraints on string and static if

2018-04-26 Thread Alex via Digitalmars-d-learn
On Thursday, 26 April 2018 at 15:06:49 UTC, sungal wrote: I have this piece of code and I can't understand why the `static if` conditionals are always false. ``` import std.digest.sha; import std.file; import std.stdio; void main() { auto hash1 = produceHash!string("prova.d"); auto

Re: Getting the overload set of a template

2018-04-23 Thread Alex via Digitalmars-d-learn
On Monday, 23 April 2018 at 17:46:10 UTC, Arafel wrote: You could also argue that function overloads are just semantically equivalent to a single function with variadic arguments. It is not. As there are exact known, distinct, finite numbers and types of arguments of functions, which can

Re: Getting the overload set of a template

2018-04-23 Thread Alex via Digitalmars-d-learn
On Monday, 23 April 2018 at 16:16:09 UTC, Arafel wrote: ``` import std.meta; void main() { pragma(msg, __traits(getMember, A, "Foo1").stringof); // Foo1(int N) if (N & 1) pragma(msg, __traits(getAttributes, __traits(getMember, A, "Foo1"))[0]); // tuple("int", "odd") alias f1a =

Re: Getting the overload set of a template

2018-04-23 Thread Alex via Digitalmars-d-learn
On Monday, 23 April 2018 at 15:44:10 UTC, Simen Kjærås wrote: Ah, but I'm not looking to instantiate the templates, but to learn about them - how many parameters do they take? Are their UDAs different, so that I should warn the programmer? Must I wrap them in different ways? So... Do I

Re: Getting the overload set of a template

2018-04-23 Thread Alex via Digitalmars-d-learn
On Monday, 23 April 2018 at 14:22:13 UTC, Simen Kjærås wrote: As with all things D, the only real spec is the compiler source code. :p :( :p Proving that two templates are equivalent is in general impossible, since any amount of wasted computation could be performed before the end result is

Re: Getting the overload set of a template

2018-04-23 Thread Alex via Digitalmars-d-learn
On Monday, 23 April 2018 at 10:57:59 UTC, Simen Kjærås wrote: There is no official definition. That's because some natural rewrite rules are implied, which are very general, I assume... How official do you want it to be? That's the only definition in common use by others in the context of

Re: Getting the overload set of a template

2018-04-23 Thread Alex via Digitalmars-d-learn
On Monday, 23 April 2018 at 07:49:39 UTC, Simen Kjærås wrote: On Monday, 23 April 2018 at 04:58:38 UTC, Alex wrote: On Monday, 23 April 2018 at 00:26:23 UTC, Simen Kjærås wrote: There is a limited set of lowerings, and they are defined in the language, not in user code. They include operator

Re: Getting the overload set of a template

2018-04-22 Thread Alex via Digitalmars-d-learn
On Monday, 23 April 2018 at 00:26:23 UTC, Simen Kjærås wrote: // tuple("Has foo1_A") pragma(msg, __traits(getAttributes, foo1!"a")); // tuple("Has foo1_A") pragma(msg, __traits(getAttributes, foo2!"a")); // tuple("Has foo1_B") pragma(msg, __traits(getAttributes, foo1!"b")); // tuple("Has

Re: Getting the overload set of a template

2018-04-22 Thread Alex via Digitalmars-d-learn
On Sunday, 22 April 2018 at 18:25:29 UTC, Simen Kjærås wrote: No lowering occurs here. A lowering is when the compiler takes one piece of syntax and replaces it with a different one, usually one that's more verbose. In a way, it's kind of like a template being instantiated, in that you write

Re: Getting the overload set of a template

2018-04-21 Thread Alex via Digitalmars-d-learn
On Saturday, 21 April 2018 at 19:51:05 UTC, Simen Kjærås wrote: On Saturday, 21 April 2018 at 11:23:33 UTC, Alex wrote: So, do you mean, that the constraint belongs to the interface of a template? Not necessarily - it depends on what you want to achieve. The only thing I mean is that the

Re: Getting the overload set of a template

2018-04-21 Thread Alex via Digitalmars-d-learn
On Thursday, 19 April 2018 at 17:55:47 UTC, Simen Kjærås wrote: Your first example defines two templates (which are overloads of the same name), the second only one. There's no ambiguity there. So, do you mean, that the constraint belongs to the interface of a template?

Re: Getting the overload set of a template

2018-04-19 Thread Alex via Digitalmars-d-learn
On Thursday, 19 April 2018 at 13:57:04 UTC, Simen Kjærås wrote: Currently, there is no way (that I've found, at least) to do this. If you have a workaround, that's great, but there really should be a way - probably __traits(getOverloads). Having __traits(getOverloads) return templates as well

Re: Assoc. Array and struct with immutable member

2018-04-17 Thread Alex via Digitalmars-d-learn
On Tuesday, 17 April 2018 at 11:07:55 UTC, bauss wrote: Even though it works in static this, then it still looks like a bug if you ask me, because the associative array itself isn't immutable. Yeah... I'm not sure, if this behavior is wanted, too... If you argue, that an absent field in in

Re: Assoc. Array and struct with immutable member

2018-04-15 Thread Alex via Digitalmars-d-learn
On Sunday, 15 April 2018 at 17:59:01 UTC, Dgame wrote: How am I supposed to insert a struct with immutable members into an assoc. array? Reduced example: struct A { immutable string name; } A[string] as; as["a"] = A("a"); // Does not work Via a static this() it would work. But

Re: "%s"-format template function arguments

2018-04-15 Thread Alex via Digitalmars-d-learn
On Sunday, 15 April 2018 at 12:04:19 UTC, vladdeSV wrote: Hello people of D-land. In a template function, I want to format all arguments as if it was an array. Se this snippet of code: foo(1,2,3); void foo(T...)(T args) { writefln("expected: %s", [1,2,3]);

Re: template evaluation

2018-04-14 Thread Alex via Digitalmars-d-learn
Ok, trying to reduce my example a little bit, I arrived at this: ´´´ void main(){} struct D { size_t dummy; auto static s = S!D.init; } struct S(alias container = null) { pragma(msg, container); static if(__traits(compiles, __traits(allMembers,

template evaluation

2018-04-14 Thread Alex via Digitalmars-d-learn
Hi all, I must overlook something, but given this: ´´´ void main(){} static assert(isMatching!(D, S!(D, true))); // place 1: works as expected. struct D { auto static s = S!(typeof(this), true).init; } enum bool isMatching(T, U) = (){ bool b;

Re: Is using function() in templates possible at all?

2018-04-11 Thread Alex via Digitalmars-d-learn
On Wednesday, 11 April 2018 at 21:07:03 UTC, Sjoerd Nijboer wrote: class SortedList(T, int function(T) comparer) I would say, alias template parameter is your friend. https://dlang.org/spec/template.html#TemplateAliasParameter ´´´ import std.stdio; import std.range; void main() {

Re: Source expression passed to a lazy parameter

2018-04-09 Thread Alex via Digitalmars-d-learn
On Monday, 9 April 2018 at 09:20:42 UTC, Simen Kjærås wrote: Nope. Something along the lines of __traits(getSource, arg) has been discussed occasionally. Is this available somehow? And/or do you have a link to the discussion, maybe?

Re: Store struct tuple of alias and access members through it?

2018-04-07 Thread Alex via Digitalmars-d-learn
On Saturday, 7 April 2018 at 13:31:01 UTC, Timoses wrote: Simen was faster :) In my solution I simply ignore such things as functions... But there is the cool delegate creation approach in Simen's solution for this. I can handle arrays instead. :) And I got rid of tupelof acting on an

Re: std.datetime.systime: days Deprecation message

2018-04-07 Thread Alex via Digitalmars-d-learn
On Saturday, 7 April 2018 at 17:25:07 UTC, Vino wrote: Hi All, Request your help on the below Deprecation message. import std.datetime.systime: Clock, days, SysTime; void main (int AgeSize) { int AgeSize = 1 auto ct2 = Clock.currTime(), st2 = ct2 + days(-AgeSize); } test.d(30): Deprecation:

Re: c2 classes

2018-04-06 Thread Alex via Digitalmars-d-learn
On Friday, 6 April 2018 at 13:41:50 UTC, aerto wrote: its possible to make this work ?? import std.stdio; class UUsers { public: int age; } class users { public: int[int] uid; } void main() { users newuser = new users(); newuser.uid[0].age = 23;

Re: Compile-time variables

2018-04-06 Thread Alex via Digitalmars-d-learn
On Friday, 6 April 2018 at 02:20:29 UTC, Kayomn wrote: Wrong example code, here's the correct example: switch (queryString(childJson,"type")) { case (typeof (Sprite).name): child =

Re: Construct immutable member in derived class

2018-04-05 Thread Alex via Digitalmars-d-learn
On Thursday, 5 April 2018 at 19:31:39 UTC, Jonathan M Davis wrote: And you can't abstract whether a member variable is marked with immutable or not. That's part of the variable. Declaring an immutable instance of an object would then treat the member variable in immutable for that instance, so

Re: Construct immutable member in derived class

2018-04-05 Thread Alex via Digitalmars-d-learn
On Wednesday, 4 April 2018 at 21:49:08 UTC, Timoses wrote: "[...] the construction of the base class can be independent from the derived one." Hm, the points 7 and 8 don't clearly state what you wrote. Yes :) But it somehow does make sense.. Still I wonder why that is so. Let's say you

Re: Construct immutable member in derived class

2018-04-04 Thread Alex via Digitalmars-d-learn
On Wednesday, 4 April 2018 at 16:05:52 UTC, Timoses wrote: This becomes a bit hideous, unfortunately, when there are many initializations involved. Found this, but it doesn't mention anything about derived classes.. https://dlang.org/spec/class.html#field-init Here is something:

Re: Better way to append to array than ~= ?

2018-04-03 Thread Alex via Digitalmars-d-learn
On Tuesday, 3 April 2018 at 20:02:46 UTC, Vladimirs Nordholm wrote: On Tuesday, 3 April 2018 at 19:53:11 UTC, Meta wrote: On Tuesday, 3 April 2018 at 19:02:25 UTC, Vladimirs Nordholm wrote: [...] In this specific case, since you know the length of `Args`, you can pre-allocate an array of

Re: mixin break; in switch containing static foreach

2018-04-03 Thread Alex via Digitalmars-d-learn
On Tuesday, 3 April 2018 at 19:31:50 UTC, Vladimirs Nordholm wrote: My base problem is that I want to mixin `break` into a switch statement, but the mixin is within a static foreach. Take a look at the following code: switch(foo) { static foreach(f; EnumMembers!Foo) {

Re: is this even possible? newbie + mixin template + foreach (allMembers)

2018-04-03 Thread Alex via Digitalmars-d-learn
On Tuesday, 3 April 2018 at 18:57:29 UTC, WebFreak001 wrote: you need to use a static foreach for this. You can insert a static foreach basically where you can insert a function definition like void foo() {} foreach is more like a function call like foo(), so you can't put it in the mixin

Re: Optional parameters?

2018-04-01 Thread Alex via Digitalmars-d-learn
On Sunday, 1 April 2018 at 15:54:16 UTC, Steven Schveighoffer wrote: void main() { foo(1); // error int x; foo(x); // error } For the first line, I had the same problem a while ago... https://issues.dlang.org/show_bug.cgi?id=15792

Re: converting a number into bit array

2018-03-25 Thread Alex via Digitalmars-d-learn
On Sunday, 25 March 2018 at 11:32:56 UTC, Alex wrote: how to convert a number to a BitArray as fast as possible, given that the BitArray is already allocated to the needed length? Is bit checking the way to go, or is there a way to cast one to the other somehow? Via bit checking I would end

converting a number into bit array

2018-03-25 Thread Alex via Digitalmars-d-learn
Given this, ´´´ import std.bitmanip; import core.stdc.limits; void main() { BitArray ba; ba.length = size_t.sizeof * CHAR_BIT; // enough length, known at compile time size_t arbitrary; // = random size_t, not known at compile time // ba ???assign??? arbitrary;

Re: cannot access frame of function

2018-03-23 Thread Alex via Digitalmars-d-learn
On Friday, 23 March 2018 at 03:38:22 UTC, Jordan Wilson wrote: I have this same issue. Anyone have any thoughts on a workaround? For completeness: https://issues.dlang.org/show_bug.cgi?id=17841

Re: how to make private class member private

2018-03-18 Thread Alex via Digitalmars-d-learn
On Sunday, 18 March 2018 at 09:56:31 UTC, psychoticRabbit wrote: However, are there no scenarios in which the person writing that module, would not want to encapsulate their class, or some parts of it, from the rest of the module (while not being forced to put the class in it's own file)? If

Re: Is there any web browser control in D Lang to display html file ?

2018-03-16 Thread Alex via Digitalmars-d-learn
On Friday, 16 March 2018 at 10:31:51 UTC, Jayam wrote: I creating one simple desktop application using dlang. I need to display some html file in my desktop application. How can make it works ? Do you mean something like this? http://vibed.org/api/diet.dom/

Re: RefRange behavior

2018-03-14 Thread Alex via Digitalmars-d-learn
On Wednesday, 14 March 2018 at 10:22:45 UTC, Alex wrote: Is there a simple workaround, maybe? ok, the workaround would be to enumerate the member and to use the former notation.

RefRange behavior

2018-03-14 Thread Alex via Digitalmars-d-learn
Hi all, given this: ´´´ import std.range; size_t[] arr; struct S { RefRange!(size_t[]) member; } void fun(ref size_t numByRef){} void main() { arr.length = 42; S s; s.member = refRange(); static assert(__traits(compiles, fun(s.member[0])));

Re: how to make private class member private

2018-03-13 Thread Alex via Digitalmars-d-learn
On Tuesday, 13 March 2018 at 07:39:04 UTC, psychoticRabbit wrote: I don't have any objection to the idea that a module can have privileged access to members of classes within that model. It sounds sensible enough, if the module is a level of encapsulation also. My arguments is that, this

Re: Generic Property Implementation

2018-03-12 Thread Alex via Digitalmars-d-learn
On Monday, 12 March 2018 at 13:04:54 UTC, Simen Kjærås wrote: On Monday, 12 March 2018 at 10:37:00 UTC, Alex wrote: Sure, you have. https://dlang.org/spec/struct.html#assign-overload Point #4. In this case, ref S opAssign(ref S rhs) { return this; } True. Can you fix these, too? struct

Re: Generic Property Implementation

2018-03-12 Thread Alex via Digitalmars-d-learn
On Monday, 12 March 2018 at 09:54:20 UTC, Simen Kjærås wrote: But I don't have a hook to update the pointer when the struct is moved. The GC may move my struct without informing me in any way. In fact, even just a copy construction will break this: struct S { S* ptr; this(int dummy)

Re: Generic Property Implementation

2018-03-12 Thread Alex via Digitalmars-d-learn
On Monday, 12 March 2018 at 07:04:19 UTC, Simen Kjærås wrote: On Saturday, 10 March 2018 at 17:43:06 UTC, Simen Kjærås wrote: I'm not sure how fixable this is, but I am sure that there's plenty of benefit to being able to write code like this: struct S { int n, m; SomeType!(() => n +

Re: issue with inf from exp function

2018-03-07 Thread Alex via Digitalmars-d-learn
On Wednesday, 7 March 2018 at 15:44:28 UTC, Matt Gamble wrote: I don't understand why I'm getting an 'inf' by raising E to a real number, e^^710.0L. See below. import std.stdio; import std.math; unittest { writefln("ln(largest double) = %s", log(double.max)); // 709.783

Re: Generic test bit function (core.bitop)

2018-03-07 Thread Alex via Digitalmars-d-learn
On Tuesday, 6 March 2018 at 10:37:30 UTC, Pierre wrote: Hi all, I would like to use bt function (core.bitop) on generic array but it seems that's not possible. I would like to know if there is some reasons to have a fixed type (size_t) instead of something like : pure @system int bt(T)(in

Re: Double link list

2018-02-24 Thread Alex via Digitalmars-d-learn
On Saturday, 24 February 2018 at 09:48:13 UTC, Joel wrote: I'm trying some code for practice, but it isn't working properly - it prints just one number when printing in reverse. [...] the first writeln destroys the range via popFront, I think. As if you comment it out, the writeln with

Re: Trying to forward unwrapped opDispatch names to alias this

2018-02-20 Thread Alex via Digitalmars-d-learn
On Monday, 19 February 2018 at 08:28:22 UTC, aliak wrote: On Monday, 19 February 2018 at 01:00:23 UTC, Adam D. Ruppe wrote: On Monday, 19 February 2018 at 00:42:05 UTC, aliak wrote: struct B(T) { T t; A a; alias a this; auto opDispatch(string name)() if (hasMember!(T, name)) {

Re: static opSlice is not possible

2018-02-16 Thread Alex via Digitalmars-d-learn
On Friday, 16 February 2018 at 13:35:03 UTC, Basile B. wrote: Technically iy's a multi dimensional slicing but there's a constraint on the number of dimension allowed so that it looks exactly like a normal opSlice. By the way, i reduced too much. This shows more how it works: struct Foo {

Re: static opSlice is not possible

2018-02-15 Thread Alex via Digitalmars-d-learn
On Thursday, 15 February 2018 at 23:31:23 UTC, Jonathan M Davis wrote: On Thursday, February 15, 2018 23:22:17 Adam D. Ruppe via Digitalmars-d- learn wrote: On Thursday, 15 February 2018 at 23:20:42 UTC, Jonathan M Davis wrote: > The only overloaded operator that I'd expect to work as >

static opSlice is not possible

2018-02-15 Thread Alex via Digitalmars-d-learn
Hi all, a short question about an old bug: https://issues.dlang.org/show_bug.cgi?id=11877 Are there reasons, which speaks against this feature? And maybe another one, more general: Is there any place, where it is documented, which operators can work in static mode and which cannot?

Re: typedef behavior

2018-02-12 Thread Alex via Digitalmars-d-learn
On Monday, 12 February 2018 at 11:25:40 UTC, Simen Kjærås wrote: I'm sorry, I was apparently unclear. When I said 'static array' above, I meant 'static member'. Since we've been using arrays in our examples, there could be conflation of ideas there. The fact that you can access (and even

Re: typedef behavior

2018-02-12 Thread Alex via Digitalmars-d-learn
On Monday, 12 February 2018 at 09:37:56 UTC, Simen Kjærås wrote: Not really, since D doesn't have a concept of an address associated with a type, only with instances of it. So when you use a static array, the address is hard-coded. -- Simen Ok... so the query on ptr on a static is not

Re: typedef behavior

2018-02-12 Thread Alex via Digitalmars-d-learn
On Monday, 12 February 2018 at 08:51:14 UTC, Simen Kjærås wrote: I agree that'd be nice. Sadly, it's not a reasonable expectation. :( :) A more extreme example: You have a compiled library, and some .di (header) files. In one of those files is this code: struct S { static int[] arr;

Re: typedef behavior

2018-02-11 Thread Alex via Digitalmars-d-learn
On Sunday, 11 February 2018 at 15:18:11 UTC, Simen Kjærås wrote: Basically, Typedef looks like this: struct Typedef(T) { T _payload; // Forward method calls, member access, etc, to _payload. } If T looks like this: struct T { static int[3] arr; void foo() { arr[0]++; } } How

Re: typedef behavior

2018-02-10 Thread Alex via Digitalmars-d-learn
On Saturday, 10 February 2018 at 02:55:26 UTC, Alex wrote: bug filed https://issues.dlang.org/show_bug.cgi?id=18416

Re: typedef behavior with @disable this()

2018-02-10 Thread Alex via Digitalmars-d-learn
On Sunday, 11 February 2018 at 00:54:07 UTC, Simen Kjærås wrote: Typedef explicitly initializes the wrapped value to T.init, thus circumventing the disabled default constructor. Filed a bug: https://issues.dlang.org/show_bug.cgi?id=18415 -- Simen Thanks!

typedef behavior with @disable this()

2018-02-10 Thread Alex via Digitalmars-d-learn
Do I overlook something? /// --- code --- /// import std.typecons; void main(){} static assert(!__traits( compiles, E())); static assert(!__traits( compiles, MyE())); // line 6 struct E { size_t dummy; @disable this(); this(size_t val) { dummy = val; } } alias MyE =

Re: typedef behavior

2018-02-09 Thread Alex via Digitalmars-d-learn
On Saturday, 10 February 2018 at 02:08:50 UTC, Alex wrote: Inside of the struct E I define more then one static array. Namely, one for each Typedef I plan to instantiate. The Typedefs have to be known at compile time, so the amount of them has to be known by me :) Then, during the

Re: typedef behavior

2018-02-09 Thread Alex via Digitalmars-d-learn
On Saturday, 10 February 2018 at 01:23:20 UTC, Ali Çehreli wrote: > > Yup. They are shared by two Typedef instantiations with different cookies. > > So... > The question is two-fold: > Would it help to alter the init value of the Typedef? > If yes, how to alter it? > If no, is this a bug? I

Re: typedef behavior

2018-02-09 Thread Alex via Digitalmars-d-learn
On Saturday, 10 February 2018 at 01:01:39 UTC, Ali Çehreli wrote: On 02/09/2018 03:45 PM, Alex wrote: > A question about Typedef usage: > Say, I have the following circumstances > > /// --- code --- /// > > import std.typecons; > > void main() > { > MyEA ea; > MyEB eb; >

typedef behavior

2018-02-09 Thread Alex via Digitalmars-d-learn
A question about Typedef usage: Say, I have the following circumstances /// --- code --- /// import std.typecons; void main() { MyEA ea; MyEB eb; ea.tarr.length = 5; static assert(!is(MyEA == MyEB)); static assert(!is(MyEA == E)); static

Re: Lambda returning a lambda?

2018-02-01 Thread Alex via Digitalmars-d-learn
On Thursday, 1 February 2018 at 11:51:11 UTC, aliak wrote: Is there a way to do this: import std.stdio; void main() { alias f = (a) => (b) => a * b; f(2)(3).writeln; } Error now is: Error: template lambda has no type Cheers This works: void main() { auto f = (size_t x) =>

Re: BitFlags usage

2018-01-25 Thread Alex via Digitalmars-d-learn
On Thursday, 25 January 2018 at 13:05:07 UTC, Ali Çehreli wrote: On 01/25/2018 03:50 AM, Alex wrote:     r |= cast(BitFlags!Rs)val; // line 20 ... from asignment r |= BitFlags!Rs(cast(Rs)val); Ali Thanks :)

Re: static weirdness

2018-01-25 Thread Alex via Digitalmars-d-learn
On Thursday, 25 January 2018 at 12:06:07 UTC, Jonathan M Davis wrote: On Thursday, January 25, 2018 10:17:34 Kagamin via Digitalmars-d-learn wrote: On Wednesday, 24 January 2018 at 02:01:54 UTC, Jonathan M Davis wrote: > (so there's no need to dereference the pointer to call it) It used to

Re: static weirdness

2018-01-25 Thread Alex via Digitalmars-d-learn
On Thursday, 25 January 2018 at 10:17:34 UTC, Kagamin wrote: On Wednesday, 24 January 2018 at 02:01:54 UTC, Jonathan M Davis wrote: (so there's no need to dereference the pointer to call it) It used to check this pointer with an assert. When did it change? Fortunately, I have some

BitFlags usage

2018-01-25 Thread Alex via Digitalmars-d-learn
I have a question on usage of BitFlags, described here: https://dlang.org/library/std/typecons/bit_flags.html and/or on bitop https://dlang.org/phobos/core_bitop.html#.bsf A similar example to the bit flags example is given here: [code] import std.typecons; enum Rs : ubyte { None,

Re: static weirdness

2018-01-23 Thread Alex via Digitalmars-d-learn
On Wednesday, 24 January 2018 at 02:01:54 UTC, Jonathan M Davis wrote: On Wednesday, January 24, 2018 01:48:45 Alex via Digitalmars-d-learn wrote: the story of https://forum.dlang.org/thread/qknxjxzbaowmsjdng...@forum.dlang.org continues How can this be? void main() { auto s = S

Re: static weirdness

2018-01-23 Thread Alex via Digitalmars-d-learn
On Wednesday, 24 January 2018 at 01:48:45 UTC, Alex wrote: Ah... I figured it out. For using the function of S, an object does not have to exist... And in case I would return a member from S, there is a segmentation violation, as expected. So, everything is ok. Sorry for noise.

static weirdness

2018-01-23 Thread Alex via Digitalmars-d-learn
the story of https://forum.dlang.org/thread/qknxjxzbaowmsjdng...@forum.dlang.org continues How can this be? void main() { auto s = S(); auto t = T!s(); assert(typeof(t).dummy == null); assert(t.dummy == null); t.foo; } struct S { auto fun() { return 42;

Re: static function and access frame

2018-01-23 Thread Alex via Digitalmars-d-learn
On Tuesday, 23 January 2018 at 23:22:09 UTC, Steven Schveighoffer wrote: So, if change the fun to static, it cannot pickup the pointer and therefore can't call anything of the aliased object. If I get it right... I think so. But this is a guess, as the generated call clearly never uses

Re: static function and access frame

2018-01-23 Thread Alex via Digitalmars-d-learn
On Tuesday, 23 January 2018 at 22:59:31 UTC, Steven Schveighoffer wrote: On 1/23/18 5:52 PM, Steven Schveighoffer wrote: I don't know the reason. You would think that accessing s would be relative to T.fun's stack frame, and have nothing to do with an instance of T. using -vcg-ast gives a

Re: static function and access frame

2018-01-23 Thread Alex via Digitalmars-d-learn
On Tuesday, 23 January 2018 at 22:52:47 UTC, Steven Schveighoffer wrote: No: void main() { auto s = S(); auto t = T!s(); t.fun; } struct S { void fun(){} } struct T(alias s){ static fun() { s.fun; } } Fails in 2.078. I don't know the reason. You would think that accessing s would

Re: static function and access frame

2018-01-23 Thread Alex via Digitalmars-d-learn
On Tuesday, 23 January 2018 at 22:33:31 UTC, Ali Çehreli wrote: On 01/23/2018 01:51 PM, Alex wrote: > Ok, I'm quite sure, I overlooked something. > > First version, working > > [code] > void main() > { > auto s = S(); > auto t = T!s(); > t.fun; > } > struct S { void fun(){} } >

static function and access frame

2018-01-23 Thread Alex via Digitalmars-d-learn
Ok, I'm quite sure, I overlooked something. First version, working [code] void main() { auto s = S(); auto t = T!s(); t.fun; } struct S { void fun(){} } struct T(alias s){ auto fun() { s.fun; } } [/code] Now, the fun method of struct T has to become static and the

Re: TemplateOf behavior

2018-01-06 Thread Alex via Digitalmars-d-learn
On Saturday, 6 January 2018 at 22:25:48 UTC, ag0aep6g wrote: On Saturday, 6 January 2018 at 19:58:10 UTC, Alex wrote: template T(alias S) { struct T { this(int dummy) { static assert(__traits(isSame, TemplateOf!(T!arr), T)); } } } Now

TemplateOf behavior

2018-01-06 Thread Alex via Digitalmars-d-learn
//code starts import std.traits; void main() { static assert(__traits(isSame, TemplateOf!(T!arr), T)); } size_t[] arr; struct T(alias S) { mixin Contents!() contents; this(Args)(ref Args args) { contents.__ctor(42); } } static

Re: using .init reliably

2017-10-31 Thread Alex via Digitalmars-d-learn
On Tuesday, 31 October 2017 at 02:24:48 UTC, Steven Schveighoffer wrote: Yeah... my problem is, that I don't know it at compile time. You know it at language time :) :) The .init property is provided by the compiler, unless you define it. It means the default value of the type. Here, I'm

Re: using .init reliably

2017-10-30 Thread Alex via Digitalmars-d-learn
On Monday, 30 October 2017 at 15:03:25 UTC, Steven Schveighoffer wrote: This should also be disallowed. In order to know x.init means what it normally means, we shouldn't allow overriding it. This is the point of this thread, and the impetus for renaming of TypeInfo.init(). Yeah... my

Re: using .init reliably

2017-10-30 Thread Alex via Digitalmars-d-learn
Sorry for dig out this posting, but this one is more recent, than http://forum.dlang.org/thread/k15of5$22ub$1...@digitalmars.com?page=1 and my question is just beyond the two: I'm with you, regarding that the standard init property should not be overridden. But how about to override it with a

Re: Two way struct wrapper

2017-10-14 Thread Alex via Digitalmars-d-learn
On Saturday, 14 October 2017 at 12:39:17 UTC, Alex wrote: ok, the last version for now. Without assumptions on alias number. Sorry for noise. https://run.dlang.io/is/OSJYtY

Re: Two way struct wrapper

2017-10-14 Thread Alex via Digitalmars-d-learn
On Saturday, 14 October 2017 at 11:25:20 UTC, Alex wrote: of course, with the proper operator in line 32 return T(mixin("this" ~ op ~ "f")); https://run.dlang.io/is/jGKVYN

Re: Two way struct wrapper

2017-10-14 Thread Alex via Digitalmars-d-learn
On Wednesday, 11 October 2017 at 12:35:51 UTC, drug wrote: Using `alias this` it's easy to make wrapper for structure that calls wrapped structure methods like its own. This is one way - from wrapper to wrapped transformation. Is it possible to create the opposite way from wrapped to wrapper?

exclude members at compile time

2017-10-07 Thread Alex via Digitalmars-d-learn
Ok, what I'm trying to do is the following: take a type and a value of its type; given a known member of the type, (re?)create a similar type, without this very known member. What does work is this: /// --- code --- void main() { S s; s.i = 42; s.d = 73.0;

Re: template auto deduction

2017-10-06 Thread Alex via Digitalmars-d-learn
On Friday, 6 October 2017 at 21:42:40 UTC, Steven Schveighoffer wrote: What you need is IFTI or "Implicit Function Template Instantiation" Note the "Function" part of it, in that it's only valid for functions. So you need a factory function: auto m(T)(T x) { return M!(T)(x); } ...

Re: Iterating over functions in module in order?

2017-10-06 Thread Alex via Digitalmars-d-learn
On Thursday, 5 October 2017 at 00:24:12 UTC, Jerry wrote: Any ideas on how someone could iterate over functions in a module as they appear, rather than any random order, without having to manually label them? Do you mean something like this? /// --- code --- module test165; import

template auto deduction

2017-10-06 Thread Alex via Digitalmars-d-learn
Hey, template gurus :) given this: struct M(alias I : S!E, alias S, E...) { R!E r; this(S)(S initStruct)// line 4 { r = R!E(initStruct); } } struct R(E...) { this(S)(S initStruct)// line 12 { // do some cool

Re: cannot access frame of function

2017-09-18 Thread Alex via Digitalmars-d-learn
On Monday, 18 September 2017 at 18:49:54 UTC, ag0aep6g wrote: Doesn't work for me. This still fails compilation with the same error: import std.algorithm.iteration : sum, cumulativeFold; void main() { double[5] a; auto asum = 1.23; auto jProbs = a[].cumulativeFold!((a, b) =>

cannot access frame of function

2017-09-18 Thread Alex via Digitalmars-d-learn
Hi all, given this code: import std.algorithm.iteration : sum, cumulativeFold; void main() { double[5] a; a = 0; foreach(el; a) assert(el == 0); a[0] = 1.0; a[1] = 2.0; a[2] = 3.0; a[3] = 4.0; a[4] = 5.0; foreach(el; a)

Re: Synax for variadic template

2017-09-01 Thread Alex via Digitalmars-d-learn
On Friday, 1 September 2017 at 10:01:16 UTC, Nicholas Wilson wrote: b.arr refers to an `(AliasSeq!(int, double))[]`, so with `b.arr[0] ~= 5;` you are trying to append a integer to an array of pairs of ints and doubles, which you can't do. b.arr[0] ~= ElementType!(typeof(b.arr))(5,42.0);

Synax for variadic template

2017-09-01 Thread Alex via Digitalmars-d-learn
Hi all! Say, I have struct A(T...) { T arr; } struct B(T...) { T[] arr; } void main() { A!(int[], double[]) a; a.arr[0] ~= 5; a.arr[0] ~= 6; static assert(!__traits(compiles, a.arr[0] ~= 3.5)); a.arr[1] ~= 19.8;

Re: gcd with doubles

2017-09-01 Thread Alex via Digitalmars-d-learn
On Sunday, 27 August 2017 at 23:13:24 UTC, Moritz Maxeiner wrote: On Sunday, 27 August 2017 at 19:47:59 UTC, Alex wrote: [...] To expand on the earlier workaround: You can also adapt a floating point to string algorithm in order to dynamically determine an upper bound on the number of after

Re: gcd with doubles

2017-08-27 Thread Alex via Digitalmars-d-learn
ok... googled a little bit. Seems to be the problem of the kind floating poing <--> decimal... Will try to get by with some division and lrint logic, as there is a lack of definition, how to define a gcd in general case. For example with 30 and 0.16. Never mind...

gcd with doubles

2017-08-27 Thread Alex via Digitalmars-d-learn
Hi, all. Can anybody explain to me why void main() { import std.numeric; assert(gcd(0.5,32) == 0.5); assert(gcd(0.2,32) == 0.2); } fails on the second assert? I'm aware, that calculating gcd on doubles is not so obvios, as on integers. But if the library accepts

Re: Array of Template instantiations

2017-07-20 Thread Alex via Digitalmars-d-learn
On Thursday, 20 July 2017 at 12:33:43 UTC, Alex wrote: The Problem is, i dont know what type WHAT_TYPE is / i don´t know how to build a loopable something of futures. Ok, i think i understood now. my function `load` returns `KpiResponseEntity` so Future!(KpiResponseEntity)[] futures; seems

Array of Template instantiations

2017-07-20 Thread Alex via Digitalmars-d-learn
Hi, i don't even know if the subject makes any sense :) What i want to achieve is: instead of making: auto v_a = async( , queryA ); auto v_b = async( , queryB ); auto v_c = async( , queryC ); ( async is a function from vibe and returns a "Future" - see

Re: templatized delegate

2017-05-23 Thread Alex via Digitalmars-d-learn
On Tuesday, 23 May 2017 at 16:38:14 UTC, Stanislav Blinov wrote: Ah, now I think I get it. You want to store a single delegate that could be called with different sets of arguments? No, you can't do that: you need an actual delegate instance, and for that, you need to know the signature, at

Re: templatized delegate

2017-05-23 Thread Alex via Digitalmars-d-learn
On Tuesday, 23 May 2017 at 18:14:34 UTC, ag0aep6g wrote: Something like this: import core.vararg; import std.meta: AliasSeq, staticMap; import std.traits: isCopyable; struct A { void delegate(...) dg; auto fun(T, U ...)(T t, auto ref U u) { template

Re: templatized delegate

2017-05-23 Thread Alex via Digitalmars-d-learn
On Tuesday, 23 May 2017 at 11:05:09 UTC, Stanislav Blinov wrote: void variadic(Args...)(auto ref Args args) { /* ... */ } This infers whether you pass lvalues or rvalues. If passing further down the chain of such calls is needed, one can use std.functional : fowrard : yes... void

Re: templatized delegate

2017-05-23 Thread Alex via Digitalmars-d-learn
On Tuesday, 23 May 2017 at 10:42:54 UTC, Nicholas Wilson wrote: On Tuesday, 23 May 2017 at 10:30:56 UTC, Alex wrote: On Monday, 22 May 2017 at 21:44:17 UTC, ag0aep6g wrote: With that kind of variadics, you're not dealing with a template. A (run-time) variadic delegate is an actual delegate,

Re: templatized delegate

2017-05-23 Thread Alex via Digitalmars-d-learn
On Monday, 22 May 2017 at 21:44:17 UTC, ag0aep6g wrote: With that kind of variadics, you're not dealing with a template. A (run-time) variadic delegate is an actual delegate, i.e. a value that can be passed around. But the variadic stuff is a bit weird to use, and probably affects performance.

<    1   2   3   4   5   6   >