Re: Static CT Factory

2016-08-18 Thread Engine Machine via Digitalmars-d-learn

On Friday, 19 August 2016 at 02:54:48 UTC, Basile B. wrote:

On Friday, 19 August 2016 at 01:53:22 UTC, Engine Machine wrote:

On Friday, 19 August 2016 at 01:25:10 UTC, Anonymouse wrote:

On Friday, 19 August 2016 at 01:10:42 UTC, Engine Machine

x = 1.234;

Ok, well, I guess the error comes from something else.


*x = 1.234 for when T verifies is(T == int*) produces an error.

You can put an aditional argument in the function header:

void foo(T)(auto ref T t = T.init)
{
static if (is(T == int))
auto x = new Thing!int;
else static if (is(T == double))
auto x = new Thing!double;
else
static assert(false, "incorrect type");
*x = t;
}


It was because I had a added a new type that I didn't account for 
in the static if chain ;/ The static assert is sort of required. 
We sort of need a static switch with required default so 
forgetting this stuff doesn't break later on(in strange ways) 
when new types are added.








Re: Static CT Factory

2016-08-18 Thread Basile B. via Digitalmars-d-learn

On Friday, 19 August 2016 at 01:53:22 UTC, Engine Machine wrote:

On Friday, 19 August 2016 at 01:25:10 UTC, Anonymouse wrote:

On Friday, 19 August 2016 at 01:10:42 UTC, Engine Machine

x = 1.234;

Ok, well, I guess the error comes from something else.


*x = 1.234 for when T verifies is(T == int*) produces an error.

You can put an aditional argument in the function header:

void foo(T)(auto ref T t = T.init)
{
static if (is(T == int))
auto x = new Thing!int;
else static if (is(T == double))
auto x = new Thing!double;
else
static assert(false, "incorrect type");
*x = t;
}


Re: Static CT Factory

2016-08-18 Thread Engine Machine via Digitalmars-d-learn

On Friday, 19 August 2016 at 01:18:28 UTC, Adam D. Ruppe wrote:

On Friday, 19 August 2016 at 01:10:42 UTC, Engine Machine wrote:
I feel that in this case I feel that the scope of the static 
if should allow things to escape since, well, they are static 
if's.



They do.

What, exactly, did you do and what, exactly did you see as the 
error?


I get undefined identifier, but when create the variable outside 
it works.


I used Anonymouse code and it works so I guess the issue stems 
from something else.


My code is more complex and the stuff is in a foreach. I don't 
know why it isn't working since the simplified code is nearly 
identical. Maybe a branch wasn't being taken, I thought I covered 
them all.







Re: Static CT Factory

2016-08-18 Thread Engine Machine via Digitalmars-d-learn

On Friday, 19 August 2016 at 01:25:10 UTC, Anonymouse wrote:

On Friday, 19 August 2016 at 01:10:42 UTC, Engine Machine wrote:
I have a template that is suppose to create a type based on a 
template parameter


static if (T == "int")
{
   auto x = New!int();
}
else static if (T == "double")
{
   auto x = New!double();
}

x = 1.234;


This is just an example, I use custom types.

The static if's prevent x's scope from being after them, even 
though it should work perfectly fine. I can't declare x before 
because I don't know the type.


I'm not sure I understand. static if shouldn't introduce a new 
scope that way.


https://dpaste.dzfl.pl/7b63a6e52309

Mind that x might be a pointer.


Ok, well, I guess the error comes from something else.


Re: Static CT Factory

2016-08-18 Thread Anonymouse via Digitalmars-d-learn

On Friday, 19 August 2016 at 01:10:42 UTC, Engine Machine wrote:
I have a template that is suppose to create a type based on a 
template parameter


static if (T == "int")
{
   auto x = New!int();
}
else static if (T == "double")
{
   auto x = New!double();
}

x = 1.234;


This is just an example, I use custom types.

The static if's prevent x's scope from being after them, even 
though it should work perfectly fine. I can't declare x before 
because I don't know the type.


I'm not sure I understand. static if shouldn't introduce a new 
scope that way.


https://dpaste.dzfl.pl/7b63a6e52309

Mind that x might be a pointer.


Static CT Factory

2016-08-18 Thread Engine Machine via Digitalmars-d-learn
I have a template that is suppose to create a type based on a 
template parameter


static if (T == "int")
{
   auto x = New!int();
}
else static if (T == "double")
{
   auto x = New!double();
}

x = 1.234;


This is just an example, I use custom types.

The static if's prevent x's scope from being after them, even 
though it should work perfectly fine. I can't declare x before 
because I don't know the type.


The point is that I don't want to have to put x = 1.234; in each 
static if block when I should be able to do it perfectly fine 
afterwards.


My types that I'm creating all have a name field and I want to 
set it once after the object is created.


Luckily, all of them inherit from the same type and I can declare 
that before the static if block, but in general, that won't work.


I feel that in this case I feel that the scope of the static if 
should allow things to escape since, well, they are static if's. 
It would be similar to #ifdef.


I realize that D doesn't work this way, I'm asking for a nicer 
solution than having to duplicate the same code(x = 1.234 in this 
example) or having use a base class.




Re: RSA library

2016-08-18 Thread Andre via Digitalmars-d-learn

On Thursday, 18 August 2016 at 14:29:54 UTC, Adam D. Ruppe wrote:

On Thursday, 18 August 2016 at 09:00:58 UTC, Andre Pany wrote:
Is there a D library which can be built with a plain x86 DMD 
and without dll dependencies?


