Re: How to use template Object in interface?

2019-06-26 Thread zoujiaqing via Digitalmars-d-learn

On Tuesday, 25 June 2019 at 12:11:47 UTC, zoujiaqing wrote:
hunt-cache current version use template implemention adapter 
changes.


I want use Interface to define Adapter, this master code unable 
to comple.


How to do it? D programming language design flaws?

```bash
git clone https://github.com/huntlabs/hunt-cache
cd hunt-cache/example
dub run -v

...

source/app.d(29,19): Error: no property name for type 
Nullable!(User)


```


Error in this commit:
https://github.com/huntlabs/hunt-cache/commit/1f4ca85b47a7e62b41907152f8c8904e69a09975


Re: Conversion problem.

2019-06-26 Thread Den_d_y via Digitalmars-d-learn

On Wednesday, 26 June 2019 at 05:53:29 UTC, Den_d_y wrote:

On Tuesday, 25 June 2019 at 16:44:28 UTC, H. S. Teoh wrote:
On Tue, Jun 25, 2019 at 12:08:07PM +, Den_d_y via 
Digitalmars-d-learn wrote:
Hello! Here I am again, with my problem ... In my program, I 
cannot manage to convert from "double" to "int". Here is the 
code:

[...]

Did you try this?

import std.conv : to;

double d = ...;
int i = d.to!int;


T


This does not work. The program hangs at this stage, even the 
code you have proposed also does not work as we would like. 
Maybe I'm doing something wrong?


Something is tracked:
std.conv.ConvOverflowException@C: \ D \ dmd2 \ windows \ bin \ .. 
\ .. \ src \ phobos \ std \ conv.d (1457): Conversion Underflow 
Overflow

What could it be


Re: Conversion problem.

2019-06-26 Thread Den_d_y via Digitalmars-d-learn

On Wednesday, 26 June 2019 at 10:49:50 UTC, Den_d_y wrote:

On Wednesday, 26 June 2019 at 05:53:29 UTC, Den_d_y wrote:

On Tuesday, 25 June 2019 at 16:44:28 UTC, H. S. Teoh wrote:
On Tue, Jun 25, 2019 at 12:08:07PM +, Den_d_y via 
Digitalmars-d-learn wrote:

[...]

[...]

Did you try this?

import std.conv : to;

double d = ...;
int i = d.to!int;


T


This does not work. The program hangs at this stage, even the 
code you have proposed also does not work as we would like. 
Maybe I'm doing something wrong?


Something is tracked:
std.conv.ConvOverflowException@C: \ D \ dmd2 \ windows \ bin \ 
.. \ .. \ src \ phobos \ std \ conv.d (1457): Conversion 
Underflow Overflow

What could it be


How stupid ... You just had to assign the value "0" to the value 
0 ... The problem is solved.


Illegal Filename after basic install and trying Hello World

2019-06-26 Thread Gilbert Fernandes via Digitalmars-d-learn

I am using VS 2019 into which I have C# and C++ active.
Installed the following : DMD 2.086.1 then Visual D 0.50.0
DMD has been installed at the base of C:\ at C:\D

Created a D project, which contains a default Hello world program.
Build fails. Running the program fails.

VS displays the following error :

-- Build started: Project: Test2, Configuration: Debug x64 
--

Building x64\Debug\Test2.exe...
OPTLINK (R) for Win32  Release 8.00.17
Copyright (C) Digital Mars 1989-2013  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
OPTLINK : Error 8: Illegal Filename
== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped 
==


Besides installing Visual D and creating a new project, done 
nothing.


I have searched the forum for people with the same problem and 
found two threads.

https://forum.dlang.org/post/poq048$28mm$1...@digitalmars.com
https://forum.dlang.org/post/xmhkgkqujxmzruque...@forum.dlang.org

None do help. The option "override linker settings from sc.ini" 
is nowhere it seems. I have checked both inside the current 
project properties, and VS settings themselves.


I have the following cmd to build the program in the folder :

set PATH=C:\Program Files (x86)\Visual Studio\VC\bin;C:\Program 
Files (x86)\Visual Studio\Common7\IDE;C:\Program Files 
(x86)\Windows Kits\10\bin;C:\D\dmd2\windows\bin;%PATH%

set DMD_LIB=C:\Program Files (x86)\Visual Studio\VC\lib\amd64
set VCINSTALLDIR=C:\Program Files (x86)\Visual Studio\VC\
set VCTOOLSINSTALLDIR=C:\Program Files (x86)\Visual 
Studio\VC\Tools\MSVC\14.21.27702\

