Re: Error: constructor Foo.this default constructor for structs only allowed with @disable, no body, and no parameters

2016-03-07 Thread Nicholas Wilson via Digitalmars-d-learn

On Monday, 7 March 2016 at 13:23:58 UTC, Nicholas Wilson wrote:

struct Fence
{
VkFence fence;
alias fence this;

 static struct CreateInfo
{
 VkFenceCreateInfo  ci;
 alias ci this;
 this(
   )
{
 ci = typeof(ci)(
 cast(typeof(ci.sType))StructureType.eFenceCreateInfo,
 null,
 0);
 }
 }
}

I'm not quite sure what this error is saying. Is it that the 
only struct constructor that can have no parameters is @disable 
this(){} ?


If so this is rather annoying as I have to create a new code 
path for the generation of this and 7 other structs. What must 
the code be in this case?


 static struct CreateInfo
{
		 VkFenceCreateInfo	ci = 
VkFenceCreateInfo(cast(typeof(ci.sType))StructureType.eFenceCreateInfo,null,0);

 alias ci this;
}
?


"Solved" by having a default parameter. Results in a deprecation 
but w/e.


Re: Speed up `dub`.

2016-03-07 Thread Luis via Digitalmars-d-learn

On Monday, 7 March 2016 at 18:58:55 UTC, ciechowoj wrote:

dub --version
DUB version 0.9.24+161-gb9ce700, built on Feb 23 2016

`dub.json` is `dub.json` of dstep

`dub test --skip-registry=all`
Do not helps.


I try to grab dstep with dub fetch step (dub version 0.9.24, 
built on Aug 19 2015, on Ubuntu), and try to run dub build step. 
I can confirm that on my machine takes around 5 seconds to check 
if the dependencies are update.


Re: Speed up `dub`.

2016-03-07 Thread Seb via Digitalmars-d-learn

On Monday, 7 March 2016 at 09:18:37 UTC, ciechowoj wrote:
I'm using `dub` to build project. And every time I run `dub` it 
seems to check if dependencies are up to date, which takes some 
time. Is there a way to switch of that checking? Or any other 
way to speed up building process? It really slows down my 
modify-compile-check iteration time.


Use ld.gold - it will speed up your linking quite dramatically!

https://code.dawg.eu/reducing-vibed-turnaround-time-part-1-faster-linking.html


Re: Speed up `dub`.

2016-03-07 Thread xcvn via Digitalmars-d-learn

On Monday, 7 March 2016 at 19:58:19 UTC, WebFreak001 wrote:

On Monday, 7 March 2016 at 18:58:55 UTC, ciechowoj wrote:

dub --version
DUB version 0.9.24+161-gb9ce700, built on Feb 23 2016

`dub.json` is `dub.json` of dstep

`dub test --skip-registry=all`
Do not helps.


Its because of dub going through all those JSON files. For 
example just querying the import paths would probably take like 
7s in your case. Try "dub describe --import-paths" in your 
project. Its something you can't do anything against except 
reporting it to the dub issues


Yes but if he wants to build then `--describe` will not help that 
much !


Re: Speed up `dub`.

2016-03-07 Thread WebFreak001 via Digitalmars-d-learn

On Monday, 7 March 2016 at 18:58:55 UTC, ciechowoj wrote:

dub --version
DUB version 0.9.24+161-gb9ce700, built on Feb 23 2016

`dub.json` is `dub.json` of dstep

`dub test --skip-registry=all`
Do not helps.


Its because of dub going through all those JSON files. For 
example just querying the import paths would probably take like 
7s in your case. Try "dub describe --import-paths" in your 
project. Its something you can't do anything against except 
reporting it to the dub issues


Re: Speed up `dub`.

2016-03-07 Thread Daniel Kozak via Digitalmars-d-learn
I would say dub is broken and should be fixed. Even dub run is really 
slow and try to build everything. So please report a bug: 
https://github.com/D-Programming-Language/dub/issues


Dne 7.3.2016 v 19:58 ciechowoj via Digitalmars-d-learn napsal(a):

dub --version
DUB version 0.9.24+161-gb9ce700, built on Feb 23 2016

`dub.json` is `dub.json` of dstep

`dub test --skip-registry=all`
Do not helps.




Re: Speed up `dub`.

2016-03-07 Thread ciechowoj via Digitalmars-d-learn

dub --version
DUB version 0.9.24+161-gb9ce700, built on Feb 23 2016

