Re: What is the "right" way to create a generic type getter (and setter) ?

2018-03-15 Thread James Blachly via Digitalmars-d-learn
On Wednesday, 14 March 2018 at 22:58:25 UTC, ag0aep6g wrote: You can probably get around the (manually maintained?) `FIELDS` array with `.tupleof` or something similar: static foreach (i, f; S.tupleof) { case __traits(identifier, f): } Any pointers / design patterns on this

Re: Error: cannot implicitly convert expression this.aa of type inout(string[string]) to string[string]

2018-03-15 Thread Robert-D via Digitalmars-d-learn
On Thursday, 15 March 2018 at 13:18:38 UTC, Simen Kjærås wrote: On Thursday, 15 March 2018 at 12:00:08 UTC, Robert-D wrote: I want the function to create a mutable copy from a const or a imutable Like this: void main() { const S s = S(["": ""]); S b = s.dup(); } How can i do that?

Re: signbit question

2018-03-15 Thread Seb via Digitalmars-d-learn
On Thursday, 15 March 2018 at 16:31:56 UTC, Stefan Koch wrote: On Thursday, 15 March 2018 at 15:28:16 UTC, Miguel L wrote: Why does std.math.signbit only work for floating point types? Is there an analogue function for integer types? what is the best way to compare the sign of a float with the

Re: signbit question

2018-03-15 Thread rumbu via Digitalmars-d-learn
On Thursday, 15 March 2018 at 17:18:08 UTC, Miguel L wrote: On Thursday, 15 March 2018 at 16:31:56 UTC, Stefan Koch wrote: On Thursday, 15 March 2018 at 15:28:16 UTC, Miguel L wrote: Why does std.math.signbit only work for floating point types? Is there an analogue function for integer types?

Re: signbit question

2018-03-15 Thread Miguel L via Digitalmars-d-learn
On Thursday, 15 March 2018 at 17:31:38 UTC, rumbu wrote: On Thursday, 15 March 2018 at 17:18:08 UTC, Miguel L wrote: On Thursday, 15 March 2018 at 16:31:56 UTC, Stefan Koch wrote: On Thursday, 15 March 2018 at 15:28:16 UTC, Miguel L wrote: [...] integers don't have a sign-bit. since they

Re: signbit question

2018-03-15 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 15 March 2018 at 15:28:16 UTC, Miguel L wrote: Why does std.math.signbit only work for floating point types? Integers are stored in an entirely different way, twos-complement instead of having a sign bit. You probably shouldn't be using the sign bit function at all, it is for

Re: signbit question

2018-03-15 Thread Stefan Koch via Digitalmars-d-learn
On Thursday, 15 March 2018 at 15:28:16 UTC, Miguel L wrote: Why does std.math.signbit only work for floating point types? Is there an analogue function for integer types? what is the best way to compare the sign of a float with the sign of an integer? Thanks in advance integers don't have a

Re: signbit question

2018-03-15 Thread Miguel L via Digitalmars-d-learn
On Thursday, 15 March 2018 at 16:31:56 UTC, Stefan Koch wrote: On Thursday, 15 March 2018 at 15:28:16 UTC, Miguel L wrote: Why does std.math.signbit only work for floating point types? Is there an analogue function for integer types? what is the best way to compare the sign of a float with the

Re: signbit question

2018-03-15 Thread Dlang User via Digitalmars-d-learn
On 3/15/2018 12:39 PM, Miguel L wrote: On Thursday, 15 March 2018 at 17:31:38 UTC, rumbu wrote: On Thursday, 15 March 2018 at 17:18:08 UTC, Miguel L wrote: On Thursday, 15 March 2018 at 16:31:56 UTC, Stefan Koch wrote: On Thursday, 15 March 2018 at 15:28:16 UTC, Miguel L wrote: [...]

Allocator Part of Type

2018-03-15 Thread jmh530 via Digitalmars-d-learn
I recall some talk Andrei did where he said it was a bad idea to make the allocator part of the type. However, the container library in dlang-community(says it is backed with std.experimental.allocator) contains allocator as part of the type. Automem does too. Honestly, I would think you

Re: Error: cannot implicitly convert expression this.aa of type inout(string[string]) to string[string]

2018-03-15 Thread Simen Kjærås via Digitalmars-d-learn
On Thursday, 15 March 2018 at 15:41:54 UTC, Robert-D wrote: Why something like this doesn't compile (with or without the cast on bb.dup)? struct S { string[string] aa; S dup() inout pure { return S(cast(string[string]) aa.dup); } } struct SS { S[] bb; SS dup()

Re: What is the "right" way to create a generic type getter (and setter) ?

