Orange serializer/deserializer

2018-06-01 Thread IntegratedDimensions via Digitalmars-d-learn
How can I modify the pre serialization and post serialization values? I need to transform some variables that are stored but I would like to do this easily "inline"(would be cool to be able to provide a delegate to do the transformations at the site of definition of the fields). Also, how do

How are switches optimized

2018-06-01 Thread IntegratedDimensions via Digitalmars-d-learn
What is the best optimizations that a compiler does to switches in general and in the D compilers? A switch can be seen as if statements, or safer, nested if elses. but surely the cost per case does not grow with depth in the switch? If one has a switch of N case then the last cost surely doe

Re: Getter an lvalue and cannot be modified

2018-05-27 Thread IntegratedDimensions via Digitalmars-d-learn
On Sunday, 27 May 2018 at 09:28:36 UTC, Mike Franklin wrote: On Sunday, 27 May 2018 at 09:23:09 UTC, IntegratedDimensions wrote: C[] c; @property C[] get() { return c; } get ~= something; errors out, yet auto q = get; q ~= something; is fine. Why is D thinking that ~= is being applied to g

Re: Code repetition

2018-05-27 Thread IntegratedDimensions via Digitalmars-d-learn
On Sunday, 27 May 2018 at 13:20:08 UTC, Adam D. Ruppe wrote: On Sunday, 27 May 2018 at 06:47:38 UTC, IntegratedDimensions wrote: Putting the code in a template/function/lambda does not work because of the scopes which will be called when the main function exists. I think you might just be usi

Getter an lvalue and cannot be modified

2018-05-27 Thread IntegratedDimensions via Digitalmars-d-learn
C[] c; @property C[] get() { return c; } get ~= something; errors out, yet auto q = get; q ~= something; is fine. Why is D thinking that ~= is being applied to get, the function, rather than what it returns? Also When I converted a field in to a property, an AA, it is returning null rat

Code repetition

