Re: @nogc with opApply

2018-08-11 Thread tide via Digitalmars-d-learn

On Saturday, 11 August 2018 at 10:00:34 UTC, Alex wrote:

Hi all,
maybe I misunderstand something but having this:

´´´
import std.experimental.all;

static assert(isIterable!S);

void main()
{
S s;
s.each!(el => el.writeln);
}

struct S
{
private Nullable!uint member = 0;
Nullable!uint front() @nogc { return member; }
//void popFront(){} // not implementable.
//bool empty(){} // not implementable
Nullable!uint successor(uint current) @nogc { return 
Nullable!uint.init; }


/**
the opApply method grants the correct foreach behavior
*/
int opApply(scope int delegate(ref uint) /*@nogc*/ 
operations) //@nogc

{
int result;

for(auto leading = front; !leading.isNull; leading = 
successor(leading.get))

{
result = operations(leading.get);

if(result)
{
break;
}
}
return result;
}
}
´´´

Everything works fine, before I try to use the opApply function 
inside a @nogc function.


If I do, compiler complains, that opApply is not marked as 
@nogc. Ok.
If I try to mark opApply @nogc, I would have to mark operations 
delegate also as @nogc, but I can't do this, as I do not know a 
priori, how it will be used.


Now, as I learned at some point, a possibility would be, to 
templatify the function, as the compiler can then derive, if 
@nogc apply or not.

But if I write
´´´
int opApply()(...){...}
´´´
Then the static assert from above refuses to compile.

So... how to solve this case?


There's no way to solve it, just don't use @nogc is the easiest 
workaround. It wasn't thought out when it was added and these are 
one of the cases where it doesn't work. Having functions 
automatically declare themselves @nogc if they don't use the gc 
would solve part of the problem. Which is how templates work.


https://dlang.org/library/std/traits/is_iterable.html

If you see how isIterable is defined you'll see that it requires 
opApply be able to provide the element type automatically. That 
is "foreach" doesn't define a type and it is automatically 
deduced. The compiler can't deduce the argument type because the 
function is a template.



foreach(t ; S.init) // Error: cannot infer type for `foreach` 
variable `t`, perhaps set it explicitly

{

}


Re: Could you anybody using DerelictSDL2 on Android?

2018-08-11 Thread tide via Digitalmars-d-learn

On Saturday, 11 August 2018 at 14:44:49 UTC, zhani wrote:

On Saturday, 11 August 2018 at 14:03:21 UTC, tide wrote:

On Tuesday, 7 August 2018 at 12:05:33 UTC, zhani wrote:

howdy :-)

can anybody use sdl2 on android?

first, i got a ldc2 for android. i just followed here on 
windows:

https://wiki.dlang.org/Build_D_for_Android#Windows

so i could compile a sieve.d but didnt run it on android yet.

then next? wut can i try for using DerelictSDL2 on android?
and this guide didn't use dub. how can i intergradted with 
ldc2 for android?


pls be advised me.

regards,


You can use SDL2 for Android, you don't need DerelictSDL2 
either. You just need a way to call the SDL2 functions, which 
you can do by creating bindings for them with "extern(C)". 
Which is my preference over Derelict, as it is simpler and 
makes things easier to use (for me).


Otherwise you are probably going to run into a lot of issues 
as no one is really testing LDC2 for android. The people that 
are testing it aren't testing it the traditional way you build 
an app with the Android SDK.


Oh, could you tell me more about it?
what's different about "extern(C)" and "DerelictSDL2"?
i known, a DerelictSDL2 is a binding library for D and that's 
support "Dynamic" and "Static".


need a help and more info!
have you got some work(eg. source, project) about it?
otherwise, can you tell me any link about it ?


extern(C) is a feature, Derelict are libraries.

https://dlang.org/spec/interfaceToC.html

You can use Derelict "static" to the same effect I think, but 
they way they achieve it doesn't play well with auto completion 
and such.


Re: Could you anybody using DerelictSDL2 on Android?

2018-08-11 Thread tide via Digitalmars-d-learn

On Tuesday, 7 August 2018 at 12:05:33 UTC, zhani wrote:

howdy :-)

can anybody use sdl2 on android?

first, i got a ldc2 for android. i just followed here on 
windows:

https://wiki.dlang.org/Build_D_for_Android#Windows

so i could compile a sieve.d but didnt run it on android yet.

then next? wut can i try for using DerelictSDL2 on android?
and this guide didn't use dub. how can i intergradted with ldc2 
for android?


pls be advised me.

regards,


You can use SDL2 for Android, you don't need DerelictSDL2 either. 
You just need a way to call the SDL2 functions, which you can do 
by creating bindings for them with "extern(C)". Which is my 
preference over Derelict, as it is simpler and makes things 
easier to use (for me).


Otherwise you are probably going to run into a lot of issues as 
no one is really testing LDC2 for android. The people that are 
testing it aren't testing it the traditional way you build an app 
with the Android SDK.