`dub.json` is `dub.json` of dstep

`dub test --skip-registry=all`
Do not helps.


Re: Const vs Non const method

2016-03-07 Thread Ola Fosheim Grøstad via Digitalmars-d-learn

On Monday, 7 March 2016 at 18:44:01 UTC, Namespace wrote:
Honestly speaking, I think this case is impossible to solve in 
C++. I'll show my fellow students the advantages of D over C++ 
in next couple of weeks, and this example is pretty good. :)


:-) Good luck!


Re: Const vs Non const method

2016-03-07 Thread Namespace via Digitalmars-d-learn
On Monday, 7 March 2016 at 18:17:18 UTC, Ola Fosheim Grøstad 
wrote:

On Monday, 7 March 2016 at 16:30:48 UTC, Namespace wrote:
Thanks to the wildcard modifier inout. Is there any possible 
way to do the same in C++?


In this specific case you could do it with a macro if you don't 
mind dirty macros, but you really should implement the const 
version explicitly or use a free function that cover both cases 
using templating.


If you are looking for information on C++ you probably should 
use stack overflow:


http://stackoverflow.com/questions/7792052/c-template-to-cover-const-and-non-const-method


Honestly speaking, I think this case is impossible to solve in 
C++. I'll show my fellow students the advantages of D over C++ in 
next couple of weeks, and this example is pretty good. :)


Re: Const vs Non const method

2016-03-07 Thread Ola Fosheim Grøstad via Digitalmars-d-learn

On Monday, 7 March 2016 at 16:30:48 UTC, Namespace wrote:
Thanks to the wildcard modifier inout. Is there any possible 
way to do the same in C++?


In this specific case you could do it with a macro if you don't 
mind dirty macros, but you really should implement the const 
version explicitly or use a free function that cover both cases 
using templating.


If you are looking for information on C++ you probably should use 
stack overflow:


http://stackoverflow.com/questions/7792052/c-template-to-cover-const-and-non-const-method



Re: Const vs Non const method

2016-03-07 Thread Namespace via Digitalmars-d-learn

Let's use an example:


import std.stdio;

class Visitor {
public:
void visit(inout A) {
writeln("visit A");
}

void visit(inout B) {
writeln("visit B");
}
}

class A {
public:
void accept(Visitor v) inout {
v.visit(this);
}
}

class B : A {
public:
override void accept(Visitor v) inout {
v.visit(this);
}
}


This piece of code works for both versions below:

#1:

void main() {
A a = new A();
A b = new B();

Visitor v = new Visitor();

a.accept(v);
b.accept(v);
}


#2:

void main() {
const A a = new A();
const A b = new B();

Visitor v = new Visitor();

a.accept(v);
b.accept(v);
}


Thanks to the wildcard modifier inout. Is there any possible way 
to do the same in C++?


Re: Is it safe to use 'is' to compare types?

2016-03-07 Thread Steven Schveighoffer via Digitalmars-d-learn

On 3/4/16 4:30 PM, Yuxuan Shui wrote:

On Friday, 4 March 2016 at 15:18:55 UTC, Steven Schveighoffer wrote:

On 3/3/16 6:58 PM, Yuxuan Shui wrote:

On Thursday, 3 March 2016 at 23:51:16 UTC, Adam D. Ruppe wrote:

On Thursday, 3 March 2016 at 23:46:50 UTC, Yuxuan Shui wrote:

Will typeid(a) is typeid(b) yield different results than typeid(a) ==
typeid(b)?


No. Indeed, opEquals on TypeInfo just calls is itself.


But opEquals also has extra comparison:

 auto ti = cast(const TypeInfo)o;
 return ti && this.toString() == ti.toString();

This makes me feel they are not the same.


In some cases, for instance using DLLs, the TypeInfo for an object
allocated in one way may be identical, but be a different instance
from the TypeInfo allocated in another way. This is why the string
comparison occurs.

Note that comparing ANY object will first check if they are the same
instance before calling any functions (this is in object.opEquals)



Thanks for answering. But I still don't understand why TypeInfo would
need to be allocated. Aren't typeid() just returning references to the
__DxxTypeInfo___initZ symbol?


You misunderstood, I meant the typeinfo *for* an allocated object, not 
that the typeinfo was allocated.


In some cases, 2 different objects allocated from different libraries 
(usually DLL-land) may reference TypeInfo from different segments, even 
though the TypeInfo is identical.


