Re: non empty slices

2016-06-02 Thread ag0aep6g via Digitalmars-d-learn
On 06/02/2016 10:11 PM, Alex wrote: The cool thing about the Algebraic is as I expected, that it doesn't change it's type... And the hard thing is, that I'm not used to its Empty, Many, ... things yet. I just made those up on the spot. Note that Many is not actually implemented at all. There

Re: non empty slices

2016-06-02 Thread ag0aep6g via Digitalmars-d-learn
On 06/02/2016 11:37 PM, Alex wrote: Just tried this instead of your f-function: void f(int[] arr) { A result; import std.meta; alias TL = AliasSeq!(Empty, int, Many!int); int caseS; switch (arr.length) { case 0: result = Empty.init; caseS = 0; break;

Re: Problem with insertBack

2016-06-03 Thread ag0aep6g via Digitalmars-d-learn
On 06/03/2016 04:34 PM, John Nixon wrote: import std.stdio; import std.container; struct CS{ char[] t; CS dup()const{ CS cs; cs.t = this.t.dup; return cs;} }; Aside: No semicolon after struct declarations in D. void main(){ Array!CS cs_array = make!(Array!CS)();

Re: non empty slices

2016-06-02 Thread ag0aep6g via Digitalmars-d-learn
On 06/03/2016 01:35 AM, ag0aep6g wrote: The alternative `peek` method is not documented to throw an exception, but it's not @nogc either. No idea why. Maybe Algebraic does GC allocations internally. I wouldn't know for what, though. Or it misses a @nogc somewhere. I've looked at the source to

Re: non empty slices

2016-06-02 Thread ag0aep6g via Digitalmars-d-learn
On 06/03/2016 01:17 AM, Alex wrote: But still, I can't mark the f-method @nogc, and this is not due to the writeln calls... why GC is invoked, although everything is known and no memory allocation should happen? It's the Algebraic. The `get` method isn't @nogc. The documentation [1] says that

Re: Overriden method not detected ?

2016-06-03 Thread ag0aep6g via Digitalmars-d-learn
On 06/03/2016 10:06 PM, chmike wrote: If I have a static immutable object, I don't have to declare it as shared because it is implicit. Right ? Right. [...] 1. question --- I had a __gshared Info[N] infos_; that I fill in a static this() method. Should be filling it in a `shared

Re: Why I can't catch the exception?

2016-06-05 Thread ag0aep6g via Digitalmars-d-learn
On 06/05/2016 08:02 PM, Suliman wrote: I really can't understand why try-catch block do not handle exception. digit 1 is printing, so exception is accrue after it, but why nothing in catch block? http://img.ctrlv.in/img/16/06/05/57546861d8e81.png Here is my code: void dbSetup() { try

Re: Enum that can be 0 or null

2016-06-07 Thread ag0aep6g via Digitalmars-d-learn
On 06/07/2016 08:50 PM, ParticlePeter wrote: On Tuesday, 7 June 2016 at 14:31:40 UTC, Alex Parrill wrote: I don't think opCast gets called for implicit conversions; it only gets called for explicit casts. I'll test it later. It does for type bool, but I fear that's the only exception. No,

Re: a lambda with arguments has type void?

2016-06-07 Thread ag0aep6g via Digitalmars-d-learn
On 06/08/2016 12:02 AM, cy wrote: import std.stdio; void foo(Callable)(Callable bar) { bar(); } void foo2(Callable)(Callable bar, int baz) { bar(baz); } void main() { foo({ writeln("okay"); }); foo2((bar) { writeln("got",bar); },42); foo2((bar) =>

Re: interfacing with C: strings and byte vectors

2016-06-11 Thread ag0aep6g via Digitalmars-d-learn
On 06/11/2016 01:59 PM, yawniek wrote: i forgot to add a few important points: - the strings in vec_t are not c strings - vec_t might contain other data than strings the original ctor i pasted actually doesn't even work, temporarly i solved it like this(string s) { char[] si =

Re: Error: mutable method isolated.graphics.g3d.model.Model.begin is not callable using a const object

2016-06-06 Thread ag0aep6g via Digitalmars-d-learn
On 06/06/2016 11:25 PM, Alex Parrill wrote: You might be able to get away with casting the const away, if you are sure it won't modify the hash or equality check. Casting away const and then mutating has undefined behavior. The compiler is free to assume that it doesn't happen. Be aware

Re: Overriden method not detected ?

2016-06-04 Thread ag0aep6g via Digitalmars-d-learn
On 06/04/2016 05:02 PM, chmike wrote: Is it possible to instantiate immutable objects by using emplace Yes. I'm not sure, but the memory may have to be untyped for the emplace call to avoid mutating immutable data. I.e., call emplace with void[], not with a pointer whose target is already

Re: is my code to get CTFE instantiated object valid D ?

2016-05-28 Thread ag0aep6g via Digitalmars-d-learn
On 05/28/2016 09:54 PM, chmike wrote: The only inconvenience left is that we can't have mutable references to immutable objects. There is std.typecons.Rebindable for that.

Re: is my code to get CTFE instantiated object valid D ?

2016-05-28 Thread ag0aep6g via Digitalmars-d-learn
On 05/28/2016 10:34 AM, Mike Parker wrote: On Saturday, 28 May 2016 at 05:30:26 UTC, chmike wrote: [...] Is a static const Category c variable a TLS variable ? Yes. All variables are TLS unless explicitly marked with __gshared or shared. I don't think that's true. import core.thread;

Re: @trusting generic functions

2016-05-28 Thread ag0aep6g via Digitalmars-d-learn
On 05/28/2016 02:43 PM, Lodovico Giaretta wrote: struct S1 { int doSomething() @safe { // do something safely return 1; } } struct S2 { int doSomething() @system { // do something usafe return 2; } } auto doSomethingDumb(T)(ref

Re: is my code to get CTFE instantiated object valid D ?

2016-05-28 Thread ag0aep6g via Digitalmars-d-learn
On 05/28/2016 06:09 PM, chmike wrote: In the following instruction of the above commit, what effect has the [] after init ? _store[0 .. __traits(classInstanceSize, T)] = typeid(T).init[]; T is a template argument that is a class derived from Error. I couldn't find an explanation here

Re: String compare in words?

2016-05-30 Thread ag0aep6g via Digitalmars-d-learn
On 05/29/2016 10:40 PM, qznc wrote: bool string_cmp_opt(immutable(ubyte)[] x, immutable(ubyte)[] y) { Having "string" in the function name may be a bit misleading. This doesn't have any special functionality for text/characters/Unicode, does it? Should have const parameters, not immutable.

Re: Why do some T.init evaluate to true while others to false?

2016-05-26 Thread ag0aep6g via Digitalmars-d-learn
On 05/26/2016 05:28 PM, ArturG wrote: On Thursday, 26 May 2016 at 15:25:26 UTC, ag0aep6g wrote: [...] What does it matter? You would have to create special cases for them. When? If you want to check if something is the .init value, compare against .init.

Re: Why do some T.init evaluate to true while others to false?

2016-05-26 Thread ag0aep6g via Digitalmars-d-learn
On 05/26/2016 04:03 PM, ArturG wrote: for example: if(any floatingpoint.init) will be true if(any char.init) also true if("") also true while others are false e.g. string s; if(s) will be false all others are also false or did i miss any? What does it matter?

Re: non empty slices

2016-06-02 Thread ag0aep6g via Digitalmars-d-learn
On 06/02/2016 03:37 PM, Alex wrote: The question is, how to define the same thing for ranges. What I started with is: import std.range : iota; alias MrSlice = typeof(iota(M.init)); so far, so good. The MrSlice-thing is the analogy for Mr, as it can be empty, as Mr can. What I also need is the

Re: Creating a "fixed-range int" with opDispatch and/or alias this?

2016-06-02 Thread ag0aep6g via Digitalmars-d-learn
On 06/02/2016 04:59 PM, Ali Çehreli wrote: 'alias this' with property functions work at least for your example: struct FixedRangeInt { int min; int max; int i_; int value() const { return i_; } void value(int i) { assert(i >= min);

Re: non empty slices

2016-06-02 Thread ag0aep6g via Digitalmars-d-learn
On 06/02/2016 05:16 PM, Alex wrote: What I mean is: if there would be a possibility to use algebraic types here (or maybe some kind of template...), then my types would be able (maybe! did not seen anything similar yet...) to choose the proper methods for themselves automatically: As long as my

Re: Testing array ptr for offset 0...

2016-05-26 Thread ag0aep6g via Digitalmars-d-learn
On 05/26/2016 11:13 PM, Era Scarecrow wrote: By adding a struct overload for opOpAssign I can shrink it all down to this, and avoid lengths entirely... As such internally the length starts at 0, and checks are in place to ensure the bounds are never exceeded. void scan(ref Data[][] data,

Re: Testing array ptr for offset 0...

2016-05-26 Thread ag0aep6g via Digitalmars-d-learn
On 05/26/2016 09:51 AM, Era Scarecrow wrote: So I'm experimenting and want to override how arrays are managed for a short duration, this is for optimization of not having to make another array to keep track of lengths and then shorten them when i can in fact just manage it myself *very*

Re: opDispatch and @property setters

2016-06-21 Thread ag0aep6g via Digitalmars-d-learn
On 06/21/2016 10:48 PM, Lodovico Giaretta wrote: struct Wrapper(T) { private T wrapped; template hasAssignableProperty(string name, Arg) { enum bool hasAssignableProperty = is(typeof( (ref T val, ref Arg arg) {

Re: Why do I get this error when casting to an immutable or shared byRef return type?

2016-06-19 Thread ag0aep6g via Digitalmars-d-learn
On 06/19/2016 12:45 PM, Gary Willoughby wrote: On Sunday, 19 June 2016 at 10:35:59 UTC, Gary Willoughby wrote: ... A more correct example: import core.stdc.stdlib; import std.traits; ref T foo(T)() { alias Type = Unqual!(T); Type* foo = cast(Type*) malloc(Type.sizeof * 8);

Re: D casting broke?

2016-06-19 Thread ag0aep6g via Digitalmars-d-learn
On 06/19/2016 11:19 PM, Joerg Joergonson wrote: On Sunday, 19 June 2016 at 20:21:35 UTC, ag0aep6g wrote: [...] No. B!b is derived from A!b, not from A!a. `b` being derived from `a` does not make A!b derived from A!a. why not? This doesn't seem logical! Template parameters simply don't work

Re: D casting broke?

2016-06-19 Thread ag0aep6g via Digitalmars-d-learn
On 06/19/2016 09:59 PM, Joerg Joergonson wrote: This should be completely valid since B!T' obviously derives from A!T directly ok and we see that T' derives from b which derives from a directly. ok So B!b is an entirely derived from A!a No. B!b is derived from A!b, not from A!a. `b`

Re: D casting broke?

2016-06-20 Thread ag0aep6g via Digitalmars-d-learn
On 06/20/2016 01:40 AM, Joerg Joergonson wrote: public class Button(T : ButtonItem) : Widget { ... } public class ButtonItem : Item { void Do() { auto parent = (cast(Button!ButtonItem)this.Parent); } ... } All this works great! As long as Do is not being called from a derived class public

Re: canFind doesn't work on Array, replacing [] with array doesn't work, etc...

2016-06-18 Thread ag0aep6g via Digitalmars-d-learn
On Saturday, 18 June 2016 at 17:02:40 UTC, Joerg Joergonson wrote: 3. can't use canFind from algorithm. Complains it can't find a matching case. I tried many variations to get this to work. canFind takes a range. Array isn't a range itself, but you can get one by slicing it with []:

Re: Is there a more elegant way of testing T for multiple types?

2016-06-18 Thread ag0aep6g via Digitalmars-d-learn
On 06/18/2016 04:37 PM, Gary Willoughby wrote: Here I'm testing T is either a class or interface: void foo(T)(T bar) if (is(T == class) || is(T == interface)) { ... } Is there a more elegant way of testing T for multiple types? Because it doesn't scale well if I need to add more. I would

Re: executeShell doesn't work but system does

2016-06-26 Thread ag0aep6g via Digitalmars-d-learn
On 06/26/2016 05:37 PM, Smoke Adams wrote: system("cls") works but executeShell doesn't. system is depreciated. Unsolicited spelling correction: no 'i' in "deprecated". What's going on? The docs say that it creates a new process. I simply want to clear the console! `system` directly prints

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: 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: 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

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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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 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 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: 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: 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: 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: 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: 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: 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: 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: 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: /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: 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: 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 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: 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: 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: 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: 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: 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: 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: 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: Will the GC scan this pointer?

2016-04-24 Thread ag0aep6g via Digitalmars-d-learn
On 24.04.2016 13:03, Lass Safin wrote: // Omitting the required imports. void[] ptr; void main() { uint buffer; glCreateBuffers(1, ); // Filling the buffer with data and such... ptr = glMapNamedBufferRange(buffer, 0, 512, GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT |

Re: Are structs saved in multi-thread delegate call?

2016-04-22 Thread ag0aep6g via Digitalmars-d-learn
On 23.04.2016 03:11, Ramon wrote: mmm, I figured the problem, but don't know how to solve it. my struct has a destructor which clears itself: struct json_value { ~this() { .ValueClear(); } } So the struct is destroyed at the end of DoDirSearch, despite there being a closure for it. Is the

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 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: 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: "inline" conversion of array to immutable

2016-04-22 Thread ag0aep6g via Digitalmars-d-learn
On 22.04.2016 13:46, Jeff Thompson wrote: The function literal also works if I add "function int[]()": void main(string[] args) { immutable int[] array = function int[]() { int[] result = new int[10]; result[0] = 1; return result; }(); } I take it you're on 2.070 or older

Re: "inline" conversion of array to immutable

2016-04-22 Thread ag0aep6g via Digitalmars-d-learn
On 22.04.2016 13:07, Jeff Thompson wrote: OK, we lose the compiler check for correctness. What if I put func directly in main with the hopes that the compiler will check correctness and also inline the function? But it won't assign to the immutable array. Why not? It's the same function. void

Re: sending shared pointer to struct. message type mismatch

2016-04-21 Thread ag0aep6g via Digitalmars-d-learn
On 21.04.2016 19:10, jacob wrote: private void runner(T)() { shared(T*) s = receiveOnly!(shared(T*))(); This tries to receive a `shared(S!(M, 2)*)`. writeln(s.x.length); writeln(s.x[0]); send(thisTid, true); Aside: Should be `ownerTid` here, no? } int main(string[]

Re: What does alias do?

2016-04-27 Thread ag0aep6g via Digitalmars-d-learn
On 27.04.2016 21:40, xtreak wrote: import std.array; import std.range; import std.algorithm; import std.stdio; T test(alias f, T)(T num) { return f(num); } T test1(T, V)(T num, V f){ return f(num); } void main() { writeln("hello world"); writeln(1.iota .map!(a =>

Re: Constructing an enum using the members of an AliasSeq as enumerator names

2016-04-27 Thread ag0aep6g via Digitalmars-d-learn
On 27.04.2016 13:06, Nordlöw wrote: /** Returns: a `string` containing the definition of an `enum` named `name` and with enumerator names given by `Es`, optionally prepended with `prefix` and appended with `suffix`. TODO Move to Phobos std.typecons */ string

Re: Garbage Collector : Ignoring a reference

2016-04-26 Thread ag0aep6g via Digitalmars-d-learn
On 26.04.2016 15:35, Begah wrote: Nothing will reload. An example : I load a texture "button.png" in a class and draw it to the screen, When the screen switches to another screen ie from menu to the game, I want that the "button.png" texture is automaticly destroyed by the gc. But this will

Re: Are structs saved in multi-thread delegate call?

2016-04-23 Thread ag0aep6g via Digitalmars-d-learn
On 23.04.2016 07:35, ag0aep6g wrote: So the struct is destroyed at the end of DoDirSearch, despite there being a closure for it. Is the compiler doing the right thing here? Shouldn't the struct be considered alive until the closure gets garbage collected? I've filed an issue:

Re: What does alias do?

2016-04-23 Thread ag0aep6g via Digitalmars-d-learn
On 23.04.2016 21:49, xtreak wrote: I am a D newbie from Python and I am trying to grok alias. Is alias like Python does as below L = [] myextend = L.extend L.myextend My Python isn't too great, but I think this is more similar to function pointers or delegates in D. Renaming imported

Re: Can't use std.algorithm.remove on a char[]?

2016-04-30 Thread ag0aep6g via Digitalmars-d-learn
On 30.04.2016 21:08, Jon D wrote: If an initial step is to fix the documentation, it would be helpful to include specifically that it doesn't work with characters. It's not obvious that characters don't meet the requirement. Characters are not the problem. remove works fine on a range of

Re: Can't use std.algorithm.remove on a char[]?

2016-04-30 Thread ag0aep6g via Digitalmars-d-learn
On 30.04.2016 18:44, TheGag96 wrote: I was just writing some code trying to remove a value from a character array, but the compiler complained "No overload matches for remove", and if I specifically say use std.algorithm.remove() the compiler doesn't think it fits any definition. For reference,

Re: Can't use std.algorithm.remove on a char[]?

2016-04-30 Thread ag0aep6g via Digitalmars-d-learn
On 30.04.2016 21:41, Jon D wrote: I didn't mean to suggest making the documentation technically incorrect. Just that it be helpful in important cases that won't necessarily be obvious. To me, char[] is an important case, one that's not made obvious by listing the hasLvalueElements constraint by

Re: mutable keyword

2016-05-20 Thread ag0aep6g via Digitalmars-d-learn
On 05/20/2016 08:23 PM, Jack Applegame wrote: You can just cast const away: struct A { int id = 0; this(int id) { this.id = id; } void change() const { (cast() id)++; } } That's not a valid D program, though.

Re: Dub selects wrong version

2016-05-20 Thread ag0aep6g via Digitalmars-d-learn
On 05/21/2016 06:54 AM, Bauss wrote: When I then compile with dub build I get this error: Selected package diamond 0.1.0 does not match the dependency specification >=0.2.1 <0.3.0 in package diamondtest. Need to "dub upgrade"? Have you tried "dub upgrade"?

Re: Dub selects wrong version

2016-05-20 Thread ag0aep6g via Digitalmars-d-learn
On 05/21/2016 07:15 AM, Bauss wrote: On Saturday, 21 May 2016 at 05:03:14 UTC, ag0aep6g wrote: On 05/21/2016 06:54 AM, Bauss wrote: When I then compile with dub build I get this error: Selected package diamond 0.1.0 does not match the dependency specification >=0.2.1 <0.3.0 in package

Re: Is NullableRef checked at compile time?

2016-05-23 Thread ag0aep6g via Digitalmars-d-learn
On 05/23/2016 08:10 PM, cy wrote: I was squinting at the std.typecons.NullableRef code and it _looks_ like isNull is only checked at runtime (and not checked at all in release mode!) but D has surprised me before in its ability to pre-calculate stuff during compilation. NullableRef is little

Re: std.conv.parse not accepting ByCodeUnitImpl

2016-05-23 Thread ag0aep6g via Digitalmars-d-learn
On 05/24/2016 03:59 AM, Jack Stouffer wrote: parse!int(splitValue.front); [...] std.conv.parse(Target, Source)(ref Source s) if ( isSomeChar!(ElementType!Source) && isIntegral!Target && !is(Target == enum)) You're missing that `parse`'s parameter is `ref`. `splitValue.front` is

Re: ErrorException thrown when errno is modified ?

2016-05-19 Thread ag0aep6g via Digitalmars-d-learn
On 05/19/2016 03:05 PM, chmike wrote: I'm planning to call some posix functions core.sys.posix that may set the errno value in case of error. e.g. read() or write(). Checking the std.exception documentation I see that ErrnoException may be thrown when errors setting errno may occur. Does this

Re: Using -O with DMD seems to produce non-random values.

2016-05-19 Thread ag0aep6g via Digitalmars-d-learn
On 05/19/2016 05:09 PM, Michael wrote: Any idea what causes this to occur when optimising? I wanted to try and speed up a simulation I'm running but it just produces too many unexpected consequences. I suspect that you're seeing issue 16027 [1], a bad bug in 2.071.0. The upcoming 2.071.1

Re: static member and/or @property ?

2016-05-19 Thread ag0aep6g via Digitalmars-d-learn
On 05/19/2016 05:04 PM, chmike wrote: interface AThing { ??? string name ??? } class OneThing : AThing { ??? string name ??? "OneThing" ??? } class OtherThing : AThing { ??? string name ??? "OtherThing" ??? } void main() { // Accessing name as static information writeln(OneThing.name

  1   2   3   4   5   6   7   >