set VSINSTALLDIR=C:\Program Files (x86)\Visual Studio\
set WindowsSdkDir=C:\Program Files (x86)\Windows Kits\10\
set WindowsSdkVersion=10.0.17763.0
set UniversalCRTSdkDir=C:\Program Files (x86)\Windows Kits\10\
set UCRTVersion=10.0.17763.0
"C:\Program Files (x86)\VisualD\pipedmd.exe" -deps 
x64\Debug\Test2.dep dmd -m64 -g -gf -debug -X 
-Xf"x64\Debug\Test2.json" -c -of"x64\Debug\Test2.obj" Test2.d

if %errorlevel% neq 0 goto reportError

set LIB=C:\D\dmd2\windows\bin\..\lib64
echo. > D:\sources_D\Test2\Test2\x64\Debug\Test2.link.rsp
echo "x64\Debug\Test2.obj" /OUT:"x64\Debug\Test2.exe" user32.lib  
>> D:\sources_D\Test2\Test2\x64\Debug\Test2.link.rsp
echo kernel32.lib  >> 
D:\sources_D\Test2\Test2\x64\Debug\Test2.link.rsp
echo legacy_stdio_definitions.lib /LIBPATH:"C:\Program Files 
(x86)\Visual Studio\VC\lib\amd64" /DEBUG 
/PDB:"x64\Debug\Test2.pdb" /INCREMENTAL:NO /NOLOGO /noopttls 
/NODEFAULTLIB:libcmt libcmtd.lib /SUBSYSTEM:CONSOLE >> 
D:\sources_D\Test2\Test2\x64\Debug\Test2.link.rsp
"C:\Program Files (x86)\VisualD\mb2utf16.exe" 
D:\sources_D\Test2\Test2\x64\Debug\Test2.link.rsp


"C:\Program Files (x86)\VisualD\pipedmd.exe" -msmode -deps 
x64\Debug\Test2.lnkdep C:\D\dmd2\windows\bin\link.exe 
@D:\sources_D\Test2\Test2\x64\Debug\Test2.link.rsp

if %errorlevel% neq 0 goto reportError
if not exist "x64\Debug\Test2.exe" (echo "x64\Debug\Test2.exe" 
not created! && goto reportError)


goto noError

:reportError
echo Building x64\Debug\Test2.exe failed!

:noError

Typing "link" seems to launch the D Optilink Linker by default on 
my CMD.
If I understand properly, I should be using the VS C++ supplied 
linker ?


Inside VS settings I have the following in the DMD Directories :

Win32 Executable Paths :
$(VCINSTALLDIR)bin
$(VSINSTALLDIR)Common7\IDE
$(WindowsSdkDir)bin
$(DMDInstallDir)windows\bin

x64 has the same ones, but a library path defined :
$(VCINSTALLDIR)lib\amd64

And the following linker is defined :
C:\D\dmd2\windows\bin\link.exe

I don't know how to fix this.

Should this work after a basic Visual D install or there are some 
configurations steps I missed ?




Re: Illegal Filename after basic install and trying Hello World

2019-06-26 Thread Nicholas Wilson via Digitalmars-d-learn
On Wednesday, 26 June 2019 at 13:57:22 UTC, Gilbert Fernandes 
wrote:

I am using VS 2019 into which I have C# and C++ active.
Installed the following : DMD 2.086.1 then Visual D 0.50.0
DMD has been installed at the base of C:\ at C:\D

Created a D project, which contains a default Hello world 
program.

Build fails. Running the program fails.

VS displays the following error :

-- Build started: Project: Test2, Configuration: Debug x64 
--

Building x64\Debug\Test2.exe...
OPTLINK (R) for Win32  Release 8.00.17
Copyright (C) Digital Mars 1989-2013  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
OPTLINK : Error 8: Illegal Filename
== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 
skipped ==


Besides installing Visual D and creating a new project, done 
nothing.


I have searched the forum for people with the same problem and 
found two threads.

https://forum.dlang.org/post/poq048$28mm$1...@digitalmars.com
https://forum.dlang.org/post/xmhkgkqujxmzruque...@forum.dlang.org

None do help. The option "override linker settings from sc.ini"


it may be called dmd.conf (it is on my Mac, but the windows may 
be different)


