Re: Create class on stack

2017-08-07 Thread ANtlord via Digitalmars-d-learn

On Sunday, 6 August 2017 at 15:47:43 UTC, Moritz Maxeiner wrote:

If you use this option, do be aware that this feature has been

 > scheduled for future deprecation [1].
It's likely going to continue working for quite a while 
(years), though.


[1] 
https://dlang.org/deprecate.html#scope%20for%20allocating%20classes%20on%20the%20stack


I can't understand. Why is moved a scope allocation to a library. 
I'm pretty sure it should be a language feature.


Re: rename file, execute os, etc at compile time

2017-08-07 Thread Stefan Koch via Digitalmars-d-learn

On Monday, 7 August 2017 at 00:07:26 UTC, Johnson Jones wrote:

On Sunday, 6 August 2017 at 23:11:56 UTC, Nicholas Wilson wrote:

On Sunday, 6 August 2017 at 19:56:06 UTC, Johnson Jones wrote:

[...]


It is deliberately not possible. reproducible builds security 
ect.

have a look at dubs preBuildCommand(?)


So it is intensionally preventing me from doing something I 
should be able to do if I want without issue because it thinks 
I will harm myself?




It has more profound reasons, more so then security it's a 
reproducibility issue.

Also it would complicate the ctfe system.


vibed.web.auth framework and redirection

2017-08-07 Thread Johannes Loher via Digitalmars-d-learn

Hello

I'd like to use the vibed.web.auth framework for authentication 
in my vibe.d app. If a user is not authorized to access a certain 
page, he should be redirected to another page (a custom error 
page for example, or the login page in my case). At the moment, 
I'm using the following authenticate method to achieve this:


@noRoute AuthInfo authenticate(scope HTTPServerRequest req, scope 
HTTPServerResponse res)

