Re: Handling arbitrary char ranges

2016-04-20 Thread ag0aep6g via Digitalmars-d-learn
On 20.04.2016 22:09, Matt Kline wrote: I'd rather not write my own cURL wrapper. Do you think it would be worthwhile starting a PR for Phobos to get it changed to ubyte[]? A reading of https://dlang.org/spec/arrays.html indicates the main difference is that that GC crawls void[], but I would

Re: Handling arbitrary char ranges

2016-04-20 Thread ag0aep6g via Digitalmars-d-learn
On 20.04.2016 21:48, Matt Kline wrote: I don't have an option here, do I? I assume HTTP.onSend doesn't take a `delegate size_t(ubyte[])` insetad of a `delegate size_t(void[])`, and that the former isn't implicitly convertible to the latter. Maybe I've missed it, but you didn't say where the

Re: Handling arbitrary char ranges

2016-04-20 Thread ag0aep6g via Digitalmars-d-learn
On 20.04.2016 19:09, Matt Kline wrote: 1. What is the idiomatic way to constrain the function to only take char ranges? One might naïvely add `is(ElementType!T : char)`, but that falls on its face due to strings "auto-decoding" their elements to dchar. (More on that later.) Well, string is not

Re: .opAssign disabled without @disable

2016-04-17 Thread ag0aep6g via Digitalmars-d-learn
On 17.04.2016 13:00, denizzzka wrote: So, my problem is solved. But nevertheless maybe here is a problem in the compiler too. I've reduced the test case and filed an issue: https://issues.dlang.org/show_bug.cgi?id=15936

Re: Is this a bug?

2016-04-15 Thread ag0aep6g via Digitalmars-d-learn
On 15.04.2016 20:55, Eric wrote: 13 class C : const (I!(J)) I think this const is ignored by the compiler. 15F!(J) m; A little tip: You can omit the parentheses of template instantiations when the argument is a single identifier. That is, `F!(J)` can be written as `F!J`.

Re: Is this a bug?

2016-04-15 Thread ag0aep6g via Digitalmars-d-learn
On 15.04.2016 19:13, Eric wrote: 1 alias J = const C; 2 3 void main(string[] args) 4 { 5 J a = new C(); 6 I!(J) i = a; 7 } 8 9 interface I(V) { } 10 11 class F(V) if (is(V : I!(V))) { } 12 13 class C : I!(J) 14 { 15 F!(J) m; 16 } The above

Re: How to run unit tests on Windows?

2016-04-14 Thread ag0aep6g via Digitalmars-d-learn
On 14.04.2016 12:39, pineapple wrote: I've had success running unit tests on OSX by running `rdmd --main -unittest [file]` but have had no such luck on Windows. The aforementioned command fails, Should work. If you can go into more detail as to how it fails, maybe we can figure out what's

Re: Extensible struct type via variadic template arguments

2016-04-11 Thread ag0aep6g via Digitalmars-d-learn
On 10.04.2016 20:45, Joseph Rushton Wakeling wrote: One very basic idea is to allow graph edges to have arbitrary properties, and to do that, I've tried to come up with a basic data structure that can be extended via variadic template arguments. However, I'm not entirely satisfied with the

Re: Casting a class variable to void*

2016-04-10 Thread ag0aep6g via Digitalmars-d-learn
On 11.04.2016 00:06, Manuel Maier wrote: So, is this a bug, or is it intended behavior? In case of the latter, I'd gladly add it to the documentation. Looks like a bug to me. And it's already been filed: https://issues.dlang.org/show_bug.cgi?id=13392

Re: Stupid question about AA. The following code works but I don't undrstand why?!

2016-04-09 Thread ag0aep6g via Digitalmars-d-learn
On Saturday, 9 April 2016 at 19:31:31 UTC, Uranuz wrote: I think that we need to add warning about such case in documentation section: https://dlang.org/spec/hash-map.html#construction_and_ref_semantic in order to prevent this kind of mistakes in code. Isn't that exactly what the section you