is nowhere it seems. I have checked both inside the current 
project properties, and VS settings themselves.


I have the following cmd to build the program in the folder :

set PATH=C:\Program Files (x86)\Visual Studio\VC\bin;C:\Program 
Files (x86)\Visual Studio\Common7\IDE;C:\Program Files 
(x86)\Windows Kits\10\bin;C:\D\dmd2\windows\bin;%PATH%

set DMD_LIB=C:\Program Files (x86)\Visual Studio\VC\lib\amd64
set VCINSTALLDIR=C:\Program Files (x86)\Visual Studio\VC\
set VCTOOLSINSTALLDIR=C:\Program Files (x86)\Visual 
Studio\VC\Tools\MSVC\14.21.27702\

set VSINSTALLDIR=C:\Program Files (x86)\Visual Studio\
set WindowsSdkDir=C:\Program Files (x86)\Windows Kits\10\
set WindowsSdkVersion=10.0.17763.0
set UniversalCRTSdkDir=C:\Program Files (x86)\Windows Kits\10\
set UCRTVersion=10.0.17763.0
"C:\Program Files (x86)\VisualD\pipedmd.exe" -deps 
x64\Debug\Test2.dep dmd -m64 -g -gf -debug -X 
-Xf"x64\Debug\Test2.json" -c -of"x64\Debug\Test2.obj" Test2.d

if %errorlevel% neq 0 goto reportError

set LIB=C:\D\dmd2\windows\bin\..\lib64
echo. > D:\sources_D\Test2\Test2\x64\Debug\Test2.link.rsp
echo "x64\Debug\Test2.obj" /OUT:"x64\Debug\Test2.exe" 
user32.lib  >> D:\sources_D\Test2\Test2\x64\Debug\Test2.link.rsp
echo kernel32.lib  >> 
D:\sources_D\Test2\Test2\x64\Debug\Test2.link.rsp
echo legacy_stdio_definitions.lib /LIBPATH:"C:\Program Files 
(x86)\Visual Studio\VC\lib\amd64" /DEBUG 
/PDB:"x64\Debug\Test2.pdb" /INCREMENTAL:NO /NOLOGO /noopttls 
/NODEFAULTLIB:libcmt libcmtd.lib /SUBSYSTEM:CONSOLE >> 
D:\sources_D\Test2\Test2\x64\Debug\Test2.link.rsp
"C:\Program Files (x86)\VisualD\mb2utf16.exe" 
D:\sources_D\Test2\Test2\x64\Debug\Test2.link.rsp


"C:\Program Files (x86)\VisualD\pipedmd.exe" -msmode -deps 
x64\Debug\Test2.lnkdep C:\D\dmd2\windows\bin\link.exe 
@D:\sources_D\Test2\Test2\x64\Debug\Test2.link.rsp

if %errorlevel% neq 0 goto reportError
if not exist "x64\Debug\Test2.exe" (echo "x64\Debug\Test2.exe" 
not created! && goto reportError)


goto noError

:reportError
echo Building x64\Debug\Test2.exe failed!

:noError

Typing "link" seems to launch the D Optilink Linker by default 
on my CMD.
If I understand properly, I should be using the VS C++ supplied 
linker ?


Correct. You have VS, so it is of no use to you. Use the VS one 
instead of C:\D\dmd2\windows\bin\link.exe in your build file. You 
can just delete the wrong link.exe any hopefully it will pick up 
the correct one in the $PATH.


Also any reason why you (or is that visualD doing that? )are 
manually invoking the linker? Omit -c and dmd will invoke the 
linker for you (hopefully the correct one).





Re: Illegal Filename after basic install and trying Hello World

2019-06-26 Thread Gilbert Fernandes via Digitalmars-d-learn

After removing all paths to the linker, the error has changed :

-- Build started: Project: Test2, Configuration: Debug x64 
--

Building x64\Debug\Test2.exe...
TRACKER : error TRK0005: ‚chec de localisation deÿ: 
"@D:\sources_D\Test2\Test2\x64\Debug\Test2.link.rsp". Le fichier 
sp‚cifi‚ est introuvable.


Building x64\Debug\Test2.exe failed!
Details saved as 
"file://D:\sources_D\Test2\Test2\x64\Debug\Test2.buildlog.html"
== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped 
==


I have checked if the rsp file does exist at the indicated path, 
and it seems so :