{
if (!req.session || !req.session.isKeySet("auth"))
{
redirect("/login");
throw new HTTPStatusException(HTTPStatus.forbidden, "Du 
musst dich erst einloggen");

}
return req.session.get!AuthInfo("auth");
}

If you need a full working example, the complete sourcecode can 
be found at 
https://git.f3l.de/fsimphy/calendar-webapp/tree/poodinis-mongo. 
The authenticate method is in the file source/calendarwebapp.d.


While this method seems to work, there are a few issues:
1. Nothing at all seems to happen with the thrown exception 
(well, something got to happen, what is it?). I'd like to somehow 
use and display the Exception msg.
2. Using authenticate methods, which are not @safe or @trusted is 
deprecated as of vibed 0.8.0. The redirect function is neither 
@safe nor @trusted, so my authenticate method can not be @safe. I 
don't know if it is safe to mark it as @trusted.


To me, it seems as if redirecting is not really intended. This 
leads me to the question: Is there any better way to do this?


Thanks in advance for your help!


Re: gtk interface responsiveness

2017-08-07 Thread Johnson Jones via Digitalmars-d-learn

On Monday, 7 August 2017 at 22:59:16 UTC, Moritz Maxeiner wrote:

On Monday, 7 August 2017 at 22:02:21 UTC, Johnson Jones wrote:
I have an icon that I toggle which clicked. It seems that I 
can't toggle it any faster than about a second.


The handler is being called each click but it seems the gui is 
not updated more than about 1fps in that case? Although, I'm 
sure it update faster than 1fps, just seems the icon/image 
isn't.


The code I use to set the image is:

Image.setFromStock("gtk-go-up", GtkIconSize.SMALL_TOOLBAR);

or

Image.setFromStock("gtk-go-down", GtkIconSize.SMALL_TOOLBAR);

[...]


Could you please post the complete minimal code (and compiler 
options) (or a link to them) required to reproduce the issue?



It takes about 3 seconds to write the map file(I have it 
generating cross references, not sure what it actually does but I 
thought it might help with debugging issues. I have it enabled 
for both x86 and x64. I thought I disabled

it with no differences, but maybe I missed it).

It takes another 4 seconds to create the pdb.

But it seems that about 6 seconds are done doing thing

7:13:14.7148555 
PM	link.exe	9860	QueryStandardInformationFile	C:\D\Libraries\x64\gtkd.lib	SUCCESS	AllocationSize: 84,443,136, EndOfFile: 84,439,450, NumberOfLinks: 1, DeletePending: False, Directory: False
7:13:14.7148665 
PM	link.exe	9860	CreateFileMapping	C:\D\Libraries\x64\gtkd.lib	SUCCESS	SyncType: SyncTypeOther
7:13:15.7801685 PM	ServiceHub.IdentityHost.exe	4952	Thread 
Exit		SUCCESS	Thread ID: 11224, User Time: 0.000, Kernel 
Time: 0.000
7:13:17.2481064 PM	ServiceHub.VSDetouredHost.exe	5004	Thread 
Create		SUCCESS	Thread ID: 10976
7:13:17.4141043 PM	devenv.exe	1040	Thread Create		SUCCESS	Thread 
ID: 11200
7:13:17.8990951 PM	DParserCOMServer.exe	4492	Thread 
Create		SUCCESS	Thread ID: 9176
7:13:18.7481654 PM	ServiceHub.VSDetouredHost.exe	5004	Thread 
Exit		SUCCESS	Thread ID: 10976, User Time: 0.000, Kernel 
Time: 0.000
7:13:18.9163321 PM	devenv.exe	1040	Thread Exit		SUCCESS	Thread 
ID: 11200, User Time: 0.000, Kernel Time: 0.000
7:13:19.4011479 PM	DParserCOMServer.exe	4492	Thread 
Exit		SUCCESS	Thread ID: 9176, User Time: 0.000, Kernel Time: 
0.000
7:13:19.9681080 PM	ServiceHub.VSDetouredHost.exe	5004	Thread 
Create		SUCCESS	Thread ID: 10416



Not sure what is happening in there but it seems like Visual D or 
Visual Studio issue rather than dmd ;/



I'll look in to it some more to see what I can find.





Re: gtk interface responsiveness

2017-08-07 Thread Johnson Jones via Digitalmars-d-learn

On Monday, 7 August 2017 at 22:59:16 UTC, Moritz Maxeiner wrote:

On Monday, 7 August 2017 at 22:02:21 UTC, Johnson Jones wrote:
I have an icon that I toggle which clicked. It seems that I 
can't toggle it any faster than about a second.


The handler is being called each click but it seems the gui is 
not updated more than about 1fps in that case? Although, I'm 
sure it update faster than 1fps, just seems the icon/image 
isn't.


The code I use to set the image is:

Image.setFromStock("gtk-go-up", GtkIconSize.SMALL_TOOLBAR);

or

Image.setFromStock("gtk-go-down", GtkIconSize.SMALL_TOOLBAR);

[...]


Could you please post the complete minimal code (and compiler 
options) (or a link to them) required to reproduce the issue?


I'll try to formulate something when I get some time to do so. 
Just trying to get things to work the way I need them to see if 
gtk is gonna be the gui library I use lots of problems but 
hopefully it's just growing pains.




Re: x64 build time 3x slower?

2017-08-07 Thread Johnson Jones via Digitalmars-d-learn

On Monday, 7 August 2017 at 22:56:37 UTC, Moritz Maxeiner wrote:

On Monday, 7 August 2017 at 22:19:57 UTC, Johnson Jones wrote:
Why would that be. Program take about 4 seconds to compile and 
12 for x64. There is fundamentally no difference between the 
two versions. I do link in gtk x86 and gtk x64 depending on 
version, and that's it as far as I can tell.


Debug
x86 4
x64 12
Release
x86 3
x64 5

The timings are pretty steady.


Split up the build time in compile time and link time and see 
how the difference is distributed between the two.
If it's distributed overwhelmingly to the link time it could be 
that you're using Microsoft's linker for x64 and OPTLINK for 
x86?


Yeah, I guess that is probably it. Forgot that two different 
linkers were used... although, Not much is being linked. Visual D 
doesn't split up the two easily, I suppose I can't separate them. 
It should probably do individual profiling between the two.


Usually the build times are pretty close and I don't recall it 
being slow when I first started building, and my code hasn't 
changed much... But I did modify a few options such as debug 
diagnostics and such as those were causing visual studio to 
freeze.


I guess I could perfmon it to see what exactly it is doing.




Re: VibeD - REST API and vibed.web.auth framework

2017-08-07 Thread holo via Digitalmars-d-learn

Thank you for explanation.

It fix my problem with compilation. I was using 
https://github.com/rejectedsoftware/vibe.d/blob/master/examples/web-auth/source/app.d as example and there is @safe function. I try to compile it with newest (beta) version of vibe.d and it compiled too (so i suspect in newest version system function is marked as trusted/safe too or it is fixed some other way :)).


Regards
holo



Re: gtk interface responsiveness

2017-08-07 Thread Moritz Maxeiner via Digitalmars-d-learn

On Monday, 7 August 2017 at 22:02:21 UTC, Johnson Jones wrote:
I have an icon that I toggle which clicked. It seems that I 
can't toggle it any faster than about a second.


The handler is being called each click but it seems the gui is 
not updated more than about 1fps in that case? Although, I'm 
sure it update faster than 1fps, just seems the icon/image 
isn't.


The code I use to set the image is:

Image.setFromStock("gtk-go-up", GtkIconSize.SMALL_TOOLBAR);

or

Image.setFromStock("gtk-go-down", GtkIconSize.SMALL_TOOLBAR);

[...]


Could you please post the complete minimal code (and compiler 
options) (or a link to them) required to reproduce the issue?


Re: x64 build time 3x slower?

2017-08-07 Thread Moritz Maxeiner via Digitalmars-d-learn

On Monday, 7 August 2017 at 22:19:57 UTC, Johnson Jones wrote:
Why would that be. Program take about 4 seconds to compile and 
12 for x64. There is fundamentally no difference between the 
two versions. I do link in gtk x86 and gtk x64 depending on 
version, and that's it as far as I can tell.


Debug
x86 4
x64 12
Release
x86 3
x64 5

The timings are pretty steady.


Split up the build time in compile time and link time and see how 
the difference is distributed between the two.
If it's distributed overwhelmingly to the link time it could be 
that you're using Microsoft's linker for x64 and OPTLINK for x86?


Re: Create class on stack

2017-08-07 Thread Moritz Maxeiner via Digitalmars-d-learn

On Monday, 7 August 2017 at 22:02:07 UTC, Mike wrote:

On Monday, 7 August 2017 at 13:42:33 UTC, Moritz Maxeiner wrote:

You can still create a (scope) class on the stack, escape a 
reference to it using `move` and use it afterwards, all 
within the rules of @safe, so I'm not convinced that the 
reason for deprecating scoped classes is gone yet.
Compare this to `scoped`, which behaves as expected (since it 
wraps the reference type object in a value type):


Looks like a bug to me.  I recommend submitting a bug report 
and tag it somehow with "scope" and/or "DIP1000".  It appears 
Walter is giving any bugs with scope/DIP1000 priority.


Thanks for the feedback, done: 
https://issues.dlang.org/show_bug.cgi?id=17730


x64 build time 3x slower?

2017-08-07 Thread Johnson Jones via Digitalmars-d-learn
Why would that be. Program take about 4 seconds to compile and 12 
for x64. There is fundamentally no difference between the two 
versions. I do link in gtk x86 and gtk x64 depending on version, 
and that's it as far as I can tell.


Debug
x86 4
x64 12
Release
x86 3
x64 5

The timings are pretty steady.








gtk interface responsiveness

2017-08-07 Thread Johnson Jones via Digitalmars-d-learn
I have an icon that I toggle which clicked. It seems that I can't 
toggle it any faster than about a second.


The handler is being called each click but it seems the gui is 
not updated more than about 1fps in that case? Although, I'm sure 
it update faster than 1fps, just seems the icon/image isn't.


The code I use to set the image is:

Image.setFromStock("gtk-go-up", GtkIconSize.SMALL_TOOLBAR);

or

Image.setFromStock("gtk-go-down", GtkIconSize.SMALL_TOOLBAR);

I also have been experiencing significant slow downs when the gui 
load for the first time. Doesn't always seem to happen but 
basically keyboard output across the os is unresponsive then 
everything occurs at once(when whatever catches up for quits 
interfering with the keyboard). It takes about 20 seconds for 
that to occur then everything works fine afterwards best I can 
tell.



(BTW, thanks mike for all the help ;))


