Re: variable template question

2018-01-14 Thread ag0aep6g via Digitalmars-d-learn
On Sunday, 14 January 2018 at 16:23:18 UTC, kdevel wrote: Why does this compile while both of the commented lines give a compile error. The code boils down to this: struct decimal32 { this(int x) {} } immutable decimal32 c = 3; /* works */ void main () { immutable decimal32 i =

Re: union/toString: crash/segfault: What's happening here?

2018-01-11 Thread ag0aep6g via Digitalmars-d-learn
On 01/12/2018 02:45 AM, Nicholas Wilson wrote: because you don't initialise `s` in    string toString ()    {   string s;   return s;    } so it defaults to `string s = null;` thus giving a segfault. try `string s = "";` instead. A null string is a perfectly fine empty string.

Re: new int[]

2018-01-10 Thread ag0aep6g via Digitalmars-d-learn
On 01/10/2018 11:35 PM, Luís Marques wrote: Due to compatibility with some C code, I basically need to do this:     struct Wrapper     {     int[] x;     }     void main()     {     void* ctxptr = new Wrapper([1, 2, 3]);     auto context = cast(Wrapper*) ctxptr;    

Re: TemplateOf behavior

2018-01-06 Thread ag0aep6g via Digitalmars-d-learn
On Saturday, 6 January 2018 at 19:58:10 UTC, Alex wrote: Given the code above, why the static assert inside the mixing template constructor yields false, while the others yield true? Let's resolve the mixin and write out the `T` template in the verbose form. It looks like this then:

Re: How do you safely deal with range.front?

2017-12-31 Thread ag0aep6g via Digitalmars-d-learn
On 12/31/2017 02:14 PM, aliak wrote: Also, is going out of array bounds well defined behavior in D even with boundscheck off? No. Without the checks you get undefined behavior. I.e., `-boundscheck=off` defeats the `@safe` attribute. For that reason, I'd advise against ever using it.

Re: Tail-constness of class parameters

2017-12-25 Thread ag0aep6g via Digitalmars-d-learn
On Monday, 25 December 2017 at 14:49:11 UTC, Nordlöw wrote: 1. Is there a way to express tail-constness on the parameters https://dlang.org/phobos/std_typecons.html#Rebindable

Re: Function signature testing with is expression.

2017-12-17 Thread ag0aep6g via Digitalmars-d-learn
On Sunday, 17 December 2017 at 14:44:15 UTC, Alexandru Ermicioi wrote: Suppose: struct F { static void foo(T)(T i, int o) {} } enum bool check(T) = is(F.foo!T == void function(Z, int), Z); enum correct = check!int; Upon running it will return false, though, by logic is

Re: Overloading float operators

2017-12-11 Thread ag0aep6g via Digitalmars-d-learn
On 12/11/2017 08:28 PM, rumbu wrote: Is there any way to overload specific floating point operators? https://dlang.org/spec/expression.html#floating-point-comparisons Those don't seem to work anymore. At least since 2.073, dmd rejects them and says to use std.math.isNaN instead. Looks like

Re: package modules and how to generate a shared library plus .di file (I)

2017-12-07 Thread ag0aep6g via Digitalmars-d-learn
On 12/07/2017 06:53 PM, kdevel wrote: Does that mean, that though the code is bundled in one library (libmymod.a) for the prototypes one has as many .di files as there were source files? yes

Re: User defined type and foreach

2017-11-16 Thread ag0aep6g via Digitalmars-d-learn
On 11/16/2017 09:03 AM, Tony wrote: However, when I use the class with foreach, the opindex gets called to create a dynamic array, rather than use the empty(),front(),popFront() routines. I would prefer it use the three methods, rather than create a dynamic array.

Re: Alias this and inheritance

2017-11-05 Thread ag0aep6g via Digitalmars-d-learn
On Sunday, 5 November 2017 at 07:07:43 UTC, Aurelien Fredouelle wrote: struct S { } class A { S s; alias s this; } class B : A { } void main() { A asA = new B; B asB = cast(B)asA; } I would expect the last line to successfully cast the B instance I created back into type B, however

Re: initializing a static array

2017-10-10 Thread ag0aep6g via Digitalmars-d-learn
On 10/10/2017 03:36 PM, Simon Bürger wrote: I have a static array inside a struct which I would like to be initialized to all-zero like so   struct Foo(size_t n)   {     double[n] bar = ... all zeroes ...   } (note that the default-initializer of double is nan, and not zero) I tried  

Re: Implementing swap for user-defined swaps

2017-10-07 Thread ag0aep6g via Digitalmars-d-learn
On 10/07/2017 07:55 PM, Balagopal Komarath wrote:   I was implement my own range type that forwards all accesses to another range. I tried to write a `swap` function so that sort etc. could be called on my range. However, I cannot get `hasSwappableElements!ARange` to evaluate to true. But,

Re: mtaching types with static if

2017-10-01 Thread ag0aep6g via Digitalmars-d-learn
On 10/01/2017 09:03 AM, Nicholas Wilson wrote: struct ArrayAccesssor(alias ptr, alias len) {} char * p; size_t len; ArrayAccesssor!(p,len) aa; template helper(Fields...) {     static if (Fields.length == 0)     enum helper = "";     else static if (is(typeof(Fields[0]) :

Re: Why isn't there more if(__ctfe) in std.math ?

2017-09-23 Thread ag0aep6g via Digitalmars-d-learn
On 09/23/2017 11:46 PM, user1234 wrote: "if (__ctfe) {}" is a test happening at runtime. Both the if and the else branches got compiled, this implies: - more code to cache - slower code just to allow CTFE. __ctfe is a constant, though. Any half-decent optimizer will throw away the path

Re: Getting the size of a type tuple

2017-09-21 Thread ag0aep6g via Digitalmars-d-learn
On 09/21/2017 09:59 PM, H. S. Teoh wrote: On Thu, Sep 21, 2017 at 09:49:14PM +0200, ag0aep6g via Digitalmars-d-learn wrote: [...] 3) Declaring a packed struct in a function literal that gets immediately called: enum size_so_very_clever(Types ...) = () { struct S { align(1) Types

Re: Getting the size of a type tuple

2017-09-21 Thread ag0aep6g via Digitalmars-d-learn
On 09/21/2017 08:44 PM, David Zhang wrote: Given the function F, where: F(Args...)(Args args) { ... } How can I statically determine the size of the argument list in bytes? Preferably, I would like a one-liner. However, std.algorithm doesn't seem to support tuples, or `Args.each!(T =>

Re: cannot access frame of function

2017-09-18 Thread ag0aep6g via Digitalmars-d-learn
On 09/18/2017 08:25 PM, user1234 wrote: On Monday, 18 September 2017 at 14:45:25 UTC, Alex wrote: [...] import std.algorithm.iteration : sum, cumulativeFold; void main() { double[5] a; [...]>> auto asum = a[].sum; [...] asum is a lazy range and the error comes from this. asum is

Re: How to use encode and decode of std.utf

2017-09-09 Thread ag0aep6g via Digitalmars-d-learn
On 09/09/2017 11:54 PM, solidstate1991 wrote: There's not much deep documentation about the functions, and I'm interested if it can decode into UTF16 from UTF8. toUTF16 can transcode from UTF-8. As linked there, byUTF!wchar does the same but lazily. import std.utf; string s8 =

Re: Finding chars in strings

2017-09-05 Thread ag0aep6g via Digitalmars-d-learn
On 09/05/2017 05:54 PM, Per Nordlöw wrote: Follow up question: If a character literal has type char, can we always assume it's an ASCII character? Strictly speaking, this is a character literal of type char: '\xC3'. It's clearly above 0x7F, and not an ASCII character. So, no. But if it's an

Re: Finding chars in strings

2017-09-05 Thread ag0aep6g via Digitalmars-d-learn
On 09/05/2017 05:43 PM, Per Nordlöw wrote: If a character literal has type char, always below 128, can we always search for it's first byte offset in a string without decoding the string to a range of dchars? Yes. You can search for ASCII characters (< 128) without decoding. The values in

Re: Simplest multithreading example

2017-09-05 Thread ag0aep6g via Digitalmars-d-learn
On 09/05/2017 03:15 AM, Brian wrote: Thanks very much for your help, I finally had time to try your suggestions. The initial example you showed does indeed have the same problem of not iterating over all values : double [] hugeCalc(int i){ // Code that takes a long time import

Re: passing member.member alias to mixin template

2017-09-03 Thread ag0aep6g via Digitalmars-d-learn
On 09/03/2017 08:54 PM, Eric_DD wrote: *** This works: struct Array { void foo() { writeln("foo"); } } mixin template arrayOperations(arrays...) { void foo() { foreach(ref a; arrays) a.foo(); } } class Thing { Array data1; Array data2; mixin

Re: string to character code hex string

2017-09-03 Thread ag0aep6g via Digitalmars-d-learn
On 09/03/2017 01:39 AM, Ali Çehreli wrote: Ok, I see that I made a mistake but I still don't think the conversion is one way. If we can convert byte-by-byte, we should be able to convert back byte-by-byte, right? You weren't converting byte-by-byte. You were only converting the significant

Re: templated type reduction

2017-09-02 Thread ag0aep6g via Digitalmars-d-learn
On 09/02/2017 11:07 PM, EntangledQuanta wrote: struct X(T) { string type = T.stringof; T t; } [...] void* x = new X!int; (passed around the program) switch(x.type) { case "int" : break; } which is invalid yet perfectly valid! Is there any way to make this work legitly in D?

Re: Simplest multithreading example

2017-09-01 Thread ag0aep6g via Digitalmars-d-learn
On 09/01/2017 07:27 AM, Brian wrote: double [] hugeCalc(int i){ // Code that takes a long time } so if I do double[][int] _hugeCalcCache; foreach(i ; I) _hugeCalcCache[i] = hugeCalc(i); of course the required time is I.length * (a long time), so I wanted to shorten this by

Re: xml utf-8 encoding error

2017-08-29 Thread ag0aep6g via Digitalmars-d-learn
On 08/29/2017 05:41 PM, Kagamin wrote: On Tuesday, 29 August 2017 at 04:41:34 UTC, graw-prog wrote: < Content-Type: text/xml; charset="utf-8" Should be Content-Type: text/xml; charset=utf-8 HTTP allows a quoted string there. https://tools.ietf.org/html/rfc7231#section-3.1.1.1

Re: Confusion over enforce and assert - both are compiled out in release mode

2017-08-27 Thread ag0aep6g via Digitalmars-d-learn
On 08/27/2017 12:02 PM, Andrew Chapman wrote: However, I am finding that BOTH enforce and assert are compiled out by dmd and ldc in release mode. Is there a standard way of doing what enforce does inside an "in" contract block that will work in release mode? I'm guessing I should write my

Re: No CTFE of function

2017-08-26 Thread ag0aep6g via Digitalmars-d-learn
On Saturday, 26 August 2017 at 16:52:36 UTC, Cecil Ward wrote: Any ideas as to why GDC might just refuse to do CTFE on compile-time-known inputs in a truly pure situation? That's not how CTFE works. CTFE only kicks in when the *result* is required at compile time. For example, when you assign

Re: ore.exception.RangeError

2017-08-22 Thread ag0aep6g via Digitalmars-d-learn
On 08/23/2017 07:45 AM, Vino.B wrote: Execution : rdmd Summary.d - Not working rdmd Summary.d test - Working Program: void main (string[] args) { if(args.length != 2 ) writefln("Unknown operation: %s", args[1]); } When args.length == 1, then the one element is args[0], not args[1].

Re: How to specify a template that uses unqualified type, like any normal function

2017-08-14 Thread ag0aep6g via Digitalmars-d-learn
On 08/15/2017 12:14 AM, Dominikus Dittes Scherkl wrote: T foo(T)(T n) { static if(!is(Unqual!T == T)) return foo!(Unqual!T)(n); else { // normal implementation } } So it's basically 2 lines of overhead. That's acceptable. The check for isImplicitlyConvertible is not

Re: delegates/lambas do not pick up calling convention

2017-08-10 Thread ag0aep6g via Digitalmars-d-learn
On 08/10/2017 01:52 AM, Johnson Jones wrote: I've tried import gdk.Threads; alias DD = static extern(C) int delegate(void*); auto x = (void*)

Re: Express "Class argument may not be null" ?

2017-08-08 Thread ag0aep6g via Digitalmars-d-learn
On 08/08/2017 08:34 PM, Johan Engelen wrote: How would you express the function interface intent that a reference to a class may not be null? For a function "void foo(Klass)", calling "foo(null)" is valid. How do I express that that is invalid? (let's leave erroring with a compile error

Re: gtkD load images

2017-08-05 Thread ag0aep6g via Digitalmars-d-learn
On 08/05/2017 10:30 PM, Mike Wey wrote: On 05-08-17 15:23, Johnson Jones wrote: On Saturday, 5 August 2017 at 12:51:13 UTC, Mike Wey wrote: [...] There are two issues here, you need to properly escape the slash: "C:a.jpg". [...] ``` Pixbuf p = new Pixbuf(r"C:\\a.jpg"); ``` Thanks. Why

Re: Getting enum from value

2017-08-05 Thread ag0aep6g via Digitalmars-d-learn
On 08/05/2017 07:05 PM, ag0aep6g wrote: E enumFromValue(E)(string s) The type of `s` should probably be a template parameter as well.

Re: Getting enum from value

2017-08-05 Thread ag0aep6g via Digitalmars-d-learn
On 08/05/2017 05:33 PM, Matthew Remmel wrote: I feel like I'm missing something, but there has to be an easier way to convert a value into an enum than switching over every possible value: i.e enum Capitals { Indiana = "Indianapolis", Illinois = "Chicago", Ohio = "Columbus" }

Re: Using lazy code to process large files

2017-08-02 Thread ag0aep6g via Digitalmars-d-learn
On 08/02/2017 08:28 PM, kdevel wrote: It's perfectly okay to put any value a octet can take into an octet. I did not claim that the data in the string memory is syntactically valid UTF-8. Read the comment in line 9 of my post of 15:02:22. You're claiming that the data is in UTF-8 when you use

Re: Compile Time versus Run Time

2017-07-31 Thread ag0aep6g via Digitalmars-d-learn
On 07/31/2017 05:43 PM, Martin Tschierschke wrote: As a rookie in D programming I try to understand the power of templated functions with compile time parameters. With DMD 2.074 a compile time format (auto output = format!("Print this %s")(var);) was introduced, now we all know that very many

Re: Taking the address of an eponymous template

2017-07-31 Thread ag0aep6g via Digitalmars-d-learn
On 07/31/2017 01:59 PM, Arafel wrote: On 07/31/2017 12:14 PM, ag0aep6g wrote: [...] > You'd have to instantiate the inner template, too. Something like > `!"a".baz!()`, but that doesn't work. I don't know how you could > make it work. > I tried this as well, and couldn't make it work

Re: Taking the address of an eponymous template

2017-07-31 Thread ag0aep6g via Digitalmars-d-learn
On 07/31/2017 11:44 AM, Arafel wrote: ``` class C { [...] template baz(string S) { void baz()() { } } } void main() { [...] void delegate() aBaz = !"a"; // This doesn't compile. } ``` If I try !"a".baz it doesn't work either (I get a different error

Re: Bug or not? Statics inside blocks

2017-07-28 Thread ag0aep6g via Digitalmars-d-learn
On 07/29/2017 03:54 AM, Cecil Ward wrote: Is it my bug, or a compiler bug? (name clash at link-time?): void main() { { immutable static dstring str1 = "a"; } { immutable static dstring str1 = "b"; } }

Re: traits compiles does not work for symbols from other modules

2017-07-25 Thread ag0aep6g via Digitalmars-d-learn
On 07/24/2017 11:40 PM, Andre Pany wrote: m1.d - module m1; import m2; class Foo { int foo; } void main() { static assert(__traits(compiles, m1.Foo.foo)); static assert(__traits(compiles, m2.Bar.bar)); } m2.d --- module m2; class Bar { int

Re: criando modulos em D para classe pessoa[AJUDA]

2017-07-24 Thread ag0aep6g via Digitalmars-d-learn
On 07/24/2017 09:45 PM, dark777 wrote: principal.d(18): Error: octal literals 01023040 are no longer supported, use std.conv.octal!1023040 instead Failed: ["dmd", "-v", "-o-", "principal.d", "-I."] [...] https://pastebin.com/CYinHWyQ From there: e = new Endereco();

Re: Appending static arrays

2017-07-17 Thread ag0aep6g via Digitalmars-d-learn
On 07/17/2017 08:35 PM, Nordlöw wrote: Thanks, but I'm talking about the variadic case where the number of input arguments are unknown (>= 2) where the function header looks something like import std.traits : allSatisfy, isStaticArray; auto append(R, Args...)(auto ref Args args) if

Re: Appending static arrays

2017-07-17 Thread ag0aep6g via Digitalmars-d-learn
On 07/17/2017 07:38 PM, Nordlöw wrote: I'm want to define a specialization of `append()` that takes only static arrays as inputs and returns a static array being the sum of the lengths of the inputs. Have anybody already implemented this? If not, I'm specifically interested in how to most

Re: Auto-decoding

2017-07-15 Thread ag0aep6g via Digitalmars-d-learn
On 07/15/2017 08:14 PM, aberba wrote: So what is the current plan? :) As far as I'm aware, there's no concrete plan to change anything. We just gotta deal with auto-decoding for the time being.

Re: Auto-decoding

2017-07-14 Thread ag0aep6g via Digitalmars-d-learn
On 07/15/2017 06:21 AM, bauss wrote: I understand what it is and how it works, but I don't understand anything of how it solves any problems? Could someone give an example of when auto-decoding actually is useful in contrast to not using it? 1) Drop two elements from "Bär". With

Re: sorting a string

2017-07-14 Thread ag0aep6g via Digitalmars-d-learn
On 07/15/2017 04:33 AM, Namal wrote: Why does it have to be char[]? auto bytes = line.representation.dup; bytes.sort; string result = bytes.assumeUTF; works too. That's a compiler bug. The code should not compile, because now you can mutate `result`'s elements through `bytes`. But

Re: sorting a string

2017-07-14 Thread ag0aep6g via Digitalmars-d-learn
On 07/14/2017 09:50 PM, Anton Fediushin wrote: But why? This should be true for `char[]`, isn't it? - if ((ss == SwapStrategy.unstable && (hasSwappableElements!Range || hasAssignableElements!Range) || ss != SwapStrategy.unstable && hasAssignableElements!Range) && isRandomAccessRange!Range

Re: WTF is going on! Corrupt value that is never assigned

2017-07-13 Thread ag0aep6g via Digitalmars-d-learn
On 07/13/2017 08:22 PM, FoxyBrown wrote: res = EnumServicesStatusExW(schSCManager, SC_ENUM_TYPE.SC_ENUM_PROCESS_INFO, servicesType, SERVICE_STATE_ALL, cast(ubyte*)buf, 5, , , , cast(const(char)*)null); The cast to `char*` here looks odd. The 'W' suffix in the function name

Re: pure factory function vs immutable(Foo)**

2017-07-11 Thread ag0aep6g via Digitalmars-d-learn
On 07/10/2017 04:57 PM, ag0aep6g wrote: alias T = int; T** f(const T** input) pure { T** output; return output; } void main() { T i; T* p = immutable T** r = f(); } [...] Now change `T` to `alias T = immutable int;`. The program gets rejected. The error

Re: Why no offsetof for static struct?

2017-07-11 Thread ag0aep6g via Digitalmars-d-learn
On 07/10/2017 11:14 PM, FoxyBrown wrote: auto GetStaticAddress(T)() { mixin("auto p = cast(T*)"~__traits(allMembers, T)[0]~";"); return p; } Returns the address of a struct's static members. No, it returns the address of T's first member. It's pretty obvious, the compiler seems to

Re: iterate over variadic

2017-07-10 Thread ag0aep6g via Digitalmars-d-learn
On 07/10/2017 08:31 PM, H. S. Teoh via Digitalmars-d-learn wrote: if (i % 2) { // even odd ... // do something with arg } else { // odd even

Re: pure factory function vs immutable(Foo)**

2017-07-10 Thread ag0aep6g via Digitalmars-d-learn
On 07/10/2017 05:42 PM, drug wrote: 10.07.2017 17:57, ag0aep6g пишет: [...] The error message is: "cannot implicitly convert expression (f(& p)) of type immutable(int)** to immutable(int**)". [...] I'm not sure I understand, but ``` immutable (T)** r = f(); ``` compiles. So compiler

pure factory function vs immutable(Foo)**

2017-07-10 Thread ag0aep6g via Digitalmars-d-learn
I feel like I must be missing something here. This works: alias T = int; T** f(const T** input) pure { T** output; return output; } void main() { T i; T* p = immutable T** r = f(); } `f` is `pure`, its parameter is const, and its return type has mutable

Re: Lazy range, extract only Nth element, set range size constraint?

2017-07-09 Thread ag0aep6g via Digitalmars-d-learn
On 07/09/2017 11:51 PM, biocyberman wrote: Following is the code for a more generalized Fibonacci range. Questions: 1. How do I get only the value of the Nth (i.e. N = 25) element in an idiomatic way? As you've only got an input range, you have to popFront the 24 values that come before.

Re: The Nullity Of strings and Its Meaning

2017-07-09 Thread ag0aep6g via Digitalmars-d-learn
On Sunday, 9 July 2017 at 18:55:51 UTC, kdevel wrote: Yes, it can obviously return one of the two representations of the empty D string. The two being null and ""? There are more than those. One for every possible .ptr value.

Re: The Nullity Of strings and Its Meaning

2017-07-09 Thread ag0aep6g via Digitalmars-d-learn
On 07/09/2017 03:51 PM, kdevel wrote: On Sunday, 9 July 2017 at 10:32:23 UTC, ag0aep6g wrote: [...] As mentioned in the subject my posting is about the state of affairs wrt. the (non-)nullity of strings. In C/C++ once a char * variable became non-NULL 'it' never loses this property. In D this

Re: The Nullity Of strings and Its Meaning

2017-07-09 Thread ag0aep6g via Digitalmars-d-learn
On 07/09/2017 01:12 AM, kdevel wrote: On Saturday, 8 July 2017 at 18:39:47 UTC, ag0aep6g wrote: On 07/08/2017 07:16 PM, kdevel wrote: null is one specific array. It happens to be empty, but that doesn't really matter. `foo is null` compares with the null array. It doesn't check for

Re: The Nullity Of strings and Its Meaning

2017-07-08 Thread ag0aep6g via Digitalmars-d-learn
On 07/08/2017 07:16 PM, kdevel wrote: The assertion in line 6 fails. This failure gave rise to a more general investigation on strings. After some research I found that one "cannot implicitly convert expression (s) of type string to bool" as in [...] Nonetheless in certain boolean contexts

Re: Double value is rounded to unexpected value: 2.5 -> 2 instead of 3

2017-07-07 Thread ag0aep6g via Digitalmars-d-learn
On 07/07/2017 08:29 PM, alex_ca wrote: I'm having trouble understanding why in some cases a double value will be rounded up and other times down, for the same code. Here's a snippet with code I tried to debug: int getNumberOfStitchesForRowLength(double rowLength) { writeln("input

Re: Address of a lambda

2017-07-07 Thread ag0aep6g via Digitalmars-d-learn
On 07/07/2017 07:33 PM, FoxyBrown wrote: In gtk, we routinly have to use delegates for callbacks. But the methods that accept these delegates want the address of the delegate, I don't think that's true. As far as I can tell, this is the signature of addOnDelete [1]: gulong

Re: [BEGINNER] reccurence! and sequence!

2017-07-06 Thread ag0aep6g via Digitalmars-d-learn
On 07/06/2017 02:21 AM, Ali Çehreli wrote: On 07/05/2017 04:38 PM, helxi wrote: [...] >> recurrence!((a, n) => a[0] + 1)(1).take(10).writeln; > 1. In the last example of reccurence, what does n in (a,n) refer to? n is "the index of the current value". Each time the lambda is called,

Re: ReadProcessMemory + address from ollydbg

2017-06-30 Thread ag0aep6g via Digitalmars-d-learn
On 07/01/2017 02:30 AM, bauss wrote: On Saturday, 1 July 2017 at 00:23:36 UTC, ag0aep6g wrote: On 07/01/2017 01:41 AM, bauss wrote: [...] if (!ReadProcessMemory(process, cast(PCVOID)address, cast(PVOID), The second cast still looks suspicious. PVOID is void*, right? Then any

Re: ReadProcessMemory + address from ollydbg

2017-06-30 Thread ag0aep6g via Digitalmars-d-learn
On 07/01/2017 01:41 AM, bauss wrote: string ReadWinString(HANDLE process, DWORD address, size_t stringSize, string defaultValue = "") { if (!process || !address) { return defaultValue; } SIZE_T bytesRead; char[1024] data; if (!ReadProcessMemory(process,

Re: ReadProcessMemory + address from ollydbg

2017-06-30 Thread ag0aep6g via Digitalmars-d-learn
On Friday, 30 June 2017 at 20:14:15 UTC, bauss wrote: This is my definition: BOOL ReadProcessMemory(HANDLE hProcess, LPCVOID lpBaseAddress, LPVOID lpBuffer, SIZE_T nSize, SIZE_T *lpNumberOfBytesRead); And I'm reading it like this: if (!ReadProcessMemory(process, cast(PCVOID)address,

Re: isImplictlyConvertible for Variadic Templates

2017-06-26 Thread ag0aep6g via Digitalmars-d-learn
On 06/27/2017 02:59 AM, rpeio wrote: struct Foo(V) { this(Vs...)(Vs values) if (eachIsImplictlyConvertible!(T, Vs)) { // do stuff } } This can be accomplished off the top of my head by taking the code from std.traits for "isImplicitlyConvertible" and making the following

Re: [BEGINNER] reccurence! and sequence!

2017-06-26 Thread ag0aep6g via Digitalmars-d-learn
On 06/26/2017 11:51 AM, helxi wrote: auto tri = sequence!((a,n) => n*(n+1)/2)(); /** okay, it's a triangular number array * I understand n is the index number, the nth term * However where does this 'a' go? */ `a` is a tuple of the run-time arguments you pass to `sequence`. In this example,

Re: Immutable

2017-06-23 Thread ag0aep6g via Digitalmars-d-learn
On 06/23/2017 04:29 PM, Adam D. Ruppe wrote: try `new immutable AppendChatCommand` instead of just `new`. If it complains that it cannot call the mutable constructor, go to the class definition and add `pure` to the constructor. Should take care of that error. With a `pure` constructor,

Re: Dealing with the interior pointers bug

2017-06-22 Thread ag0aep6g via Digitalmars-d-learn
On 06/22/2017 08:38 PM, Boris-Barboris wrote: Casts are part of the type system. Yes, D type system allows invalid operations. It's not the compiler's fault, it's type system's fault. unittest { immutable int a = 4; int* b = cast(int*) *b = 5; assert(*() == 5);

Re: Dealing with the interior pointers bug

2017-06-22 Thread ag0aep6g via Digitalmars-d-learn
On 06/22/2017 12:34 PM, Boris-Barboris wrote: Everything the language allows to compile is allowed by it's type system, or is a bug in the compiler. No. D is not supposed to be completely verifiable by the compiler. For example, the type system guarantees that immutable data never changes.

Re: Dealing with the interior pointers bug

2017-06-21 Thread ag0aep6g via Digitalmars-d-learn
On 06/21/2017 07:23 PM, H. S. Teoh via Digitalmars-d-learn wrote: Being a systems programming language means you should be able to do things outside the type system (in @system code, of course, not in @safe code), including storing pointers as int values. Any C code that your D program

Re: Transforming an argument list

2017-06-20 Thread ag0aep6g via Digitalmars-d-learn
On 06/20/2017 10:28 PM, Jean-Louis Leroy wrote: Any ideas? Thanks... 1) You can foreach over args: void test(string name, int val) { import std.stdio; writefln("%s = %d", name, val); } T double_int(T)(T val) { return val; } int double_int(int val) { return 2 * val; } void

Re: Playing with Entity System, performance and D.

2017-06-19 Thread ag0aep6g via Digitalmars-d-learn
On 06/20/2017 12:42 AM, SrMordred wrote: I took a deeper look into dub. "--build=release" make almost all optimizations flags on, except noboundscheck. There is a "--build=release-nobounds" and with it, the numbers got a lot closer (checked on another pc so will not post the numbers now)

Re: Playing with Entity System, performance and D.

2017-06-19 Thread ag0aep6g via Digitalmars-d-learn
On 06/19/2017 07:42 PM, SrMordred wrote: I was playing around my ES and different ways of doing it with D. I end up with a performance test of alias func vs ranges vs opApply. code here: https://dpaste.dzfl.pl/a2eff240552f Results on my machine win 10 x64, compiling with: dub run

Re: is it bug? (out contract in method causes dmd (2.072.2, 2.74.1) segfaults)

2017-06-14 Thread ag0aep6g via Digitalmars-d-learn
On 06/14/2017 01:06 PM, drug wrote: https://dpaste.dzfl.pl/b66fffa3bc8d It's always a bug when dmd segfaults.

Re: Generic operator overloading for immutable types?

2017-06-14 Thread ag0aep6g via Digitalmars-d-learn
On 06/14/2017 03:47 AM, Steven Schveighoffer wrote: The fundamental difference is that const and immutable share a characteristic that mutable doesn't -- you can't mutate the data. (... through the reference at hand.) const and mutable share this: The data may be mutated from elsewhere.

Re: Generic operator overloading for immutable types?

2017-06-13 Thread ag0aep6g via Digitalmars-d-learn
On 06/14/2017 12:45 AM, Steven Schveighoffer wrote: No, the fact that immutable implicitly casts to const(inout) is a special property enabled by the knowledge that immutable data can NEVER change, so it's OK to assume it's (at least) const for all references. The same cannot be true of const

Re: Static Initialization of Struct as UDA

2017-06-13 Thread ag0aep6g via Digitalmars-d-learn
On 06/14/2017 12:04 AM, jmh530 wrote: The code below doesn't compile because "static variable z cannot be read at compile time". However, z is a static variable, so I don't see why it wouldn't be available at compile-time. Bug or am I missing something? struct Bar { int x = 2; int

Re: Generic operator overloading for immutable types?

2017-06-13 Thread ag0aep6g via Digitalmars-d-learn
On 06/13/2017 10:50 PM, Steven Schveighoffer wrote: const(inout) actually *is* a thing :) It's a type constructor that can be implicitly cast from immutable. This has advantages in some cases. See (horribly written) table at the bottom if the inout function section here:

Re: Generic operator overloading for immutable types?

2017-06-13 Thread ag0aep6g via Digitalmars-d-learn
On 06/13/2017 09:29 PM, Gary Willoughby wrote: Is it possible for the `result` variable in the following code to be returned as an immutable type if it's created by adding two immutable types? Qualify the return type as `inout`: inout(Rational) opBinary(/*...*/)(/*...*/) inout {/*...*/}

Re: byLine(n)?

2017-06-11 Thread ag0aep6g via Digitalmars-d-learn
On 06/11/2017 03:00 PM, helxi wrote: I would also be really humbled if you demonstrate a faster approach of achieving the goal of the program :) (without explicitly using loops and conditions) Do you have a reason to believe that your version is slow? I don't see why it would be.

Re: Need way to compare classes, and primitive types in bst Template

2017-06-10 Thread ag0aep6g via Digitalmars-d-learn
On 06/10/2017 06:57 AM, Mark wrote: On Friday, 9 June 2017 at 15:12:04 UTC, ag0aep6g wrote: ... Note that this is only supposed to show how to do the special casing for classes. addNode probably doesn't do exactly what it's supposed to do in your tree. I'm not sure what you mean by this?

Re: Need way to compare classes, and primitive types in bst Template

2017-06-09 Thread ag0aep6g via Digitalmars-d-learn
On 06/09/2017 04:08 PM, Mark wrote: Possibly. but I can't use those methods on primitive types. Those methods implement operators. In your code you use the usual comparison operators: '==', '<', etc. Also, I tried implementing a internal method to determine if it is a class, or primitive,

Re: Need way to compare classes, and primitive types in bst Template

2017-06-08 Thread ag0aep6g via Digitalmars-d-learn
On 06/09/2017 05:32 AM, Mark wrote: https://dpaste.dzfl.pl/ff58876ce213 [...] What Id like to do is this: auto tree = new BSTbase!int; ... tree.insert(7); and auto Tree2 = new BSTbase!Aclass; ... Tree2.insert(Aclassobject); What I have is: Tree.insert(7, cast(real) 7); and

Re: The reason for SIGSEGV function pointer problem

2017-06-07 Thread ag0aep6g via Digitalmars-d-learn
On 06/07/2017 06:50 PM, Russel Winder via Digitalmars-d-learn wrote: So why isn't a thing of type check_frontend_t*? It's a thing of type `check_frontend_t`, which is a function pointer already. When you add an asterisk, you get a pointer to a function pointer.

Re: Can assumeSafeAppend() grab more and more capacity?

2017-06-06 Thread ag0aep6g via Digitalmars-d-learn
On 06/07/2017 12:12 AM, Ali Çehreli wrote: On 06/06/2017 12:13 PM, Jesse Phillips wrote: > On Monday, 5 June 2017 at 23:17:46 UTC, Ali Çehreli wrote: >> auto a = [ 1, 2, 3, 4 ]; >> auto b = a; [...] The only issue remaining for me is the part that you've quoted: Jesse Phillips

Re: Can assumeSafeAppend() grab more and more capacity?

2017-06-05 Thread ag0aep6g via Digitalmars-d-learn
On 06/05/2017 11:08 PM, Ali Çehreli wrote: Imagine an array that wants to reuse its buffer after removing elements from it. For example, a PID waiting list can remove completed elements and add new ones at the end. The code would call assumeSafeAppend like this: arr = arr.remove!(e => e

Re: How to Compare 2 objects of the same class

2017-06-03 Thread ag0aep6g via Digitalmars-d-learn
On 06/03/2017 10:02 PM, Mark wrote: auto A = new Box(); auto B = new Box(); if(A.opEquals(B)) {} gives the error test.o:(.data.rel.ro+0x18): undefined reference to `_D5Stack12__ModuleInfoZ' collect2: error: ld returned 1 exit status Error: linker exited with status 1 Your code works for

Re: RAII pointers

2017-06-03 Thread ag0aep6g via Digitalmars-d-learn
On 06/03/2017 09:37 PM, Moritz Maxeiner wrote: Of course, but AFAIK you'd need to explicitly assign it to an object, so `ptr` won't null by accident, but only by explicit programmer intent (same as overwriting the memory the object lives in via things like `memcpy`); and you can always screw

Re: RAII pointers

2017-06-03 Thread ag0aep6g via Digitalmars-d-learn
On 06/03/2017 09:06 PM, Moritz Maxeiner wrote: - null check in destructor: That's just because I forgot to add it. If you add `@disable(this)` (disable the default constructor), all elaborate constructors ensure it is not null, and no members can set it to null, you might be able to skip the

Re: Changing Template Static Ifs to Recursion

2017-05-31 Thread ag0aep6g via Digitalmars-d-learn
On 05/31/2017 08:50 PM, jmh530 wrote: Note: I left out the function foo, but think of foo is to Foo as tuple is to Tuple. You should have included foo, in my opinion. I'm having trouble figuring out what your code does. `process` instantiates foo with the field names. I'd need the definition

Re: purity question

2017-05-30 Thread ag0aep6g via Digitalmars-d-learn
On 05/30/2017 11:12 AM, Rene Zwanenburg wrote: If malloc were marked as pure, wouldn't that mean it must return the same pointer every time you call it with the same size? D's `pure` mostly means: "does not access mutable state, and does not do input/output". There is never a requirement

Re: Out of memory error (even when using destroy())

2017-05-26 Thread ag0aep6g via Digitalmars-d-learn
On 05/26/2017 10:15 AM, realhet wrote: But hey, the GC knows that is should not search for any pointers in those large blocks. And the buffer is full of 0-s at the start, so there can't be any 'false pointers' in it. And I think the GC will not search in it either. The issue is not that the

Re: Code improvement for DNA reverse complement?

2017-05-25 Thread ag0aep6g via Digitalmars-d-learn
On 05/25/2017 10:41 PM, Ali Çehreli wrote: I would like to acknowledge you in the book hopefully with your real name but if you don't want or care, I will use ag0aep6g. :) Thanks, but I don't really care for the recognition. If anything, please use ag0aep6g.

Re: Any way to reproduce Dart style constructors?

2017-05-25 Thread ag0aep6g via Digitalmars-d-learn
On 05/25/2017 09:15 PM, Moritz Maxeiner wrote: Ok, you are right. Open a bug report? Sure. https://issues.dlang.org/show_bug.cgi?id=17435

Re: Any way to reproduce Dart style constructors?

2017-05-25 Thread ag0aep6g via Digitalmars-d-learn
On 05/25/2017 08:14 PM, Moritz Maxeiner wrote: Well, then I guess we need a compiler guy to clear this up, because from my point of view, the template is instantiated within the scope of the class (way before we reach the mixin), nesting the template's scope within the class' scope, which

Re: Any way to reproduce Dart style constructors?

2017-05-25 Thread ag0aep6g via Digitalmars-d-learn
On 05/25/2017 03:13 PM, Moritz Maxeiner wrote: After thinking about this a bit I think I know why it doesn't work without static and it's not a compiler bug. Since --- string AutoConstructor(fields ...)() {} --- is just syntax sugar for --- template AutoConstructor(fields ...) { string

Re: Any way to reproduce Dart style constructors?

2017-05-25 Thread ag0aep6g via Digitalmars-d-learn
On 05/25/2017 12:52 PM, Moritz Maxeiner wrote: Be aware, though, that constructors mixed in via a mixin template behave differently with regards to overloading[1]. [1] https://issues.dlang.org/show_bug.cgi?id=11500 Of course it couldn't be that simple :( Adam's workaround (`alias __ctor =

Re: Any way to reproduce Dart style constructors?

2017-05-25 Thread ag0aep6g via Digitalmars-d-learn
On 05/25/2017 10:34 AM, JN wrote: class Person { string name; int age; mixin(AutoConstructor!(age, name)); } [...] I am not looking for code, I can try that myself, just asking if such things are possible? I know you're not asking for code, but without experimenting I wouldn't have

<    1   2   3   4   5   6   7   8   >