Re: Stupid question about AA. The following code works but I don't undrstand why?!

2016-04-09 Thread ag0aep6g via Digitalmars-d-learn
On Saturday, 9 April 2016 at 19:25:32 UTC, Uranuz wrote: Another observation is illustrated with the foloving code: http://dpaste.dzfl.pl/8d68fd5922b7 Because AA and arrays are not created before they were assigned some value it leads to inconsistency in behavior. And will produce unexpected

Re: Stupid question about AA. The following code works but I don't undrstand why?!

2016-04-09 Thread ag0aep6g via Digitalmars-d-learn
On Saturday, 9 April 2016 at 18:06:52 UTC, Uranuz wrote: Thanks. It's clear now. AA holds not `array struct` itself inside, but pointer to it. How the array is stored in the AA doesn't matter, as far as I can see. The point is that you obtain a pointer to the array struct in the AA, not a

Re: Stupid question about AA. The following code works but I don't undrstand why?!

2016-04-09 Thread ag0aep6g via Digitalmars-d-learn
On 09.04.2016 18:13, Uranuz wrote: http://dpaste.dzfl.pl/523781df67ab For reference, the code: import std.stdio; void main() { string[][string] mapka; string[]* mapElem = "item" in mapka; //Checking if I have item if( !mapElem )

Re: Practical difference between a struct with const members and with mutable members?

2016-04-09 Thread ag0aep6g via Digitalmars-d-learn
On 09.04.2016 18:07, pineapple wrote: What's different between these two examples, practically speaking? When would you use one over the other? struct thing1{ const int x, y; } struct thing2{ int x, y; } In this case, const is practically the same as immutable. But immutable is

Re: Interfaces