Re: Create class on stack

2017-08-07 Thread Mike via Digitalmars-d-learn

On Monday, 7 August 2017 at 13:42:33 UTC, Moritz Maxeiner wrote:

You can still create a (scope) class on the stack, escape a 
reference to it using `move` and use it afterwards, all within 
the rules of @safe, so I'm not convinced that the reason for 
deprecating scoped classes is gone yet.
Compare this to `scoped`, which behaves as expected (since it 
wraps the reference type object in a value type):


Looks like a bug to me.  I recommend submitting a bug report and 
tag it somehow with "scope" and/or "DIP1000".  It appears Walter 
is giving any bugs with scope/DIP1000 priority.


Mike


Re: gtkD window centering message up and no app on taskbar

2017-08-07 Thread Johnson Jones via Digitalmars-d-learn

On Monday, 7 August 2017 at 20:57:08 UTC, Mike Wey wrote:

On 07-08-17 22:46, Johnson Jones wrote:

[...]


This appears to be a GTK issue, a work around might be to get 
the Window handle from gtk and use the Windows API to set the 
taskbar visibility.




Yeah, I was thinking about that but haven't yet figured out how 
to find the window handle ;/


Re: gtkD: events being triggered twice

2017-08-07 Thread Johnson Jones via Digitalmars-d-learn