-Steve


Re: Speed up `dub`.

2016-03-07 Thread Martin Tschierschke via Digitalmars-d-learn

On Monday, 7 March 2016 at 09:18:37 UTC, ciechowoj wrote:
I'm using `dub` to build project. And every time I run `dub` it 
seems to check if dependencies are up to date, which takes some 
time. Is there a way to switch of that checking? Or any other 
way to speed up building process? It really slows down my 
modify-compile-check iteration time.


A few hours ago dub.pm alias code.dlang.org was down or slow, so 
I used:


$> dub --skip-registry=all build

might be thats the reason?


Re: Error: constructor Foo.this default constructor for structs only allowed with @disable, no body, and no parameters

2016-03-07 Thread Alex Parrill via Digitalmars-d-learn

On Monday, 7 March 2016 at 13:23:58 UTC, Nicholas Wilson wrote:
I'm not quite sure what this error is saying. Is it that the 
only struct constructor that can have no parameters is @disable 
this(){} ?


Yes, this is exactly right. You cannot have a structure with a 
default constructor, except with @disable.


You can, however, specify the initial values of fields, as in 
your second example. Note that you can use typeof on the variable 
you are currently declaring.


VkFenceCreateInfo CI = 
typeof(CI)(cast(typeof(CI.sType))StructureType.eFenceCreateInfo, 
null, 0);




Error: constructor Foo.this default constructor for structs only allowed with @disable, no body, and no parameters

2016-03-07 Thread Nicholas Wilson via Digitalmars-d-learn

struct Fence
{
VkFence fence;
alias fence this;

 static struct CreateInfo
{
 VkFenceCreateInfo  ci;
 alias ci this;
 this(
   )
{
 ci = typeof(ci)(
 cast(typeof(ci.sType))StructureType.eFenceCreateInfo,
 null,
 0);
 }
 }
}

I'm not quite sure what this error is saying. Is it that the only 
struct constructor that can have no parameters is @disable 
this(){} ?


If so this is rather annoying as I have to create a new code path 
for the generation of this and 7 other structs. What must the 
code be in this case?


 static struct CreateInfo
{
		 VkFenceCreateInfo	ci = 
VkFenceCreateInfo(cast(typeof(ci.sType))StructureType.eFenceCreateInfo,null,0);

 alias ci this;
}
?


Re: Determine decimal separator (comma vs point)

2016-03-07 Thread Andre via Digitalmars-d-learn

On Monday, 7 March 2016 at 12:29:39 UTC, Andre wrote:

Hi,

I execute an external application and get some decimal numbers:

auto p = execute(["curl", "-o", "/dev/null", "-s", "-w",

"%{time_namelookup}:%{time_appconnect}:%{time_redirect}:%{time_starttransfer}:%{time_pretransfer}:%{time_connect}:%{time_total}",
url]);

On my windows system, the decimal separator is "," therefore I 
want
to replace the "," with "." to avoid exceptions while 
converting the value to!double.


I thought following coding should return "," on my OS because 
it is set in the region settings but "." is returned:


import core.stdc.locale;

auto lConv = localeconv();
char decSeparator = *lConv.decimal_point;

How can I determine the correct decimal separator?

Kind regards
André


I just found the answer:

lconv* lc;
setlocale(LC_NUMERIC, "");
lc = localeconv();
writeln(to!string(lc.decimal_point));


Re: Speed up `dub`.

2016-03-07 Thread Luis via Digitalmars-d-learn

On Monday, 7 March 2016 at 09:18:37 UTC, ciechowoj wrote:
I'm using `dub` to build project. And every time I run `dub` it 
seems to check if dependencies are up to date, which takes some 
time. Is there a way to switch of that checking? Or any other 
way to speed up building process? It really slows down my 
modify-compile-check iteration time.


On my case, I don't see taking too long. Could you check what 
version of dub are you using, and what OS & D compiler and 
version ?

And better, if you can past here your dub.sdl/dub.json .


Determine decimal separator (comma vs point)

2016-03-07 Thread Andre via Digitalmars-d-learn

Hi,

I execute an external application and get some decimal numbers:

auto p = execute(["curl", "-o", "/dev/null", "-s", "-w",

"%{time_namelookup}:%{time_appconnect}:%{time_redirect}:%{time_starttransfer}:%{time_pretransfer}:%{time_connect}:%{time_total}",
url]);