2018-05-26 Thread IntegratedDimensions via Digitalmars-d-learn
I have some code like void foo() { // setup stuff int x; scope(exit) something; // x = 34; } void foon() { // setup stuff int x; scope(exit) something; // } All the setup stuff is virtually identical in each foo. There are slight differences such

Re: Code repetition

2018-05-26 Thread IntegratedDimensions via Digitalmars-d-learn
I guess I should have mentioned that basically this is like a C macro.

Re: C style callbacks fix for member callbacks

2018-05-25 Thread IntegratedDimensions via Digitalmars-d-learn
Investigating further, this does not seem to be pushed on the stack but set in EAX. Hence no amount of parameter placement manipulation will work. It actually becomes an easy situation although this will be invalid as it will be be whatever value is in EAX used by the caller. One cannot set

Re: Any way to override base type with dervived in derived type

2018-05-25 Thread IntegratedDimensions via Digitalmars-d-learn
On Saturday, 26 May 2018 at 01:11:39 UTC, crimaniak wrote: On Thursday, 24 May 2018 at 20:24:32 UTC, IntegratedDimensions wrote: I'm pretty much guaranteed that in C, t will be type TT due to the design(C goes with TT like bread with butter). ... 1) Your architecture is wrong, I recommend to re

Re: Any way to override base type with dervived in derived type

2018-05-25 Thread IntegratedDimensions via Digitalmars-d-learn
On Friday, 25 May 2018 at 10:45:23 UTC, Steven Schveighoffer wrote: On 5/24/18 4:24 PM, IntegratedDimensions wrote: What I'd like to do is class C : A {    private override @property TT t() { return cast(TT)(_t); } // null check if necessary    // Stuff below uses t which is now a TT    .

Re: Any way to override base type with dervived in derived type

2018-05-25 Thread IntegratedDimensions via Digitalmars-d-learn
On Friday, 25 May 2018 at 10:45:23 UTC, Steven Schveighoffer wrote: On 5/24/18 4:24 PM, IntegratedDimensions wrote: What I'd like to do is class C : A {    private override @property TT t() { return cast(TT)(_t); } // null check if necessary    // Stuff below uses t which is now a TT    .

Re: Any way to override base type with dervived in derived type

2018-05-24 Thread IntegratedDimensions via Digitalmars-d-learn
On Friday, 25 May 2018 at 01:42:48 UTC, Basile B. wrote: On Friday, 25 May 2018 at 01:17:45 UTC, IntegratedDimensions wrote: On Friday, 25 May 2018 at 01:02:00 UTC, Basile B. wrote: On Friday, 25 May 2018 at 00:15:39 UTC, IntegratedDimensions wrote: On Thursday, 24 May 2018 at 23:31:50 UTC, Al

Re: Any way to override base type with dervived in derived type

2018-05-24 Thread IntegratedDimensions via Digitalmars-d-learn
On Friday, 25 May 2018 at 01:02:00 UTC, Basile B. wrote: On Friday, 25 May 2018 at 00:15:39 UTC, IntegratedDimensions wrote: On Thursday, 24 May 2018 at 23:31:50 UTC, Alex wrote: On Thursday, 24 May 2018 at 20:24:32 UTC, IntegratedDimensions wrote: class T; class TT : T; interface I { @pro

Re: Any way to override base type with dervived in derived type

2018-05-24 Thread IntegratedDimensions via Digitalmars-d-learn
On Thursday, 24 May 2018 at 23:31:50 UTC, Alex wrote: On Thursday, 24 May 2018 at 20:24:32 UTC, IntegratedDimensions wrote: class T; class TT : T; interface I { @property T t(); } abstract class A { T _t; @property T t() { return _t; } } class C : A { // Stuff below uses t as TT

Any way to override base type with dervived in derived type

2018-05-24 Thread IntegratedDimensions via Digitalmars-d-learn
class T; class TT : T; interface I { @property T t(); } abstract class A { T _t; @property T t() { return _t; } } class C : A { // Stuff below uses t as TT but compiler, of course, treats t as T ... } The issue is that I programmed the class C with a variable that directly

Re: Efficient idiom for fastest code

2018-05-23 Thread IntegratedDimensions via Digitalmars-d-learn
On Wednesday, 23 May 2018 at 10:55:02 UTC, Malte wrote: On Wednesday, 23 May 2018 at 02:24:08 UTC, IntegratedDimensions wrote: [...] I would just do [...] [...] Thanks, I didn't think about using a for loop like that. While it is not the most general it does solve the specific case for

Re: Efficient idiom for fastest code

2018-05-22 Thread IntegratedDimensions via Digitalmars-d-learn
On Wednesday, 23 May 2018 at 03:00:17 UTC, Nicholas Wilson wrote: On Wednesday, 23 May 2018 at 02:24:08 UTC, IntegratedDimensions wrote: Many times in expensive loops one must make decisions. Decisions must be determined and the determination costs. for(int i = 0; i < N; i++) { if(decisi

Efficient idiom for fastest code

2018-05-22 Thread IntegratedDimensions via Digitalmars-d-learn
Many times in expensive loops one must make decisions. Decisions must be determined and the determination costs. for(int i = 0; i < N; i++) { if(decision(i)) A; else B; } the if statement costs N times the cycle cost. In some cases the decision holds for continuous ranges. For some 0 <=

Re: Locking data

2018-05-22 Thread IntegratedDimensions via Digitalmars-d-learn
On Tuesday, 22 May 2018 at 23:09:24 UTC, Sjoerd Nijboer wrote: On Tuesday, 22 May 2018 at 22:17:05 UTC, IntegratedDimensions wrote: On Tuesday, 22 May 2018 at 22:10:52 UTC, Alex wrote: On Tuesday, 22 May 2018 at 21:45:07 UTC, IntegratedDimensions wrote: an idea to lock data by removing the ref

Re: Locking data

2018-05-22 Thread IntegratedDimensions via Digitalmars-d-learn
On Tuesday, 22 May 2018 at 22:10:52 UTC, Alex wrote: On Tuesday, 22 May 2018 at 21:45:07 UTC, IntegratedDimensions wrote: an idea to lock data by removing the reference: class A { Lockable!Data data; } The idea is that when the data is going to be used, the user locks the data. The trick h

Locking data

2018-05-22 Thread IntegratedDimensions via Digitalmars-d-learn
an idea to lock data by removing the reference: class A { Lockable!Data data; } The idea is that when the data is going to be used, the user locks the data. The trick here is that data is a pointer to the data and the pointer is set to null when locked so no other data can use it(they see

Re: C style callbacks fix for member callbacks

2018-05-21 Thread IntegratedDimensions via Digitalmars-d-learn
On Monday, 21 May 2018 at 02:23:27 UTC, ag0aep6g wrote: I tried this. Your code crashes in windows dmd x86 x64. Hm. Works for me in a virtual machine. But I'm not surprised that it's fragile. It might be completely wrong, and it just happens to look alright on my machine. https://run.dlang.

Re: Real Int24

2018-05-21 Thread IntegratedDimensions via Digitalmars-d-learn
On Monday, 21 May 2018 at 15:41:21 UTC, Simen Kjærås wrote: On Saturday, 19 May 2018 at 18:44:42 UTC, IntegratedDimensions wrote: On Saturday, 19 May 2018 at 18:19:35 UTC, IntegratedDimensions wrote: Is there any way to create an int24 type that behaves just like any other built in type without

Re: C style callbacks fix for member callbacks

2018-05-20 Thread IntegratedDimensions via Digitalmars-d-learn
On Sunday, 20 May 2018 at 23:05:47 UTC, ag0aep6g wrote: On 05/20/2018 06:48 PM, IntegratedDimensions wrote: alias callback = extern(C) int function(const(void) a, void *b, uint c, void* context); (I'm assuming that `a` is supposed to be a `const(void)*`.) Where context acts as this. I would

Re: Convert mixin to function call

2018-05-20 Thread IntegratedDimensions via Digitalmars-d-learn
It should be obvious that these are simplifications. I can't pass the variables directly as parameters as in the real case the names may only be partially specified.

Re: Convert mixin to function call

2018-05-20 Thread IntegratedDimensions via Digitalmars-d-learn
https://dpaste.dzfl.pl/fb49bf834cff import std.stdio; auto Q(string A)() { auto foo() { auto d = mixin(Z!(A)()); return d; } return foo()(); } auto X(string A, string N)() { return N~" = (() { int y = 4; return "~A~" + y +

Re: Convert mixin to function call

2018-05-20 Thread IntegratedDimensions via Digitalmars-d-learn
Also, one thing that would help would be able to create identifier names that are unique to avoid collisions. Does D have any ability to do such a thing?

Convert mixin to function call

2018-05-20 Thread IntegratedDimensions via Digitalmars-d-learn
I have a string mixin that returns a value or function that uses the mixed in scope. Currently I have to wrap the mixin in a delegate or local function as to be able to get the value: int x = 3; int y = 1; auto foo() { mixin(X!("x")); } This allows the the mixin to see the scope but keep the

Re: C style callbacks fix for member callbacks

2018-05-20 Thread IntegratedDimensions via Digitalmars-d-learn
On Sunday, 20 May 2018 at 08:40:57 UTC, MGW wrote: On Saturday, 19 May 2018 at 23:52:58 UTC, IntegratedDimensions wrote: I have a member callback that I want to use as a C callback. http://www.agner.org/optimize/calling_conventions.pdf https://www.youtube.com/watch?v=xhDS377mAc4 Sorry, I c

Re: is ==

2018-05-19 Thread IntegratedDimensions via Digitalmars-d-learn
Furthermore: https://issues.dlang.org/show_bug.cgi?id=3889 Shows real problems. You argue from the side that the bug already exists so we must work around it because we can't go back and "fix things". Who says? D has had breaking changes in the past so it is not a deal breaker. It is also a r

Re: is ==

2018-05-19 Thread IntegratedDimensions via Digitalmars-d-learn
On Sunday, 20 May 2018 at 02:09:47 UTC, Jonathan M Davis wrote: On Sunday, May 20, 2018 01:51:50 IntegratedDimensions via Digitalmars-d- learn wrote: Simply require == null as is null and be done with it. That would be flat out wrong for dynamic arrays, because then auto result = arr == null

Re: is ==

2018-05-19 Thread IntegratedDimensions via Digitalmars-d-learn
On Sunday, 20 May 2018 at 00:19:28 UTC, Jonathan M Davis wrote: On Saturday, May 19, 2018 17:50:50 IntegratedDimensions via Digitalmars-d- learn wrote: So, ultimately what I feels like is that you are actually arguing for == null to be interpreted as is null but you don't realize it yet.

C style callbacks fix for member callbacks

2018-05-19 Thread IntegratedDimensions via Digitalmars-d-learn
I have a member callback that I want to use as a C callback. This is impossible due to the `hidden this` passed as the "first" parameter. The callback already makes it's last value a user pointer which I use as a "this". If I make my method static extern(C) then there is no crash and every

Re: Real Int24

2018-05-19 Thread IntegratedDimensions via Digitalmars-d-learn
On Saturday, 19 May 2018 at 18:19:35 UTC, IntegratedDimensions wrote: Is there any way to create an int24 type that behaves just like any other built in type without having to reimplement everything? In fact, what I'd like to do is create an arbitrary type: struct atype(T) { } where atype(T

Real Int24

2018-05-19 Thread IntegratedDimensions via Digitalmars-d-learn
Is there any way to create an int24 type that behaves just like any other built in type without having to reimplement everything?

Re: is ==

2018-05-19 Thread IntegratedDimensions via Digitalmars-d-learn
On Saturday, 19 May 2018 at 01:31:38 UTC, Jonathan M Davis wrote: On Friday, May 18, 2018 23:53:12 IntegratedDimensions via Digitalmars-d- learn wrote: Why does D complain when using == to compare with null? Is there really any technical reason? if one just defines == null to is null then

Re: is ==

2018-05-18 Thread IntegratedDimensions via Digitalmars-d-learn
On Friday, 18 May 2018 at 23:58:18 UTC, Uknown wrote: On Friday, 18 May 2018 at 23:53:12 UTC, IntegratedDimensions wrote: Why does D complain when using == to compare with null? Is there really any technical reason? if one just defines == null to is null then there should be no problem. It seem

is ==

2018-05-18 Thread IntegratedDimensions via Digitalmars-d-learn
Why does D complain when using == to compare with null? Is there really any technical reason? if one just defines == null to is null then there should be no problem. It seems like a pedantic move by who ever implemented it and I'm hoping there is actually a good technical reason for it.

Re: Dependency injection pattern

2018-05-16 Thread IntegratedDimensions via Digitalmars-d-learn
On Sunday, 13 May 2018 at 07:42:10 UTC, Suliman wrote: Could anybody give small example of Dependency injection pattern? I googled about it, but found only C# examples and I am not quite sure how to use them. Also I would like get some explanation/comments for code. Dependency injection is e

Re: Error: module `hello` is in file 'hello.d' which cannot be read

2018-05-05 Thread IntegratedDimensions via Digitalmars-d-learn
On Friday, 4 May 2018 at 23:29:12 UTC, Alex wrote: Hi I just installed D on my windows 10 and want to try to compile a hello world. My source is a classical import std.stdio; void main() { writeln("Hello, World!"); } And I try to compile and get C:\D>dmd hello.d Error: module `hello` is in

LDC phobos2-ldc.lib(json.obj) : fatal error LNK1112: module machine type 'x64' conflicts with target machine type 'x86'

2018-05-03 Thread IntegratedDimensions via Digitalmars-d-learn
trying to compile a simple program in x86. Compiles fine in dmd and ldcx64. Seems like ldc is using the wrong lib for some reason? phobos2-ldc.lib(json.obj) : fatal error LNK1112: module machine type 'x64' conflicts with target machine type 'x86' Error: C:\Program Files (x86)\Microsoft Visual

Re: How to curl!

2018-05-02 Thread IntegratedDimensions via Digitalmars-d-learn
On Wednesday, 2 May 2018 at 03:03:19 UTC, ikod wrote: On Wednesday, 2 May 2018 at 00:04:49 UTC, IntegratedDimensions wrote: On Tuesday, 1 May 2018 at 23:35:42 UTC, Arun Chandrasekaran wrote: [...] Ok, first try: Unhandled exception: object.Exception can't complete call to TLS_method at requ

Re: How to curl!

2018-05-01 Thread IntegratedDimensions via Digitalmars-d-learn
On Tuesday, 1 May 2018 at 23:35:42 UTC, Arun Chandrasekaran wrote: On Tuesday, 1 May 2018 at 21:57:22 UTC, IntegratedDimensions wrote: Trying to curl basic stuff but std.net.curl isn't cooperating: This is one of the reasons I hate D ;/ I've spent more time trying to get std.net.curl to do some

Re: How to curl!

2018-05-01 Thread IntegratedDimensions via Digitalmars-d-learn
On Tuesday, 1 May 2018 at 23:02:39 UTC, Dr.No wrote: On Tuesday, 1 May 2018 at 22:51:01 UTC, IntegratedDimensions wrote: [...] those dlls: libeay32.dll libssl32.dll ssleay32.dll I'm sure they would be installed with whatever [...] I don't think so. IIRC, when I used D+curl I needed to downl

Re: How to curl!

2018-05-01 Thread IntegratedDimensions via Digitalmars-d-learn
On Tuesday, 1 May 2018 at 22:08:50 UTC, Dr.No wrote: On Tuesday, 1 May 2018 at 21:57:22 UTC, IntegratedDimensions wrote: Trying to curl basic stuff but std.net.curl isn't cooperating: curl "https://www.googleapis.com/youtube/v3/channels"; -G -d part=contentDetails -d forUsername=test -d key=so

How to curl!

2018-05-01 Thread IntegratedDimensions via Digitalmars-d-learn
Trying to curl basic stuff but std.net.curl isn't cooperating: curl "https://www.googleapis.com/youtube/v3/channels"; -G -d part=contentDetails -d forUsername=test -d key=somekey import std.stdio; import std.net.curl; int main(string[] argv) { auto http = HTTP(); http.caInfo(

Re: Making an .exe that executes source file inside itself.

2018-04-27 Thread IntegratedDimensions via Digitalmars-d-learn
On Friday, 27 April 2018 at 14:57:34 UTC, BoQsc wrote: On Friday, 27 April 2018 at 04:30:32 UTC, IntegratedDimensions wrote: On Thursday, 26 April 2018 at 06:18:25 UTC, BoQsc wrote: On Wednesday, 25 April 2018 at 20:44:10 UTC, u0_a183 wrote: On Wednesday, 25 April 2018 at 19:54:26 UTC, BoQsc w

Re: Making an .exe that executes source file inside itself.

2018-04-26 Thread IntegratedDimensions via Digitalmars-d-learn
On Thursday, 26 April 2018 at 06:18:25 UTC, BoQsc wrote: On Wednesday, 25 April 2018 at 20:44:10 UTC, u0_a183 wrote: On Wednesday, 25 April 2018 at 19:54:26 UTC, BoQsc wrote: On Wednesday, 25 April 2018 at 19:43:31 UTC, Jonathan M Davis wrote: On Wednesday, April 25, 2018 19:19:58 BoQsc via Di

Re: Making an .exe that executes source file inside itself.

2018-04-25 Thread IntegratedDimensions via Digitalmars-d-learn
On Wednesday, 25 April 2018 at 19:19:58 UTC, BoQsc wrote: So there has been idea I've got for around few months now: making a software which executable would contain a source file. A software that anyone could modify by opening an executable and quickly change a few lines of it, rerun an executa