On Monday, 7 August 2017 at 21:01:33 UTC, Mike Wey wrote:

On 06-08-17 21:27, FoxyBrown wrote:

[...]


Also seems to be working properly with a Separator.


Ok, I guess it's on my end, I don't see how since I'm not doing a 
hell of a lot and only gtk is calling those event handlers, I'll 
try to create a test app at some point. I've already added logic 
to prevent multiple reentries though so, for now I've solved the 
problem.




Re: ldc D compiler installation on windows 10

2017-08-07 Thread Bastiaan Veelo via Digitalmars-d-learn

On Sunday, 6 August 2017 at 23:44:27 UTC, greatsam4sure wrote:
Good day. I will appreciate it if anybody here can help me with 
the step by step way of installing ldc D compiler on windows. I 
have read online info but i just don't get it. let the process 
be in steps for easy comprehension.thanks in advance


Try this:

1) go to https://github.com/ldc-developers/ldc/releases
2) download the appropriate ldc2-*-msvc.zip
3) unzip it anywhere
4) read the README.txt from that location.

If you encounter a problem, try to explain it here as detailed as 
you can.


Regards,
Bastiaan.


Re: gtkD: events being triggered twice

2017-08-07 Thread Mike Wey via Digitalmars-d-learn

On 06-08-17 21:27, FoxyBrown wrote:

On Sunday, 6 August 2017 at 18:26:20 UTC, Mike Wey wrote:

On 06-08-17 16:58, FoxyBrown wrote:
I don't really(my code is a bit more complex) but basically all it 
boils down to is a UI with some nested widgets (an overlay, an box, 
and a box and one contains the eventbox which I added those callbacks 
on.


I think that something like

https://github.com/gtkd-developers/GtkD/blob/master/demos/gtkD/TestWindow/TestWindow.d 




should probably work by just adding an eventbox somewhere and adding 
that code above.


If it doesn't exhibit the same behavior then it has something to do 
with my project and I could try to reduce it to a minimal example.


To test i put the label that is on the label page in an event box but 
that doesn't reproduce the issue. I get just a single event on enter 
and a single event on leave.


Ok, I will try to work on figuring out what is going and and potentially 
reduce to a test case. It might be on my end. I'm pretty sure I'm not 
adding


You might try a separator though in the event box and might try to add 
it handling various events(maybe even other events for the event box)... 
things related to the mouse.


Here's the glade code for the event box I'm using

   
 5
 True
 False
 True
 
   
 5
 True
 False
 False
 
 vertical
   
 
   


Try that when you get some time and see if that changes anything. If it 
doesn't then it's surely in my code or in the gtk version I'm 
using(still using msys, I'll update to what you released to see if that 
fixes it). At least we can narrow it down a little...




Also seems to be working properly with a Separator.

--
Mike Wey


Re: D on Power8 (PPC64)

2017-08-07 Thread kinke via Digitalmars-d-learn

On Monday, 7 August 2017 at 20:39:40 UTC, Dmitry Olshansky wrote:

What is the status of the platform?
I might be doing some number crunching on one of the power8 
beasts, would be nice to have D working there.


Not that bad afaik. LDC should be able to build itself, the 
runtime libs and their unittests, but a bunch of tests fail. 
Little-endian could be working pretty well out of the box, but 
Phobos doesn't fully support big-endian architectures (at least 
last time I checked).
See https://github.com/ldc-developers/ldc/issues/1909. [The 
initial problems for that guy were due to a faulty host compiler; 
make sure to bootstrap LDC via latest ltsmaster branch.]


Re: gtkD window centering message up and no app on taskbar

2017-08-07 Thread Mike Wey via Digitalmars-d-learn

On 07-08-17 22:46, Johnson Jones wrote:

On Saturday, 5 August 2017 at 20:56:10 UTC, Mike Wey wrote:


Windows will only show the taskbar icon if you are not running the 
application from the console.


Now in x64 it is showing, not in x86. So, not sure what's going on but 
at least it is showing. I was in a windows console and added a main.def 
but dmd says that it's not compatible with x64 or something:


main.def(1) : warning LNK4017: EXETYPE statement not supported for the 
target platform; ignored
main.def(4) : warning LNK4017: SUBSYSTEM statement not supported for the 
target platform; ignored


but adding that file seemed to allow the icon like you said. I'm not 
doing anything different for x86 except switching gtk versions... but 
maybe there is a flag or setting somewhere that is causing the problem.


and, in the x64 version I get both the console and gtk app task bar 
icons... which is what I originally wanted and expected.




This appears to be a GTK issue, a work around might be to get the Window 
handle from gtk and use the Windows API to set the taskbar visibility.


Interestingly the icon shows up after restarting explorer.exe.

For 64bit apps dmd uses the microsoft linker, so you probably have to 
use different flags to set the subsystem.


--
Mike Wey


Re: gtkD window centering message up and no app on taskbar

2017-08-07 Thread Johnson Jones via Digitalmars-d-learn

On Saturday, 5 August 2017 at 20:56:10 UTC, Mike Wey wrote:


Windows will only show the taskbar icon if you are not running 
the application from the console.


Now in x64 it is showing, not in x86. So, not sure what's going 
on but at least it is showing. I was in a windows console and 
added a main.def but dmd says that it's not compatible with x64 
or something:


main.def(1) : warning LNK4017: EXETYPE statement not supported 
for the target platform; ignored
main.def(4) : warning LNK4017: SUBSYSTEM statement not supported 
for the target platform; ignored


but adding that file seemed to allow the icon like you said. I'm 
not doing anything different for x86 except switching gtk 
versions... but maybe there is a flag or setting somewhere that 
is causing the problem.


and, in the x64 version I get both the console and gtk app task 
bar icons... which is what I originally wanted and expected.




Re: VibeD - REST API and vibed.web.auth framework

2017-08-07 Thread Bastiaan Veelo via Digitalmars-d-learn

On Sunday, 6 August 2017 at 16:47:14 UTC, holo wrote:

Hello

I'm trying to use auth framework with REST api ( 
http://vibed.org/api/vibe.web.auth/ ).


Is it possible to use it with registerRestInterface? According 
to description under: 
http://vibed.org/api/vibe.web.auth/requiresAuth it should be 
available on both Web and REST.


Here is my example code and compilation errors bellow:



[snip]

  AuthInfo authenticate(scope HTTPServerRequest req, scope 
HTTPServerResponse res) @safe


[snip]



And im getting such errors:

ms-frontpage ~master: building configuration "application"...
../../.dub/packages/vibe-d-0.7.31/vibe-d/source/vibe/http/server.d(286,33): 
Deprecation: alias diet.traits.FilterCallback is deprecated - Use 
SafeFilterCallback instead.
source/app.d(14,31): Error: cannot create instance of interface 
IfOAuthAPI
source/service/oauth.d(35,8): Error: @safe function 
'oauth.OAuthAPI.authenticate' cannot call @system function 
'vibe.http.session.Session.opCast'


[snip]

Are you aware what @safe does? If you remove it, it probably 
compiles.


From @safe functions you cannot call functions that are not 
marked @safe or @trusted [1].


Regards,
Bastiaan.

[1] https://dlang.org/spec/function.html#function-safety


D on Power8 (PPC64)

2017-08-07 Thread Dmitry Olshansky via Digitalmars-d-learn

What is the status of the platform?
I might be doing some number crunching on one of the power8 
beasts, would be nice to have D working there.


---
Dmitry Olshansky


Re: How to build GUI-based applications in D ?

2017-08-07 Thread Dukc via Digitalmars-d-learn

thank you aberba

ok, so this is useless to me.
i want something fully functional stand-alone tools.
i have no internet connection there.


Don't worry, DlangUI is stand-alone: you only need the connection 
to download it, but not to use it nor to compile with. Dub will 
function without connection if you have already downloaded the 
needed dependencies.


If you have no connection at all for the device you develop with, 
you can use dub add-local to register a package you have fetched 
manually.


Re: gtkD window centering message up and no app on taskbar

2017-08-07 Thread Johnson Jones via Digitalmars-d-learn
and I do have skipTaskbar disabled... tried enabling it with no 
long... and fidgeting with other settings and using a Window 
instead of Application Window.


Maybe gtk needs to be told that that the window is the "main 
window" of the application?





Re: gtkD window centering message up and no app on taskbar

2017-08-07 Thread Johnson Jones via Digitalmars-d-learn

On Saturday, 5 August 2017 at 20:56:10 UTC, Mike Wey wrote:

On 05-08-17 20:14, Johnson Jones wrote:
When trying to center the window. If one uses ALWAYS_CENTERED 
any resizing of the window is totally busted. CENTER also does 
not work. move(0,0) seems to not be relative to the main 
display. I'd basically like to center the window on the main 
display or at least be able to set coordinates properly. 
Windows sets (0,0) to be the lower left corner of the main 
display I believe. What happens is that the gtk window, when 
using 0,0 actually is like -1000,0 or something in windows 
coordinates and ends up on my secondary monitor.


When the app starts there's no taskbar icon. Luckily I still 
have the console shown but Eventually I'll need the taskbar. 
I'm not setting skipTaskBarHint, but I have tried both true 
and false without any difference.





Windows will only show the taskbar icon if you are not running 
the application from the console.


This doesn't seem to be true. I switched over, changed everything 
to windows, and I still get no taskbar icon. I changed the 
settings L:Subsystem to windows and added the appropriate def 
file. I think I did this in another app and it worked fine. So 
it's probably a gtk glade setting(I was using the older glade 
versions that we talked about).


Now I have no console window and no taskbar icon.




Re: gtkD: events being triggered twice

2017-08-07 Thread Johnson Jones via Digitalmars-d-learn

On Monday, 7 August 2017 at 16:13:18 UTC, Adam D. Ruppe wrote:

On Sunday, 6 August 2017 at 19:27:15 UTC, FoxyBrown wrote:


  


I don't know gtk, but I would suspect moving the mouse over the 
child triggers the enter/leave notifications too and it bubbles 
up to the parent.


Yeah, but both those events are from EventBox. If that were true 
I'd except Separator to be shown as the widget that has the 
event. I do return true from the handler which I believe is 
suppose to stop any more handlers.


Although, it does sound something like what you are saying... but 
it also doesn't explain why the events are not paired, which is 
the more serious issue.