On my windows system, the decimal separator is "," therefore I 
want
to replace the "," with "." to avoid exceptions while converting 
the value to!double.


I thought following coding should return "," on my OS because it 
is set in the region settings but "." is returned:


import core.stdc.locale;

auto lConv = localeconv();
char decSeparator = *lConv.decimal_point;

How can I determine the correct decimal separator?

Kind regards
André



Re: Const vs Non const method

2016-03-07 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Monday, 7 March 2016 at 10:52:53 UTC, Ola Fosheim Grøstad 
wrote:

On Sunday, 6 March 2016 at 17:53:47 UTC, Namespace wrote:
What would be the C++ way? Is there any comfortable way to 
solve this problem in a nice way like D?


C++ has a non-idiomatic language culture. There are many ways 
to do it. One clean way could be to use a templated method, 
another way is to use a function object, a dirty way would be 
to use a const-cast.


Another thing in C++ is that you can overload members on rvalue 
and lvalue references, from 
http://en.cppreference.com/w/cpp/language/member_functions :


#include 
struct S {
void f() & { std::cout << "lvalue\n"; }
void f() &&{ std::cout << "rvalue\n"; }
};

int main(){
S s;
s.f();// prints "lvalue"
std::move(s).f(); // prints "rvalue"
S().f();  // prints "rvalue"
}


Of course, all of this is just because you don't get to specify 
the type of the "this" pointer... So not as clean as it should 
be, but that applies to both languages. Adding lots of syntax 
with no real semantic benefits.





Re: Const vs Non const method

2016-03-07 Thread Ola Fosheim Grøstad via Digitalmars-d-learn

On Sunday, 6 March 2016 at 17:53:47 UTC, Namespace wrote:
What would be the C++ way? Is there any comfortable way to 
solve this problem in a nice way like D?


C++ has a non-idiomatic language culture. There are many ways to 
do it. One clean way could be to use a templated method, another 
way is to use a function object, a dirty way would be to use a 
const-cast.





Re: Speed up `dub`.

2016-03-07 Thread ciechowoj via Digitalmars-d-learn

On Monday, 7 March 2016 at 09:22:16 UTC, Daniel Kozak wrote:

maybe: dub build --nodeps

Dne 7.3.2016 v 10:18 ciechowoj via Digitalmars-d-learn 
napsal(a):
I'm using `dub` to build project. And every time I run `dub` 
it seems to check if dependencies are up to date, which takes 
some time. Is there a way to switch of that checking? Or any 
other way to speed up building process? It really slows down 
my modify-compile-check iteration time.


I've tried that one already - it makes no difference.
Currently when I run `dub test` it takes about 9s (project is 
already built). When running the executable directly takes only 
0.2s :/.


Re: Speed up `dub`.

2016-03-07 Thread Daniel Kozak via Digitalmars-d-learn

maybe: dub build --nodeps

Dne 7.3.2016 v 10:18 ciechowoj via Digitalmars-d-learn napsal(a):
I'm using `dub` to build project. And every time I run `dub` it seems 
to check if dependencies are up to date, which takes some time. Is 
there a way to switch of that checking? Or any other way to speed up 
building process? It really slows down my modify-compile-check 
iteration time.




Speed up `dub`.

2016-03-07 Thread ciechowoj via Digitalmars-d-learn
I'm using `dub` to build project. And every time I run `dub` it 
seems to check if dependencies are up to date, which takes some 
time. Is there a way to switch of that checking? Or any other way 
to speed up building process? It really slows down my 
modify-compile-check iteration time.


Re: Create Windows "shortcut" (.lnk) with D?

2016-03-07 Thread Andrea Fontana via Digitalmars-d-learn

On Sunday, 6 March 2016 at 20:13:39 UTC, 岩倉 澪 wrote:

On Sunday, 6 March 2016 at 11:00:35 UTC, John wrote:

On Sunday, 6 March 2016 at 03:13:23 UTC, 岩倉 澪 wrote:

IShellLinkA* shellLink;
IPersistFile* linkFile;

Any help would be highly appreciated as I'm new to Windows 
programming in D and have no idea what I'm doing wrong!


In D, interfaces are references, so it should be:

  IShellLinkA shellLink;
  IPersistFile linkFile;


That's exactly what the problem was, thank you!!


You can use official specs to recreate binary file:
https://msdn.microsoft.com/en-us/library/dd871305.aspx

Ok, not the fastest way. :)