D:\>dir D:\sources_D\Test2\Test2\x64\Debug\Test2.link.rsp

 Répertoire de D:\sources_D\Test2\Test2\x64\Debug

26/06/2019  16:43   590 Test2.link.rsp
   1 fichier(s)  590 octets
   0 Rép(s)  62 739 664 896 octets libres

I don't know why but I'm not gonna spend more time on this.

The "dmd" command works fine on command line.
So I'm gonna use Visual Studio Code + use command-line commands
Will make using git easier anyway.

Thanks for the help. I'd rather spend time on learning D than 
fixing VS weird way to work :p


Where can find the GC impletement source code?

2019-06-26 Thread lili via Digitalmars-d-learn

Hi Guys:
   I look for the GC source code in /usr/include/dmd dir, 
unfortunately not find.




Re: Where can find the GC impletement source code?

2019-06-26 Thread kinke via Digitalmars-d-learn

On Wednesday, 26 June 2019 at 15:56:06 UTC, lili wrote:

Hi Guys:
   I look for the GC source code in /usr/include/dmd dir, 
unfortunately not find.


https://github.com/dlang/druntime/blob/master/src/gc/impl/conservative/gc.d


Create empty SList or DList.

2019-06-26 Thread bauss via Digitalmars-d-learn
Is there a way to achieve that instead of something hacky like 
adding an initialized element and then removing it.


Ex. instead of:

auto stack = SList!int(0);
stack.removeFront();

Then something that just allowed you to do:
auto stack = SList!int; // Not allowed.

---

I feel like this makes containers like that a big hassle in D 
because you may not wanna initialize the elements of them right 
away.


Re: Create empty SList or DList.

2019-06-26 Thread drug via Digitalmars-d-learn

26.06.2019 20:39, bauss пишет:

auto stack = SList!int(0);
stack.removeFront();

Then something that just allowed you to do:
auto stack = SList!int;


this compiles:
```
auto stack = SList!int();
```



Re: Create empty SList or DList.

2019-06-26 Thread bauss via Digitalmars-d-learn

On Wednesday, 26 June 2019 at 19:06:24 UTC, drug wrote:

26.06.2019 20:39, bauss пишет:

auto stack = SList!int(0);
stack.removeFront();

Then something that just allowed you to do:
auto stack = SList!int;


this compiles:
```
auto stack = SList!int();
```


Maybe something else triggered it for me but I kept getting an 
error message like "not initialized with a value" or something 
like that .


I can't reproduce it right now though.


question about call cpp class constructer without new , and define cpp delegate

2019-06-26 Thread ChangLoong via Digitalmars-d-learn
If I want call cpp class constructer without new method, is there 
a way to do that ?


and also if the cpp api accept a delegate as parameter, how to 
create one from d and pass to cpp ?





Re: question about call cpp class constructer without new , and define cpp delegate

2019-06-26 Thread evilrat via Digitalmars-d-learn

On Thursday, 27 June 2019 at 05:37:08 UTC, ChangLoong wrote:
If I want call cpp class constructer without new method, is 
there a way to do that ?


If what you really want is to actually allocate using C++ new 
operator from D, then that is very problematic and not portable 
even across compilers on same OS.


If C++ side has poor design around this specific issue and 
expects passed object to be delete'd (using the C++ delete 
operator) later then you are in trouble. In that case you have to 
make simple wrapper on C++ side to be able to call new/delete 
from D.


If all you want is to allocate memory for object(existing buffer, 
malloc, etc..) and place it there you can use emplace function 
and call ctor later (see below)
https://dlang.org/phobos/core_lifetime.html#.emplace , or there 
was one in "object" module IIRC


Otherwise it is also possible to just call constructors manually 
using its internal name

   myObj.__ctor(..params..) / this.__ctor(...)

(destructors also possible, see __dtor/__xdtor. hint: __dtor is 
probably not what you want, read the docs first)


And finally to just allocate with GC using D new operator
   auto myObj = new MyClass(...);

Just make sure that this object won't be delete'd from C++


and also if the cpp api accept a delegate as parameter, how to 
create one from d and pass to cpp ?


Probably not possible. There are no delegates in C++, instead it 
has pointers to member functions and limited lambdas, and there 
is no analogs in D. You can try to craft it somehow to be ABI 
compatible, but probably easier to just make simple wrapper on 
C++ side.
IIRC member pointers is just pointer, and you provide 'this' 
context on call, while in D delegate is 2 pointers - context AND 
function