Re: gtkD: events being triggered twice

2017-08-07 Thread Adam D. Ruppe via Digitalmars-d-learn

On Sunday, 6 August 2017 at 19:27:15 UTC, FoxyBrown wrote:


  


I don't know gtk, but I would suspect moving the mouse over the 
child triggers the enter/leave notifications too and it bubbles 
up to the parent.


Re: Create class on stack

2017-08-07 Thread Moritz Maxeiner via Digitalmars-d-learn

On Monday, 7 August 2017 at 10:42:03 UTC, Jacob Carlborg wrote:

On 2017-08-06 17:47, Moritz Maxeiner wrote:

If you use this option, do be aware that this feature has been 
scheduled

for future deprecation [1].
It's likely going to continue working for quite a while 
(years), though.


It's used all over the place in the DMD code base.


I don't see how that's a reason for increasing the amount of code 
that needs to be changed if/when scope classes are deprecated. 
Mike's argument holds, though (if the loophole I pointed out gets 
fixed and scope classes are removed from the future deprecation 
list).


Re: Create class on stack

2017-08-07 Thread Moritz Maxeiner via Digitalmars-d-learn

On Monday, 7 August 2017 at 13:40:18 UTC, Moritz Maxeiner wrote:


Thanks, I wasn't aware of this. I tried fooling around scope 
classes and DIP1000 for a bit and was surprised that this is 
allowed:


---
import core.stdc.stdio : printf;
import std.algorithm : move;

class A
{
int i;

this() @safe
{
i = 0;
}
}

void inc(scope A a) @safe
{
a.i += 1;
}

void print(scope A a) @trusted
{
printf("A@%x: %d\n", cast(void*) a, a.i);
}

auto makeA() @safe
{
scope a = new A();
a.print();
return move(a);
}

void main() @safe
{
auto a = makeA();
foreach (i; 0..10) {
a.print();
a.inc();
}
}
---

You can still create a (scope) class on the stack, escape a 
reference to it using `move` and use it afterwards, all within 
the rules of @safe, so I'm not convinced that the reason for 
deprecating scoped classes is gone yet.
Compare this to `scoped`, which behaves as expected (since it 
wraps the reference type object in a value type):


---
import std.typecons : scoped;

auto makeA() @trusted
{
auto a = scoped!A();
a.print();
return move(a);
}

void main() @trusted
{
auto a = makeA();
foreach (i; 0..10) {
a.print();
a.inc();
}
}
---


Forgot to add the runtime output after compiling with `dmd a.d 
-dip1000`:


For `scope A`:
A@198d1568: 0
A@198d1568: 0
A@198d1568: 1
A@198d1568: 2
A@198d1568: 3
A@198d1568: 4
A@198d1568: 5
A@198d1568: 6
A@198d1568: 7
A@198d1568: 8
A@198d1568: 9

For `scoped!A`:
A@8de538b8: 0
A@8de53940: 0
A@8de53940: 1
A@8de53940: 2
A@8de53940: 3
A@8de53940: 4
A@8de53940: 5
A@8de53940: 6
A@8de53940: 7
A@8de53940: 8
A@8de53940: 9


Re: Create class on stack

2017-08-07 Thread Moritz Maxeiner via Digitalmars-d-learn

On Monday, 7 August 2017 at 10:50:21 UTC, Mike wrote:

On Sunday, 6 August 2017 at 15:47:43 UTC, Moritz Maxeiner wrote:

If you use this option, do be aware that this feature has been 
scheduled for future deprecation [1].
It's likely going to continue working for quite a while 
(years), though.


[1] 
https://dlang.org/deprecate.html#scope%20for%20allocating%20classes%20on%20the%20stack


FYI:  http://forum.dlang.org/post/np1fll$ast$1...@digitalmars.com

"Yes, it will have to be updated - but I didn't want to adjust 
it before DIP1000 spec is finalized. Rationale that was driving 
deprecation of scope storage class is becoming obsolete with 
DIP1000 implemented but not before."


