Re: Order of interfaces

2019-06-21 Thread Tomas via Digitalmars-d-learn

On Friday, 21 June 2019 at 20:50:02 UTC, user1234 wrote:

On Friday, 21 June 2019 at 20:42:00 UTC, Tomas wrote:

Does it matter in which order a class inherits from interfaces?

   class A : Interface1, Interface2{ ... }

   vs

   class A : Interface2, Interface1{ ... }

Conceptually it should not matter, but I'm getting really 
weird segfault errors with one version and no errors with the 
other version.


compiler segfault or segfault when the program runs ?

I still do not know what I'm doing wrong, but does anyone have 
an idea why the order might matter?


I'm getting segfault when running the program.


Order of interfaces

2019-06-21 Thread Tomas via Digitalmars-d-learn

Does it matter in which order a class inherits from interfaces?

   class A : Interface1, Interface2{ ... }

   vs

   class A : Interface2, Interface1{ ... }

Conceptually it should not matter, but I'm getting really weird 
segfault errors with one version and no errors with the other 
version.


I still do not know what I'm doing wrong, but does anyone have an 
idea why the order might matter?


Re: Parameter pack expansion

2019-05-30 Thread Tomas via Digitalmars-d-learn

On Thursday, 30 May 2019 at 20:55:00 UTC, Q. Schroll wrote:
If it would be implemented, you could place your parameter pack 
into a Tuple-like structure with an opDispatch that returns 
such a Tuple again, but the contents would be the member 
components "projection" to the member. It's doable[2], but the 
lack of indexing the pack is the main blocker.


 ...

[1] https://github.com/dlang/DIPs/pull/155
[2] https://run.dlang.io/is/tIxmQS


Thanks! Sounds interesting, but right now it is a bit over my 
head. It will take me some time digest it.


Re: Parameter pack expansion

2019-05-30 Thread Tomas via Digitalmars-d-learn

On Thursday, 30 May 2019 at 20:34:18 UTC, Adam D. Ruppe wrote:

Foo foo;
test(foo.tupleof); // works!


This is really neat! I will definitely use this in the future.


import std.meta;

then staticMap is like what your myMap thing was.

http://dpldocs.info/experimental-docs/std.meta.staticMap.html


I'm already using `staticMap` to transform types but can 
`staticMap` be used also to transform values? I do not see how.


Parameter pack expansion

2019-05-30 Thread Tomas via Digitalmars-d-learn
I'm very new to D, coming from C++ I'm missing parameter pack 
expansion and fold expressions.


For example, I want to write a function `f(x[0], ..., x[n])` 
which accepts any number of objects and calls `g(x[0].member, 
..., x[n].member)`.


In C++, I would write this:

   template
   void f(X ... x){
  g(x.member...);
   }

Similar transformation can be also done in C++ on types too:

   template
   using F = G;

How do I do something like this in D?

Basicaly, how do I preform tuple transformations

X = (X[0], ..., X[n]) ->  TX = (X[0].Member, ... ,X[n].Member)
x = (x[0], ..., x[n]) ->  tx = (x[0].member, ... ,x[0].member)

Here is my best shot in D, it kind of does what I want, but I 
have do define my own map function `myMap`.


   // Helper function
   auto myMap(alias Fun, X...)(X x) {
 import std.typecons;

 static if (X.length > 1)
   return tuple(Fun(x[0])) ~ myMap!(Fun)(x[1 .. $]);
 else
   return tuple(Fun(x[0]));
   }

   // Do the transformation inside
   void foo(X...)(X x){
  // type transformation
  alias MemberOf(T) = T.Member;
  alias XM = staticMap!(MemberOf, X);

  // value transformation, notice the `expand`!
  auto tx  = myMap!(x => x.member)(x).expand;
   }

What is the recommended what to do this in D? Surely, there has 
to be a standard function which does exactly(probably better) the 
same thing as what `myMap` does.