2018-03-15 Thread Cym13 via Digitalmars-d-learn
On Thursday, 15 March 2018 at 15:48:52 UTC, James Blachly wrote: On Wednesday, 14 March 2018 at 22:58:25 UTC, ag0aep6g wrote: You can probably get around the (manually maintained?) `FIELDS` array with `.tupleof` or something similar: static foreach (i, f; S.tupleof) { case

Re: Networking library

2018-03-15 Thread Dmitry Olshansky via Digitalmars-d-learn
On Thursday, 15 March 2018 at 00:06:49 UTC, Cecil Ward wrote: Can anyone point me in the direction of a library that provides very very lightweight (minimum overhead) asynchronous i/o routines for - shopping list 1. sending and receiving IPv4 / IPv6 packets, 2. sending receiving ICMP and 3,

Re: Allocator Part of Type

2018-03-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/15/18 3:36 PM, jmh530 wrote: I recall some talk Andrei did where he said it was a bad idea to make the allocator part of the type.  However, the container library in dlang-community(says it is backed with std.experimental.allocator) contains allocator as part of the type. Automem does

Re: Readonly field for class type

2018-03-15 Thread Ali Çehreli via Digitalmars-d-learn
On 03/15/2018 03:16 AM, Andrey wrote: Hello, is there way to declare read only field for class type with ability to call inner non constant methods? i.e.: class A {     int value = 12;     void updateValue() {     value = 13;     } } class B {     const A a;     this() {     a = new

Re: Allocator Part of Type

2018-03-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/15/18 6:30 PM, jmh530 wrote: On Thursday, 15 March 2018 at 21:43:41 UTC, Steven Schveighoffer wrote: [snip] I don't know if I've heard Andrei talk about that, but I definitely have made it part of the type for types that need to allocate. The only other possibility is to accept and use

Re: Function argument that is a pointer to memory which the function is not allowed to modify, as in C const

2018-03-15 Thread Cecil Ward via Digitalmars-d-learn
On Wednesday, 14 March 2018 at 22:23:47 UTC, Cecil Ward wrote: say in C I have a function with a pointer argument foo( const sometype_t * p ) [...] That's the secret - I didn't know about the const (T) * thing - I would never have discovered that ! Many thanks, the missing piece to the

Re: Allocator Part of Type

2018-03-15 Thread jmh530 via Digitalmars-d-learn
On Thursday, 15 March 2018 at 21:43:41 UTC, Steven Schveighoffer wrote: [snip] I don't know if I've heard Andrei talk about that, but I definitely have made it part of the type for types that need to allocate. The only other possibility is to accept and use an Allocator object (i.e. the

Re: Efficient way to pass struct as parameter

2018-03-15 Thread Cecil Ward via Digitalmars-d-learn
On Thursday, 15 March 2018 at 23:14:14 UTC, Cecil Ward wrote: On Tuesday, 2 January 2018 at 18:21:13 UTC, Tim Hsu wrote: [...] U or even 'I' will be delighted to take a look.

Re: signbit question

2018-03-15 Thread ketmar via Digitalmars-d-learn
Miguel L wrote: as the calculations on f guarantee it cannot be 0 at all. than `f` will become zero very soon. something that "cannot happen" is the most probable thing to happen. otherwise, LGTM.

Re: Efficient way to pass struct as parameter

2018-03-15 Thread Cecil Ward via Digitalmars-d-learn
On Tuesday, 2 January 2018 at 18:21:13 UTC, Tim Hsu wrote: I am creating Vector3 structure. I use struct to avoid GC. However, struct will be copied when passed as parameter to function struct Ray { Vector3f origin; Vector3f dir; @nogc @system this(Vector3f *origin, Vector3f

Re: Efficient way to pass struct as parameter

2018-03-15 Thread Cecil Ward via Digitalmars-d-learn
On Thursday, 15 March 2018 at 23:15:47 UTC, Cecil Ward wrote: On Thursday, 15 March 2018 at 23:14:14 UTC, Cecil Ward wrote: On Tuesday, 2 January 2018 at 18:21:13 UTC, Tim Hsu wrote: [...] U or even 'I' will be delighted to take a look. Also link time optimisation and whole program

Re: signbit question

2018-03-15 Thread Seb via Digitalmars-d-learn
On Thursday, 15 March 2018 at 15:28:16 UTC, Miguel L wrote: Why does std.math.signbit only work for floating point types? Is there an analogue function for integer types? I guess because for integers you don't need to distinguish between +0.0 and -0.0, so no one bother until now to add it to

Readonly field for class type

2018-03-15 Thread Andrey via Digitalmars-d-learn
Hello, is there way to declare read only field for class type with ability to call inner non constant methods? i.e.: class A { int value = 12; void updateValue() { value = 13; } } class B { const A a; this() { a = new A(); a.updateValue(); //

Re: how to make private class member private

2018-03-15 Thread Nathan S. via Digitalmars-d-learn
On Tuesday, 13 March 2018 at 22:56:31 UTC, Jonathan M Davis wrote: The downside is that it increases the number of symbols which the program has to deal with when linking against a shared library, which can have some negative effects. - Jonathan M Davis If I understand correctly it's also

Re: Readonly field for class type

2018-03-15 Thread Mike Parker via Digitalmars-d-learn
On Thursday, 15 March 2018 at 10:55:16 UTC, Mike Parker wrote: class A { private int _value = 12; int value() @property { return _value; } void updateValue() { value = 13; } } ... auto a = new A(); writeln(a.value); a.updateValue(); writeln(a.value); Sorry. I overlooked that

Re: Readonly field for class type

2018-03-15 Thread Mike Parker via Digitalmars-d-learn
On Thursday, 15 March 2018 at 10:16:49 UTC, Andrey wrote: Hello, is there way to declare read only field for class type with ability to call inner non constant methods? i.e.: class A { int value = 12; void updateValue() { value = 13; } } class B { const A a;

Re: Readonly field for class type

2018-03-15 Thread Simen Kjærås via Digitalmars-d-learn
On Thursday, 15 March 2018 at 10:16:49 UTC, Andrey wrote: Hello, is there way to declare read only field for class type with ability to call inner non constant methods? i.e.: class A { int value = 12; void updateValue() { value = 13; } } class B { const A a;

Re: Error: cannot implicitly convert expression this.aa of type inout(string[string]) to string[string]

2018-03-15 Thread Simen Kjærås via Digitalmars-d-learn
On Thursday, 15 March 2018 at 11:18:48 UTC, Robert-D wrote: struct S { string[string] aa; S dup() inout pure { return S(aa); } } void main() { auto s = S(["": ""]); s.dup(); } Result: Error: cannot implicitly convert expression this.aa of type

Error: cannot implicitly convert expression this.aa of type inout(string[string]) to string[string]

2018-03-15 Thread Robert-D via Digitalmars-d-learn
struct S { string[string] aa; S dup() inout pure { return S(aa); } } void main() { auto s = S(["": ""]); s.dup(); } Result: Error: cannot implicitly convert expression this.aa of type inout(string[string]) to string[string] I need help with the above program.

Re: Error: cannot implicitly convert expression this.aa of type inout(string[string]) to string[string]

2018-03-15 Thread Robert-D via Digitalmars-d-learn
On Thursday, 15 March 2018 at 11:33:49 UTC, Simen Kjærås wrote: On Thursday, 15 March 2018 at 11:18:48 UTC, Robert-D wrote: [...] This is where things go wrong: [...] 'inout' means that this function can keep the const, immutable or mutable status of the type on which the function is

Re: Error: cannot implicitly convert expression this.aa of type inout(string[string]) to string[string]

2018-03-15 Thread Simen Kjærås via Digitalmars-d-learn
On Thursday, 15 March 2018 at 12:00:08 UTC, Robert-D wrote: I want the function to create a mutable copy from a const or a imutable Like this: void main() { const S s = S(["": ""]); S b = s.dup(); } How can i do that? In that case, the problem is that you also have to .dup the aa:

Re: Readonly field for class type

2018-03-15 Thread Seb via Digitalmars-d-learn
On Thursday, 15 March 2018 at 13:44:20 UTC, Seb wrote: On Thursday, 15 March 2018 at 10:57:52 UTC, Mike Parker wrote: On Thursday, 15 March 2018 at 10:55:16 UTC, Mike Parker wrote: class A { private int _value = 12; int value() @property { return _value; } void updateValue() {

Re: Readonly field for class type

2018-03-15 Thread Seb via Digitalmars-d-learn
On Thursday, 15 March 2018 at 13:44:20 UTC, Seb wrote: On Thursday, 15 March 2018 at 10:57:52 UTC, Mike Parker wrote: On Thursday, 15 March 2018 at 10:55:16 UTC, Mike Parker wrote: [...] Sorry. I overlooked that B.a is const. It still works, the `value` just needs to be `const` (or

Re: Readonly field for class type

2018-03-15 Thread Seb via Digitalmars-d-learn
On Thursday, 15 March 2018 at 10:57:52 UTC, Mike Parker wrote: On Thursday, 15 March 2018 at 10:55:16 UTC, Mike Parker wrote: class A { private int _value = 12; int value() @property { return _value; } void updateValue() { value = 13; } } ... auto a = new A(); writeln(a.value);

signbit question

2018-03-15 Thread Miguel L via Digitalmars-d-learn
Why does std.math.signbit only work for floating point types? Is there an analogue function for integer types? what is the best way to compare the sign of a float with the sign of an integer? Thanks in advance