Thanks, I wasn't aware of this. I tried fooling around scope 
classes and DIP1000 for a bit and was surprised that this is 
allowed:


---
import core.stdc.stdio : printf;
import std.algorithm : move;

class A
{
int i;

this() @safe
{
i = 0;
}
}

void inc(scope A a) @safe
{
a.i += 1;
}

void print(scope A a) @trusted
{
printf("A@%x: %d\n", cast(void*) a, a.i);
}

auto makeA() @safe
{
scope a = new A();
a.print();
return move(a);
}

void main() @safe
{
auto a = makeA();
foreach (i; 0..10) {
a.print();
a.inc();
}
}
---

You can still create a (scope) class on the stack, escape a 
reference to it using `move` and use it afterwards, all within 
the rules of @safe, so I'm not convinced that the reason for 
deprecating scoped classes is gone yet.
Compare this to `scoped`, which behaves as expected (since it 
wraps the reference type object in a value type):


---
import std.typecons : scoped;

auto makeA() @trusted
{
auto a = scoped!A();
a.print();
return move(a);
}

void main() @trusted
{
auto a = makeA();
foreach (i; 0..10) {
a.print();
a.inc();
}
}
---


Re: rename file, execute os, etc at compile time

2017-08-07 Thread lobo via Digitalmars-d-learn

On Monday, 7 August 2017 at 00:07:26 UTC, Johnson Jones wrote:

On Sunday, 6 August 2017 at 23:11:56 UTC, Nicholas Wilson wrote:

On Sunday, 6 August 2017 at 19:56:06 UTC, Johnson Jones wrote:

[...]


It is deliberately not possible. reproducible builds security 
ect.

have a look at dubs preBuildCommand(?)


So it is intensionally preventing me from doing something I 
should be able to do if I want without issue because it thinks 
I will harm myself?


Why not a compiler switch that enables it? It's blocking 
something that might be an issue but is almost surely not and 
prevents the vast capabilities that it would otherwise be able 
to accomplish.


I guess one can always patch the compiler...

But Dmd does give an error about security, it usually says that 
the there are not source code available for compile time or 
something like that.


How is this a blocking anything when you can do it already with 
nearly every build tool available. Invoke a script or prebuilt 
binary etc. as a target that does the munging for you at 
pre-compile time.


Re: std.math module

2017-08-07 Thread greatsam4sure via Digitalmars-d-learn

On Monday, 7 August 2017 at 04:47:56 UTC, Nicholas Wilson wrote:

On Sunday, 6 August 2017 at 23:33:26 UTC, greatsam4sure wrote:

import std.math;
import std.stdio;

cos(90*PI/180) = -2.7e-20 instead of zero. I will appreciate 
any help. thanks in advance.


tan(90*PI/180) = -3.689e+19 instead of infinity. What is the 
best way to use this module


in addition to what sarn said, tan(3pi/4) is a pole, not 
infinity. the mean of the left and right hand limits is 0


Thanks for the help. I will appreciate any resources for further 
reading


Re: Create class on stack

2017-08-07 Thread Mike via Digitalmars-d-learn

On Sunday, 6 August 2017 at 15:47:43 UTC, Moritz Maxeiner wrote:

If you use this option, do be aware that this feature has been 
scheduled for future deprecation [1].
It's likely going to continue working for quite a while 
(years), though.


[1] 
https://dlang.org/deprecate.html#scope%20for%20allocating%20classes%20on%20the%20stack


FYI:  http://forum.dlang.org/post/np1fll$ast$1...@digitalmars.com

"Yes, it will have to be updated - but I didn't want to adjust it 
before DIP1000 spec is finalized. Rationale that was driving 
deprecation of scope storage class is becoming obsolete with 
DIP1000 implemented but not before."


Mike


Re: Create class on stack

2017-08-07 Thread Jacob Carlborg via Digitalmars-d-learn

On 2017-08-06 17:47, Moritz Maxeiner wrote:


If you use this option, do be aware that this feature has been scheduled
for future deprecation [1].
It's likely going to continue working for quite a while (years), though.


It's used all over the place in the DMD code base.

--
/Jacob Carlborg