Not that I know of, and I don't think the win32 api includes 
rsa256 (though .net does!).


The botan lib though, why doesn't it work on 32 bit optlink? 
You might be able to hack it by just taking the algorithms you 
need and compiling yourself.


It is a statement from the botan github readme, maybe due to a 
dependency.


I will try the windows api, from the description it seems exactly 
what i need. I will also check wheter the specific botan part 
could be extracted.

Thanks a lot.

Kind regards
Andre


Re: compile error while use `extern(C++, class)`

2016-08-18 Thread Lodovico Giaretta via Digitalmars-d-learn

On Thursday, 18 August 2016 at 16:19:41 UTC, Johan Engelen wrote:
On Thursday, 18 August 2016 at 11:43:03 UTC, Lodovico Giaretta 
wrote:
Which compiler version are you using? On DMD 2.071.0 this does 
not work.


Note: this does work with LDC 1.1.0 even though it is based on 
DMD 2.071.


https://github.com/ldc-developers/ldc/releases/tag/v1.1.0-beta2


Well, LDC 1.1.0 is based on DMD 2.071.1, while I tested the above 
code on asm.dlang.org with DMD 2.071.0, so maybe on DMD 2.071.1 
it works too. On nightly it works for sure.
So again nothing wrong here, just a matter of having the most 
recent compiler version.


Re: compile error while use `extern(C++, class)`

2016-08-18 Thread Johan Engelen via Digitalmars-d-learn
On Thursday, 18 August 2016 at 11:43:03 UTC, Lodovico Giaretta 
wrote:

On Thursday, 18 August 2016 at 11:11:10 UTC, mogu wrote:


Compiler Error exactly. The minimal code is(dmd or ldc2 in 
ubuntu 16.04 lts):

```
extern (C++, struct)
class A {}
```

Error: identifier expected for C++ namespace found 'struct' 
when expecting ')' declaration expected, not ')'


Which compiler version are you using? On DMD 2.071.0 this does 
not work.


Note: this does work with LDC 1.1.0 even though it is based on 
DMD 2.071.


https://github.com/ldc-developers/ldc/releases/tag/v1.1.0-beta2



Re: RSA library

2016-08-18 Thread Kagamin via Digitalmars-d-learn
Well, windows api has RSA 
https://msdn.microsoft.com/en-us/library/windows/desktop/aa375534%28v=vs.85%29.aspx is it different from RSA256?


Re: RSA library

2016-08-18 Thread Adam D. Ruppe via Digitalmars-d-learn

On Thursday, 18 August 2016 at 09:00:58 UTC, Andre Pany wrote:
Is there a D library which can be built with a plain x86 DMD 
and without dll dependencies?


Not that I know of, and I don't think the win32 api includes 
rsa256 (though .net does!).


The botan lib though, why doesn't it work on 32 bit optlink? You 
might be able to hack it by just taking the algorithms you need 
and compiling yourself.


Re: compile error while use `extern(C++, class)`

2016-08-18 Thread pineapple via Digitalmars-d-learn
On Thursday, 18 August 2016 at 11:43:03 UTC, Lodovico Giaretta 
wrote:

On Thursday, 18 August 2016 at 11:11:10 UTC, mogu wrote:
On Thursday, 18 August 2016 at 10:45:14 UTC, Lodovico Giaretta 
wrote:


Which kind of error? An error message by the compiler? One by 
the linker? The compiler crashes?




Compiler Error exactly. The minimal code is(dmd or ldc2 in 
ubuntu 16.04 lts):

```
extern (C++, struct)
class A {}
```

Error: identifier expected for C++ namespace found 'struct' 
when expecting ')' declaration expected, not ')'


Which compiler version are you using? On DMD 2.071.0 this does 
not work. On nightly build it compiles without errors. So 
probably it is a feature that is present, but didn't ship yet. 
I suggest you download the latest beta or a nightly build from 
the site.


Wouldn't this be more syntactically consistent if it were "Cpp" 
instead of "C++"?


Re: compile error while use `extern(C++, class)`

2016-08-18 Thread Lodovico Giaretta via Digitalmars-d-learn

On Thursday, 18 August 2016 at 11:11:10 UTC, mogu wrote:
On Thursday, 18 August 2016 at 10:45:14 UTC, Lodovico Giaretta 
wrote:


Which kind of error? An error message by the compiler? One by 
the linker? The compiler crashes?




Compiler Error exactly. The minimal code is(dmd or ldc2 in 
ubuntu 16.04 lts):

```
extern (C++, struct)
class A {}
```

Error: identifier expected for C++ namespace found 'struct' 
when expecting ')' declaration expected, not ')'


Which compiler version are you using? On DMD 2.071.0 this does 
not work. On nightly build it compiles without errors. So 
probably it is a feature that is present, but didn't ship yet. I 
suggest you download the latest beta or a nightly build from the 
site.


Re: compile error while use `extern(C++, class)`

2016-08-18 Thread mogu via Digitalmars-d-learn
On Thursday, 18 August 2016 at 10:45:14 UTC, Lodovico Giaretta 
wrote:


Which kind of error? An error message by the compiler? One by 
the linker? The compiler crashes?




Compiler Error exactly. The minimal code is(dmd or ldc2 in ubuntu 
16.04 lts):

```
extern (C++, struct)
class A {}
```

Error: identifier expected for C++ namespace found 'struct' when 
expecting ')' declaration expected, not ')'