2016-04-09 Thread ag0aep6g via Digitalmars-d-learn
On 09.04.2016 10:45, alexander Patapoff wrote: is there a way for me to do this in D? In java, one is able to create a new instance of an interface. interface Action { void actions(T t); } class testAction { this() { Action action = new Action() { void

Re: Mixin templates as virtual function add tool

2016-04-08 Thread ag0aep6g via Digitalmars-d-learn
On 08.04.2016 14:04, Voitech wrote: template MixinTypeIterate(alias mixinTemplate,TList...){ [...] } how to alias mixin template to be able to pass it to this one ? class BaseClass(T){ protected alias Types=AliasSeq!(int,string,ubyte); private alias WrappedMix(S)=mixin Mix!(T,S);

Re: How to set padding for base64 encoding

2016-04-07 Thread ag0aep6g via Digitalmars-d-learn
On 07.04.2016 14:57, rikki cattermole wrote: Ugh, 2.070.2 definitely has it still. I have no idea when that changed I don't think """...""" ever was a thing. You could definitely put newlines in normal "..." literals since basically forever. And concatenation of adjacent "..." literals

Re: How to set padding for base64 encoding

2016-04-07 Thread ag0aep6g via Digitalmars-d-learn
On 07.04.2016 13:59, rikki cattermole wrote: "abc" strings are not multiline. Use """abc""" for that purpose. Wat. We're talking about, aren't we? In D, "abc" strings are multiline, and """abc""" is not a thing. `"""abc"""` is the same as `"" "abc" ""` is the same as `"" ~ "abc" ~ ""` is the

Re: Convert wchar* to wstring?

2016-04-05 Thread ag0aep6g via Digitalmars-d-learn
On 05.04.2016 20:44, Thalamus wrote: import core.stdc.stddef; // For wchar_t. This is defined differently for Windows vs POSIX. import core.stdc.wchar_; // For wcslen. Aside: D has syntax for "// For wchar_t.": `import core.stdc.stddef: wchar_t;`. wstring toWstring(wchar_t* value) {

Re: Using a macro for a function signature

2016-04-05 Thread ag0aep6g via Digitalmars-d-learn
On 05.04.2016 13:35, pineapple wrote: alias somelongsignature = int(in int x); alias somelongsignature = int function(in int); Or if you want to accept methods and such: alias somelongsignature = int delegate(in int); You can name the parameter, but it won't be part of the type. int

Re: Issue Turning Template into Variadic Template

2016-03-31 Thread ag0aep6g via Digitalmars-d-learn
On 30.03.2016 20:12, jmh530 wrote: I wrote a version of cartesianProduct that will return the cartesian product when the some of the types are not ranges. The original code is below. My issue is that I can't figure out how to turn it into a variadic template. The latest thing I tried is: auto

Re: char array weirdness

2016-03-31 Thread ag0aep6g via Digitalmars-d-learn
On 31.03.2016 07:40, Jack Stouffer wrote: $ ldc2 -O3 -release -boundscheck=off test.d $ ./test auto-decoding1 sec, 757 ms, and 946 μs byCodeUnit87 ms, 731 μs, and 8 hnsecs byGrapheme14 secs, 769 ms, 796 μs, and 6 hnsecs So the auto-decoding version takes about twenty

Re: char array weirdness

2016-03-30 Thread ag0aep6g via Digitalmars-d-learn
On 30.03.2016 19:30, Jack Stouffer wrote: Just to drive this point home, I made a very simple benchmark. Iterating over code points when you don't need to is 100x slower than iterating over code units. [...] enum testCount = 1_000_000; enum var = "Lorem ipsum dolor sit amet, consectetur

Re: Array Indexing/Slicing Range Checking, Exceptions and @nogc

2016-03-30 Thread ag0aep6g via Digitalmars-d-learn
On 30.03.2016 15:44, Nordlöw wrote: On Wednesday, 30 March 2016 at 13:24:20 UTC, ag0aep6g wrote: [...] This is off topic, but don't mark templates like that @trusted. By doing so you also trust R, but you don't know if it's memory safe. Should I post in group "General" instead? No, no, I

Re: Array Indexing/Slicing Range Checking, Exceptions and @nogc

2016-03-30 Thread ag0aep6g via Digitalmars-d-learn
On 30.03.2016 15:12, Nordlöw wrote: https://github.com/nordlow/justd/blob/master/packedarray.d From there: this(R)(R values, bool assumeSortedParameter = false) @trusted nothrow @("complexity", "O(n*log(n))") if (isInputRange!R) This is off topic, but don't mark templates like

Re: char array weirdness

2016-03-28 Thread ag0aep6g via Digitalmars-d-learn
On 29.03.2016 00:49, Jack Stouffer wrote: But the value fits into a char; a dchar is a waste of space. Why on Earth would a different type be given for the front value than the type of the elements themselves? UTF-8 strings are decoded by the range primitives. That is, `front` returns one

Re: I need some help benchmarking SoA vs AoS

2016-03-26 Thread ag0aep6g via Digitalmars-d-learn
On 26.03.2016 18:04, ag0aep6g wrote: https://gist.github.com/aG0aep6G/a1b87df1ac5930870ffe/revisions PS: Those enforces are for a size of 100_000 not 1_000_000, because I'm impatient.

Re: I need some help benchmarking SoA vs AoS

2016-03-26 Thread ag0aep6g via Digitalmars-d-learn
On 26.03.2016 17:31, ag0aep6g wrote: Let the output depend on the results somehow. Simply printing them out should do the trick. You can also try throwing an Exception on wrong results. Else the calculations will be optimized away completely. Also make sure that data that's supposed to be

Re: I need some help benchmarking SoA vs AoS

2016-03-26 Thread ag0aep6g via Digitalmars-d-learn
On 26.03.2016 14:47, maik klein wrote: The problem I have is that LDC always seems to optimize the functions too much. At least one function executes always in "1 hnsec". Let the output depend on the results somehow. Simply printing them out should do the trick. You can also try throwing an

Re: How do you append to a dynamic array using move semantics?

2016-03-23 Thread ag0aep6g via Digitalmars-d-learn
On 24.03.2016 00:44, ag0aep6g wrote: On 24.03.2016 00:26, cy wrote: ++items.length move(items[$-1],item); // Error: struct Thing is not copyable because it is annotated with @disable You got the order of arguments wrong here. Source goes first, target second. Works for me with `move(item,

Re: How do you append to a dynamic array using move semantics?

2016-03-23 Thread ag0aep6g via Digitalmars-d-learn
On 24.03.2016 00:26, cy wrote: ++items.length move(items[$-1],item); // Error: struct Thing is not copyable because it is annotated with @disable You got the order of arguments wrong here. Source goes first, target second. Works for me with `move(item, items[$-1]);`.

Re: If I understand const right...

2016-03-23 Thread ag0aep6g via Digitalmars-d-learn
On 23.03.2016 22:26, ag0aep6g wrote: On 23.03.2016 22:18, cy wrote: On Wednesday, 23 March 2016 at 21:10:49 UTC, ag0aep6g wrote: [...] b = new int(*b + 1); Here "b" is pointing to mutable heap allocated data, which got cast to constant. with b = b + 1, it's still constant memory. It's

Re: If I understand const right...

2016-03-23 Thread ag0aep6g via Digitalmars-d-learn
On 23.03.2016 22:18, cy wrote: On Wednesday, 23 March 2016 at 21:10:49 UTC, ag0aep6g wrote: [...] b = new int(*b + 1); Here "b" is pointing to mutable heap allocated data, which got cast to constant. with b = b + 1, it's still constant memory. It's stack memory. Its constness isn't any

Re: If I understand const right...

2016-03-23 Thread ag0aep6g via Digitalmars-d-learn
On 23.03.2016 21:52, cy wrote: const(int)[2] a = [23,24]; const(int)* b = a; Should be: const(int)* b = a.ptr; writeln(," always constant"); writeln(a, " always constant"); There's some subtlety here. `a` itself is not const, but its elements are. `a` being a fixed-sized array, you can't

Re: Something wrong with GC

2016-03-23 Thread ag0aep6g via Digitalmars-d-learn
On 22.03.2016 16:56, ag0aep6g wrote: I've filed an issue: https://issues.dlang.org/show_bug.cgi?id=15821 And it's been fixed: https://github.com/D-Programming-Language/druntime/pull/1519 Since the issue was a regression, the fix was made against the stable branch. It's going to be in the

Re: Something wrong with GC

2016-03-22 Thread ag0aep6g via Digitalmars-d-learn
On 20.03.2016 08:49, stunaep wrote: The gc throws invalid memory errors if I use Arrays from std.container. For example, this throws an InvalidMemoryOperationError: import std.stdio; import std.container; void main() { new Test(); } class Test { private Array!string test =

Re: /usr/bin/ld: cannot find -lphobos2

2016-03-21 Thread ag0aep6g via Digitalmars-d-learn
On 21.03.2016 11:19, ZombineDev wrote: DFLAGS=-I~/dev/repos/dlang/druntime/import -I~/dev/repos/dlang/phobos -L-L/home/zombinedev/dev/repos/dlang/phobos/generated/*/release/64 [...] Linking... ... /usr/bin/ld {other stuff...} -L/home/zombinedev/dev/repos/dlang/phobos/generated/*/release/64

Re: Class member always has the same address

2016-03-19 Thread ag0aep6g via Digitalmars-d-learn
On 19.03.2016 21:24, szymski wrote: In my opinion should give different addresses for each instance of A, because it's not static. What am I doing wrong? Thanks in advance. The As are different, but they all reference the same B. Initialize b in a constructor instead.

Re: Specialized template in different module

2016-03-14 Thread ag0aep6g via Digitalmars-d-learn
On 14.03.2016 09:42, John wrote: module one; struct Test(T) {} void testing(T)(Test!T t) {} module two; struct Test(T : int) {} void main() { Test!int i; testing!int(i); } Output: error : testing (Test!int t) is not callable using argument types (Test!int)

Re: Filling an array

2016-03-12 Thread ag0aep6g via Digitalmars-d-learn
On 12.03.2016 16:44, Mike Parker wrote: arr[] = cast(Nullable!uint)1; Nicer than a cast: construct a Nullable!int. arr[] = Nullable!uint(1);

Re: Simple call to static member function

2016-03-11 Thread ag0aep6g via Digitalmars-d-learn
On 11.03.2016 23:47, WhatMeWorry wrote: --- main.d void main(string[] argv) { ResourceManager.LoadShader("VertexShader.glsl", "FragmentShader.glsl", "filler", "sprite"); --- File ResourceManager.d

Re: What can _not_ be marked pure?

2016-03-09 Thread ag0aep6g via Digitalmars-d-learn
On 09.03.2016 10:57, Guillaume Piolat wrote: Another question that ensues is: will the compiler prevent incorrect use of pure, so that it's safe to spam it in your code? The compiler should catch wrong usage of `pure`, yes. Function declarations without implementation are an exception, of

Re: What can _not_ be marked pure?

2016-03-09 Thread ag0aep6g via Digitalmars-d-learn
On 09.03.2016 10:56, Guillaume Piolat wrote: If I understand purity correctly (http://klickverbot.at/blog/2012/05/purity-in-d/), every function out there can be marked pure as long as it doesn't modify globals, shared variables or do I/O? Pure functions also can't *read* mutable globals. But

Re: Unable to instantiate template with same name as function

2016-03-03 Thread ag0aep6g via Digitalmars-d-learn
On 03.03.2016 07:12, Shriramana Sharma wrote: string ta(string s) { return s ~ "1"; } template ta(string s) { enum ta = ta(s); } In `ta(s)` here, `ta` is the enum itself again. It's similar to `int x = x;`. Can't do that, of course. Add a leading dot to refer to the module level `ta`

Re: Warning: statement is not reachable

2016-03-02 Thread ag0aep6g via Digitalmars-d-learn
On 01.03.2016 22:30, Tamas wrote: struct Tag {} template isTagged(S) { enum bool isTagged = delegate() { foreach(attr; __traits(getAttributes, S)) { static if (is(attr == Tag)) { return true; } }

Re: Lazy param with nothrow

2016-03-01 Thread ag0aep6g via Digitalmars-d-learn
On 01.03.2016 14:35, Andrea Fontana wrote: This very very simple function [1] won't compile. It says that param t is not nothrow. Why? What's wrong with this? http://dpaste.dzfl.pl/bfc382e62711 It's a bug. Lazy parameters generate delegates. nothrow is currently not inferred for those

Re: Why .length on Windows is int and on Linux is ulong?

2016-02-29 Thread ag0aep6g via Digitalmars-d-learn
On 29.02.2016 12:06, Suliman wrote: On Windows next code work fine: int len = fullimgurl.length; On Linux DMD get error that: Error: cannot implicitly convert expression (fullimgurl.length) of type ulong to int Why on every OS length have different size? On Windows, the compiler flag -m32 is

Re: Why we cannot use string in mixins?

2016-02-27 Thread ag0aep6g via Digitalmars-d-learn
On 28.02.2016 00:29, mahdi wrote: I read this criticism about D on Reddit and it claims that you cannot use strings in mixins. Can you please elaborate about this and the reason behind it? QUOTE: Look at strings: they are defined as immutable(char []). immutable(char)[] actually "immutable"

Re: how do you append arrays?

2016-02-25 Thread ag0aep6g via Digitalmars-d-learn
On 25.02.2016 14:33, Nicholas Wilson wrote: Note that D has zero based array indexing so assuming your array has 100 elements history[1..100] is going one past the end of the array. No, that's fine. `history[1..100]` gives you 99 elements starting at index 1, i.e. all except the first one.

Re: Issues

2016-02-22 Thread ag0aep6g via Digitalmars-d-learn
On 22.02.2016 23:56, Andre wrote: I was wondering how people in this D community think about the number of issues with NEW status... It could scare individuals/organizations to start with D, when they get the impression that there are a large and growing number of issues that are open (for

<    3   4   5   6   7   8