Re: Changing by ref a class passed in function

2015-01-22 Thread anonymous via Digitalmars-d-learn
On Thursday, 22 January 2015 at 13:06:42 UTC, Zaher Dirkey wrote: See example bellow, i want to pass object to function nullIt and want this function to null it. import std.stdio; static if (!is(typeof(writeln))) alias writefln writeln; class MyClass{ } void

Re: Changing by ref a class passed in function

2015-01-22 Thread anonymous via Digitalmars-d-learn
On Thursday, 22 January 2015 at 14:29:59 UTC, anonymous wrote: o needs to be typed as Object: Object o = new MyClass(); nullIt(o); Alternatively, templatize nullIt: void nullIt(O)(ref O o) {o = null;} auto o = new MyClass(); nullIt(o);

Re: What to do with InvalidMemoryOperationError

2015-01-21 Thread anonymous via Digitalmars-d-learn
On Wednesday, 21 January 2015 at 15:34:35 UTC, Per Nordlöw wrote: On Wednesday, 21 January 2015 at 14:50:06 UTC, Ali Çehreli wrote: Known bug with a pull request: https://issues.dlang.org/show_bug.cgi?id=13856 Here is the duplicate of it, which I've opened recently:

Re: What to do with InvalidMemoryOperationError

2015-01-21 Thread anonymous via Digitalmars-d-learn
On Wednesday, 21 January 2015 at 13:07:11 UTC, Nordlöw wrote: On Wednesday, 21 January 2015 at 12:10:20 UTC, Nordlöw wrote: On Wednesday, 21 January 2015 at 12:00:47 UTC, Nordlöw wrote: My executable throws as core.exception.InvalidMemoryOperationError@(0) I've tracked it down to being

Re: How can I convert the following C to D.

2015-01-21 Thread anonymous via Digitalmars-d-learn
On Wednesday, 21 January 2015 at 23:44:52 UTC, anon wrote: I have the following C code, how can I do the same in D. Info **info; info = new Info*[hl + 2]; int r; for(r = 0; r hl; r++) { info[r] = new Info[vl + 2]; } info[r] = NULL; anon The super-literal translation: Info**

Re: Bug on Posix IPC_STAT. Wrong number of attachments

2015-01-19 Thread anonymous via Digitalmars-d-learn
On Monday, 19 January 2015 at 05:35:46 UTC, tcak wrote: Fixed shm.d file is put on issue page. If someone could put a pull request on Github with it. shmid_ds is on version(linux) part is fixed up on it, and works properly. But tested on 64-bit system only. Aand it's in:

Re: Bug on Posix IPC_STAT. Wrong number of attachments

2015-01-18 Thread anonymous via Digitalmars-d-learn
On Sunday, 18 January 2015 at 18:07:05 UTC, tcak wrote: After these, it works perfectly. I hope this can be fixed in next version. Please file a bug at https://issues.dlang.org/. And since you seem to know how to fix it, maybe you can make a pull request via GitHub, too?

Re: Struggling with shared objects

2015-01-17 Thread anonymous via Digitalmars-d-learn
On Saturday, 17 January 2015 at 21:00:34 UTC, Mike wrote: Hey, all. I have just started using D and I'm really loving it, but I have been caught on a problem. I am trying to share my Client class to a new thread, and after a bit of struggling: I finally got the code to compile! Now I am

building a simple json tree

2015-01-15 Thread anonymous via Digitalmars-d-learn
what's the right syntax for building a JSON tree ? I try to do like in an AA but the program throw because the Key doesn't exist: --- import std.stdio, std.json; void main(string[] args) { struct Foo{ string a, b; void writeToJson(ref JSONValue target) {

Re: building a simple json tree

2015-01-15 Thread anonymous via Digitalmars-d-learn
On Thursday, 15 January 2015 at 12:10:09 UTC, Rikki Cattermole wrote: On 16/01/2015 12:16 a.m., anonymous wrote: what's the right syntax for building a JSON tree ? I try to do like in an AA but the program throw because the Key doesn't exist: --- import std.stdio, std.json; void

Re: reinterpret array

2015-01-13 Thread anonymous via Digitalmars-d-learn
On Tuesday, 13 January 2015 at 20:00:57 UTC, Dominikus Dittes Scherkl wrote: So if I have a function that allowes to do this: uint a; a.bit[16] = true; writeln(a); // 65536 Is it also already available? a |= 1 16;

Re: reinterpret array

2015-01-13 Thread anonymous via Digitalmars-d-learn
On Tuesday, 13 January 2015 at 20:52:15 UTC, Dominikus Dittes Scherkl wrote: Of course you can calculate it, but the syntax looks quite different if you want to do a.bit[22] = false: a = ~(116); Or if you want to test a bit: if(a.bit[16]) instead of if(a (116)) much more convenient for

Re: Cast a struct to void*

2015-01-09 Thread anonymous via Digitalmars-d-learn
On Friday, 9 January 2015 at 18:25:42 UTC, John Colvin wrote: struct S { void* p; } void main() { S s; auto a = cast(void*)s; //Error: e2ir: cannot cast s of type S to type void* } Is there are a good reason for this being disallowed? You'd expect `cast(void*)s == s.p`? That

Re: idiomatic D: what to use instead of pointers in constructing a tree data structure?

2015-01-07 Thread anonymous via Digitalmars-d-learn
On Wednesday, 7 January 2015 at 20:25:10 UTC, Meta wrote: struct Tree { this(string data, Tree[] children...) { this.data = data; this.children = children; Don't do this without `dup`ing. Quoting the documentation: An implementation may construct the object or array

Re: Template function type inference with default arguments

2015-01-05 Thread anonymous via Digitalmars-d-learn
On Sunday, 4 January 2015 at 00:22:01 UTC, ixid wrote: Why don't templates take a type from the default argument if nothing else is supplied? https://issues.dlang.org/show_bug.cgi?id=2803

Re: Initialization of nested struct fields

2015-01-01 Thread anonymous via Digitalmars-d-learn
On Thursday, 1 January 2015 at 23:06:30 UTC, Peter Alexander wrote: Can someone please explain this behaviour? I find it totally bizarre. auto f(T)(T x) { struct S { T y; this(int) { } } return S(0); } void main() { f(f(0)); }

Re: How to create instance of class that get data from 2 another instance?

2015-01-01 Thread anonymous via Digitalmars-d-learn
On Thursday, 1 January 2015 at 22:15:52 UTC, Suliman wrote: I have instance of class, that need data from 2 another classes. So I decided that I need to create it only after I get the data from both instance. auto mysql = new MySQL(parseconfig, seismoDownload); // the problem is here! (LOC

Re: Problem with immutables and Template typeof(this)

2014-12-28 Thread anonymous via Digitalmars-d-learn
On Sunday, 28 December 2014 at 22:07:31 UTC, AuoroP via Digitalmars-d-learn wrote: I have been trying to figure templates out... template ExampleTemplate(T) { struct ExampleTemplate { T value; // constructor auto this(T value) Constructors don't have return

Re: Fastest Way to Append Multiple Elements to an Array

2014-12-19 Thread Anonymous via Digitalmars-d-learn
On Thursday, 18 December 2014 at 22:27:06 UTC, zeljkog wrote: On 18.12.14 14:50, Steven Schveighoffer wrote: I wonder how your code compares to this: void append(T)(ref T[] arr, T[] args...) { arr ~= args; } This is ~20% slower for ints, but it difference increases for bigger structs.

Re: Fastest Way to Append Multiple Elements to an Array

2014-12-19 Thread Anonymous via Digitalmars-d-learn
On Friday, 19 December 2014 at 15:25:46 UTC, Steven Schveighoffer wrote: On 12/18/14 5:27 PM, zeljkog wrote: On 18.12.14 14:50, Steven Schveighoffer wrote: I wonder how your code compares to this: void append(T)(ref T[] arr, T[] args...) { arr ~= args; } This is ~20% slower for ints,

Re: Fastest Way to Append Multiple Elements to an Array

2014-12-19 Thread Anonymous via Digitalmars-d-learn
On Friday, 19 December 2014 at 18:38:32 UTC, Steven Schveighoffer wrote: On 12/19/14 12:15 PM, Anonymous wrote: On Friday, 19 December 2014 at 15:25:46 UTC, Steven Schveighoffer wrote: This is surprising to me. Ho ho ho, this year he has brought your surprise sooner than expected...

Re: Fastest Way to Append Multiple Elements to an Array

2014-12-19 Thread anonymous via Digitalmars-d-learn
On Friday, 19 December 2014 at 14:41:07 UTC, Anonymous wrote: What a big surprise. If you make an array of struct, each item of your array has the length of the struct. structs a values. If you want to append a struct to an array just append a pointer to the struct: -- struct arg{uint

Re: Fastest Way to Append Multiple Elements to an Array

2014-12-19 Thread anonymous via Digitalmars-d-learn
On Saturday, 20 December 2014 at 00:15:21 UTC, MarcelDuchamp wrote: You've forget the array of ref version. (append the address of the first data) What array of ref version? Sounds like it would be a different data structure, which would be beyond the scope the topic. And adding S to an array

Re: Referring to alias parameters in a mixin template

2014-12-17 Thread anonymous via Digitalmars-d-learn
On Wednesday, 17 December 2014 at 02:34:16 UTC, aldanor wrote: On Wednesday, 17 December 2014 at 02:12:52 UTC, anonymous wrote: Sure, straight forward: mixin template makeProperty(T, string name, alias func) { mixin(T %s() @property { return func(); }.format(name)); }

Re: Referring to alias parameters in a mixin template

2014-12-17 Thread anonymous via Digitalmars-d-learn
On Wednesday, 17 December 2014 at 15:40:25 UTC, aldanor wrote: On Wednesday, 17 December 2014 at 12:49:10 UTC, anonymous wrote: [...] As to if there were `T` or `func` in the target scope, they'd be shadowed by the template parameters, no matter if there's a string mixin or not. That makes

Re: Referring to alias parameters in a mixin template

2014-12-16 Thread anonymous via Digitalmars-d-learn
On Wednesday, 17 December 2014 at 01:14:36 UTC, aldanor wrote: A partial solution would be something like this: mixin template makeProperty(T, string name, alias func) { enum p = makeUnnamedProperty!(T, func); mixin(enum %s = p;.format(name)); // or alias } however now

Re: Referring to alias parameters in a mixin template

2014-12-16 Thread anonymous via Digitalmars-d-learn
On Wednesday, 17 December 2014 at 01:49:14 UTC, aldanor wrote: Wonder if this is doable within a single mixin template without using makeUnnamedProperty? Sure, straight forward: mixin template makeProperty(T, string name, alias func) { mixin(T %s() @property { return func();

Re: mixin template and const property qualifier?

2014-12-15 Thread anonymous via Digitalmars-d-learn
On Monday, 15 December 2014 at 23:14:30 UTC, aldanor wrote: Could someone please explain why the following doesn't compile with const qualifier while it does work without it? /* test.d */ module test; mixin template Foo() { mixin(@property int bar() const { return foo; }); } int foo =

Re: Fastest Way to Append Multiple Elements to an Array

2014-12-14 Thread anonymous via Digitalmars-d-learn
On Sunday, 14 December 2014 at 23:52:15 UTC, zeljkog wrote: On 15.12.14 00:16, Nordlöw wrote: or some other trick? void append(T, Args...)(ref T[] arr, Args args){ arr.length += args.length; foreach(i, e; args) arr[$ - args.length + i] = args[i]; } void main() { int[] arr = [1, 2,

Re: Fast matrix struct

2014-12-14 Thread anonymous via Digitalmars-d-learn
On Sunday, 14 December 2014 at 22:14:55 UTC, Ryan wrote: I'm writing a Matrix struct that I plan to use for some number crunching, which will be intensive at times. So I want it to be fast. Will I do better by manually managing the memory myself with malloc and free in the

Re: How do i use std.functional.binaryFun?

2014-12-08 Thread anonymous via Digitalmars-d-learn
On Monday, 8 December 2014 at 20:08:35 UTC, Gary Willoughby wrote: import std.stdio; import std.functional; class Foo(T, alias greater = a b) if (is(typeof(binaryFun!(greater)(T.init, T.init)) == bool)) { private alias compare = binaryFun!(greater); public this() {

Re: Accented Characters and Counting Syllables

2014-12-07 Thread anonymous via Digitalmars-d-learn
On Saturday, 6 December 2014 at 22:37:19 UTC, Nordlöw wrote: Given the fact that static assert(é.length == 2); I was surprised that static assert(é.byCodeUnit.length == 2); static assert(é.byCodePoint.length == 2); string already iterates over code points. So byCodePoint doesn't

Re: What am I missing? Pure constructor behaves differently when assigning string member

2014-11-29 Thread anonymous via Digitalmars-d-learn
On Saturday, 29 November 2014 at 09:41:00 UTC, jostly wrote: I can't find a way to use a pure constructor to create both mutable and immutable instances of the same class, when one of the fields I assign is a string. [...] The question is: am I missing something that would make it possible to

Re: Casting in Safe D

2014-11-23 Thread anonymous via Digitalmars-d-learn
On Sunday, 23 November 2014 at 19:37:45 UTC, Nordlöw wrote: I just noticed that void foo() @safe pure nothrow { void[] void_array = new void[3]; auto ubyte_array = cast(ubyte[])void_array; auto short_array = cast(short[])void_array; } compiles but gives a object.Error@(0): array

Re: overiding mutable methods in immutable classes

2014-11-22 Thread anonymous via Digitalmars-d-learn
On Saturday, 22 November 2014 at 02:37:21 UTC, Eric wrote: I know I can make a class immutable, but the problem is I want to constrain a template parameter to only immutable types, and I want to use class types. template Foo(T : immutable Object) Accepts immutable(Object) and other immutable

Re: overiding mutable methods in immutable classes

2014-11-22 Thread anonymous via Digitalmars-d-learn
On Saturday, 22 November 2014 at 15:00:00 UTC, Eric wrote: Yes, but if I don't declare the class T as immutable, I don't think this constraint will work. You're mistaken. It works just fine. class X /* not immutable */ { private int x; this(int x) pure { this.x = x; } } template

Re: overiding mutable methods in immutable classes

2014-11-22 Thread anonymous via Digitalmars-d-learn
On Saturday, 22 November 2014 at 17:40:42 UTC, Eric wrote: Yes, but this is what I really want: class X(T : immutable Object) { private T x; this(T x) pure { this.x = x; } } class Y { private int x; this(int x) pure { this.x = x; } } void main() { immutable(Y) y = new

Re: how to compare the type of a subclass

2014-11-21 Thread anonymous via Digitalmars-d-learn
On Friday, 21 November 2014 at 22:15:37 UTC, Eric wrote: Suppose I have: module test; class X { } class Y : X { } Y y = new Y; X x = y; assert(is(typeof(x) == test.Y); // this assertion will fail assert(typeid(x).toString() == test.Y); // this assertion will pass Is there a way I can

Re: how to compare the type of a subclass

2014-11-21 Thread anonymous via Digitalmars-d-learn
On Friday, 21 November 2014 at 22:30:52 UTC, Eric wrote: On Friday, 21 November 2014 at 22:25:32 UTC, anonymous wrote: On Friday, 21 November 2014 at 22:15:37 UTC, Eric wrote: [...] class X { } class Y : X { } Y y = new Y; X x = y; [...] I have't quite mastered the whole is/typeof/typeid

Re: overiding mutable methods in immutable classes

2014-11-21 Thread anonymous via Digitalmars-d-learn
On Saturday, 22 November 2014 at 00:24:39 UTC, Eric wrote: immutable class X { private int x; this(int x) { this.x = x; } ... override size_t toHash(); // error: can't override mutable method } Since toHash() cannot be overridden in an immutable class, is there a work-around?

Re: Compiler error with slices, .dup and ref Parameter

2014-11-20 Thread anonymous via Digitalmars-d-learn
On Thursday, 20 November 2014 at 09:20:34 UTC, Ali Çehreli wrote: Judging from the name init(), I don't think you need ref anyway. thanks for the explanation. I can't remove the ref because it is Main.init in gtkd. A simple solution is init(args) I just tried to remove a non-GTK argument (a

Re: Recursive template

2014-11-15 Thread anonymous via Digitalmars-d-learn
On Saturday, 15 November 2014 at 18:30:00 UTC, Eric wrote: Hi - I've never designed a recursive template before, but I think that would solve my problem. What I would like is someting like this: class X(V, K...) { // I want to declare a type based on K and V such // that for X!(V,

Re: Delegates and C function pointers

2014-11-08 Thread anonymous via Digitalmars-d-learn
On Saturday, 8 November 2014 at 12:23:45 UTC, Nicolas Sicard wrote: I would like to register a D delegate to a C API that takes a function pointer as a callback and a void* pointer to pass data to this callback. My solution is in http://dpaste.dzfl.pl/7d9b504b4b965. Is this code correct? Is

Re: std.array.array and immutable elements

2014-11-07 Thread anonymous via Digitalmars-d-learn
On Friday, 7 November 2014 at 14:57:56 UTC, ketmar via Digitalmars-d-learn wrote: `map` cannot return range with immutable elements, 'cause they are obviously generated by program, and therefore aren't immutable. That's not true. Runtime generated values can be immutable just fine. And it's

Re: Reading unicode string with readf (%s)

2014-11-04 Thread anonymous via Digitalmars-d-learn
On Monday, 3 November 2014 at 19:37:20 UTC, Ivan Kazmenko wrote: Hi! The following code does not correctly handle Unicode strings. - import std.stdio; void main () { string s; readf (%s, s); write (s); } - Example input (Test. in cyrillic): - Тест. -

Re: Pointer across threads

2014-11-04 Thread anonymous via Digitalmars-d-learn
On Tuesday, 4 November 2014 at 12:47:11 UTC, Chris wrote: The following struct DATA { short* data; size_t len; } // data and len are provided by a C function // ... auto data = mymodule.getSpeechData(); // cast to immutable, because of concurrency immutable short* tmp =

Re: Pointer across threads

2014-11-04 Thread anonymous via Digitalmars-d-learn
On Tuesday, 4 November 2014 at 14:36:19 UTC, Chris wrote: I'm still curious, though, how D handles this internally, because data.data is still mutable while the other reference to the same address (tmp) is not. What if I change data.data while the other thread is being executed? Changing

Re: shallow copy of const(Object)[]

2014-11-02 Thread anonymous via Digitalmars-d-learn
On Sunday, 2 November 2014 at 00:33:53 UTC, Jonathan M Davis via Digitalmars-d-learn wrote: If you want to make sure that a dynamic array refers to new memory and is not a slice of another one, then you'd typically use dup or idup, and in almost all cases, that's exactly what you want. However,

Re: shallow copy of const(Object)[]

2014-11-01 Thread anonymous via Digitalmars-d-learn
On Saturday, 1 November 2014 at 00:08:23 UTC, Jonathan M Davis via Digitalmars-d-learn wrote: So, by shallow copy, you mean that you want an array that contains the same elements but is a new array? yes If that's what you want, just slice the array. auto b = a[]; This is the same as

Re: pop popFront combined

2014-11-01 Thread anonymous via Digitalmars-d-learn
On Saturday, 1 November 2014 at 13:22:34 UTC, Nordlöw wrote: On Saturday, 1 November 2014 at 11:45:25 UTC, Nordlöw wrote: So why isn't something like x.stealFront already in Phobos? First try here: https://github.com/nordlow/justd/blob/master/range_ex.d#L14 Please comment! That is: auto

Re: pop popFront combined

2014-11-01 Thread anonymous via Digitalmars-d-learn
On Saturday, 1 November 2014 at 13:25:03 UTC, Nordlöw wrote: On Saturday, 1 November 2014 at 13:22:34 UTC, Nordlöw wrote: https://github.com/nordlow/justd/blob/master/range_ex.d#L14 Please comment! What's the recommended way of making stealFront and stealBack inout here? Can I somehow use

Re: pop popFront combined

2014-11-01 Thread anonymous via Digitalmars-d-learn
On Saturday, 1 November 2014 at 13:36:05 UTC, Marc Schütz wrote: On Saturday, 1 November 2014 at 13:30:16 UTC, anonymous wrote: [...] auto ref stealFront(R)(ref R r) { import std.range: moveFront, popFront; auto e = r.moveFront; r.popFront; return e; } [...] It's probably intended to mean

Re: pop popFront combined

2014-11-01 Thread anonymous via Digitalmars-d-learn
On Saturday, 1 November 2014 at 14:01:42 UTC, Nordlöw wrote: On Saturday, 1 November 2014 at 13:36:05 UTC, anonymous wrote: I don't see what you'd need inout for here. stealFront/stealBack are not methods. inout can be used on free functions aswell. See for example

shallow copy of const(Object)[]

2014-10-31 Thread anonymous via Digitalmars-d-learn
I have a const(Object)[] and I want a shallow copy of the array. .dup doesn't do it, which I thought a bug, but according to Martin Nowak it's by design [1]. std.array.array fails, too. Is there really nothing in phobos for this? static import std.array; void main() { const(Object)[] a;

Re: alias and extern(C)

2014-10-30 Thread anonymous via Digitalmars-d-learn
On Thursday, 30 October 2014 at 18:43:21 UTC, Laeeth Isharc wrote: The code below works fine if you remove the extern(C). But I get the error functionpointertest.d(6): Error: basic type expected, not extern with the code as it is. How do I use alias with extern ? [...] alias Callback=

Re: Equivalent in D for .p2align 4,,15 ?

2014-10-29 Thread anonymous via Digitalmars-d-learn
On Wednesday, 29 October 2014 at 17:16:23 UTC, Etienne wrote: I'm looking for the D inline assembler equivalent of the .p2align 4,,15 directive to optimize a loop. Here's more information: http://stackoverflow.com/questions/21546946/what-p2align-does-in-asm-code I tried searching through a

Re: Using imm8 through inline assembler

2014-10-28 Thread anonymous via Digitalmars-d-learn
On Tuesday, 28 October 2014 at 21:05:15 UTC, Etienne wrote: I'm trying to write (in DMD) the assembler that handles the function : __m256i _mm256_permute4x64_epi64(__m256i a, in int M); This translates to vpermq The closest thing I could find in DMD assembly is VPERMILPS, which is called

Re: Need assistance translating this C++ template

2014-10-27 Thread anonymous via Digitalmars-d-learn
On Monday, 27 October 2014 at 22:43:23 UTC, John wrote: The C++ code: // Bitfield utilities templateunsigned bitno, unsigned nbits=1, typename T=u8 struct RegBit { [...] templatetypename T2 RegBit operator=(T2 val) [...] }; My D implementation thus far: [...] template RegBit(uint

Re: Creation of 0MQ D project

2014-10-27 Thread anonymous via Digitalmars-d-learn
On Monday, 27 October 2014 at 23:56:11 UTC, Evan Lowry wrote: ../../.dub/packages/zeromq-master/deimos/zmq/zmq.d(96): Error: function deimos.zmq.zmq.zmq_strerror without 'this' cannot be const You found a bug in the binding. Line 96 of zmq.d [1]: const char* zmq_strerror(int errnum); Should

Re: forum.dlang.org open source?

2014-10-26 Thread anonymous via Digitalmars-d-learn
On Sunday, 26 October 2014 at 23:57:41 UTC, Mike wrote: Does forum.dlang.org have an open source repository somewhere that we can contribute pull requests to, or are bug reports to recommended procedure. http://forum.dlang.org/help#contributing

Re: passing non-dynamic arrays to variadic functions

2014-10-26 Thread anonymous via Digitalmars-d-learn
On Monday, 27 October 2014 at 00:26:00 UTC, ketmar via Digitalmars-d-learn wrote: Hello. let's assume we have this code: void doWrite(A...) (A args) { import std.stdio; import std.conv; writeln(to!string(args[0])); } void main () { char[3] a0 = abc; char[3] a1 =

Re: parser bug?

2014-10-23 Thread anonymous via Digitalmars-d-learn
On Thursday, 23 October 2014 at 18:15:26 UTC, Charles Hixson via Digitalmars-d-learn wrote: The code: voidgo(ulongrecNum) {assert (buf[0] == (fh.sizeof + recNo * buf.length) 0x7f); if(dirty) yields the error message: ells$ dmd test.d test.d(78): Error:

Re: std.stdio breaks casting operation

2014-10-23 Thread anonymous via Digitalmars-d-learn
On Thursday, 23 October 2014 at 18:43:54 UTC, tcak wrote: Then I change the Test.setIt method as follows: import std.stdio; s = cast( typeof( s ) )sock; Error on s = cast... line: cannot cast module socket of type void to shared(Socket) Apparently std.stdio

Re: Bug?

2014-10-23 Thread anonymous via Digitalmars-d-learn
On Thursday, 23 October 2014 at 21:17:25 UTC, deed wrote: Some testing can be found on http://dpaste.dzfl.pl/5f55f4152aa8 for both Windows and Linux. This just illustrates the sin function. I think the tests marked [1] are expected to fail. They involve converting one operand of the

Re: Bug?

2014-10-23 Thread anonymous via Digitalmars-d-learn
On Thursday, 23 October 2014 at 21:42:46 UTC, anonymous wrote: On Thursday, 23 October 2014 at 21:17:25 UTC, deed wrote: Some testing can be found on http://dpaste.dzfl.pl/5f55f4152aa8 for both Windows and Linux. This just illustrates the sin function. I think the tests marked [1] are

Re: Destructor order

2014-10-22 Thread anonymous via Digitalmars-d-learn
On Wednesday, 22 October 2014 at 15:45:02 UTC, eles wrote: D version: { //displays ~A~B~C A foo = scoped!(A)(); B bar = scoped!(B)(); C caz = new C(); destroy(caz); } Why the objects are not destroyed in the inverse order of their

Re: Global const variables

2014-10-21 Thread anonymous via Digitalmars-d-learn
On Tuesday, 21 October 2014 at 12:08:35 UTC, Solomon E wrote: On Tuesday, 21 October 2014 at 08:48:09 UTC, safety0ff wrote: const int[] a; int[] b; static this() { b = [1]; a = b; } `a` isn't a reference to `b`. `a` is assigned by value and has its own storage. `a` is indeed a copy

Re: Really in need of help with std.container.array.d

2014-10-20 Thread anonymous via Digitalmars-d-learn
On Sunday, 19 October 2014 at 22:19:05 UTC, Nordlöw wrote: https://github.com/nordlow/phobos/commit/ce6b9e9ae600b7c28ecddd1e3af7b1516247fb33 now errors as array.d(927,15): Error: None of the overloads of 'opSlice' are callable using a const object, candidates are: array.d(472,25):

Re: Really in need of help with std.container.array.d

2014-10-20 Thread anonymous via Digitalmars-d-learn
On Monday, 20 October 2014 at 11:20:30 UTC, Nordlöw wrote: On Monday, 20 October 2014 at 10:56:43 UTC, anonymous wrote: On Sunday, 19 October 2014 at 22:19:05 UTC, Nordlöw wrote: By the way, since we're in D.learn, I'm assuming you want to do this yourself. But if you'd like, I could make a

Re: Really in need of help with std.container.array.d

2014-10-19 Thread anonymous via Digitalmars-d-learn
On Wednesday, 15 October 2014 at 21:15:14 UTC, Nordlöw wrote: https://github.com/nordlow/phobos/commit/9daf235d7091f76cd941e29e3c167d559bf56a94 but that triggers a new interesting suite of errors Error: mutable method std.container.array.Array!int.Array.__fieldPostBlit is not callable using

Re: Really in need of help with std.container.array.d

2014-10-19 Thread anonymous via Digitalmars-d-learn
On Sunday, 19 October 2014 at 18:58:50 UTC, Nordlöw wrote: On Sunday, 19 October 2014 at 15:21:02 UTC, anonymous wrote: version(none) _outer = data; /* Error: mutable method [...].Array.opAssign is not callable using a const object */ What do these comments

Re: Really in need of help with std.container.array.d

2014-10-19 Thread anonymous via Digitalmars-d-learn
On Sunday, 19 October 2014 at 19:30:40 UTC, Nordlöw wrote: On Sunday, 19 October 2014 at 19:13:33 UTC, anonymous wrote: Yes, they don't compile. It's three slightly different versions of initializing _outer. The first one, `_outer = data;`, is the original one. It's understandable that it

Re: Really in need of help with std.container.array.d

2014-10-19 Thread anonymous via Digitalmars-d-learn
On Sunday, 19 October 2014 at 20:10:33 UTC, Nordlöw wrote: Used your ideas here https://github.com/nordlow/phobos/commit/be6b5f8c4d428a9708a52757a3f31aab6878d379 but unittests now fails as array.d(234,13): Error: mutable method std.container.array.Array!int.Array.opAssign is not callable

Re: Really in need of help with std.container.array.d

2014-10-19 Thread anonymous via Digitalmars-d-learn
On Sunday, 19 October 2014 at 20:39:18 UTC, anonymous wrote: Spell the type out or use `typeof(result)`. Should be `typeof(return)`.

Re: Really in need of help with std.container.array.d

2014-10-19 Thread anonymous via Digitalmars-d-learn
On Sunday, 19 October 2014 at 15:21:02 UTC, anonymous wrote: struct RefCounted { this(this) /* const doesn't help */ {} ~this() /* const doesn't help */ {} } struct Array { RefCounted _data; } void main() {const Array a; const copy = a;} /* works */ struct RangeM {Array a;}

Re: Function parameters from TypeTuple

2014-10-17 Thread anonymous via Digitalmars-d-learn
On Friday, 17 October 2014 at 17:57:58 UTC, Tofu Ninja wrote: On Friday, 17 October 2014 at 17:44:48 UTC, Tofu Ninja wrote: Not sure if what I wrote made sense, instead I will just post the code that is vomiting on me... You forgot the imports. template arrayType(T) { alias

Re: Function parameters from TypeTuple

2014-10-17 Thread anonymous via Digitalmars-d-learn
On Friday, 17 October 2014 at 19:18:29 UTC, Tofu Ninja wrote: I had the imports, I just didn't post them. My problem is most likely that I used Tuple! instead of tuple... which is probably because the differences between the like 20(exaggeration) different types of tuples in D are confusing as

Re: Mixin template functions are ignored in struct

2014-10-14 Thread anonymous via Digitalmars-d-learn
On Tuesday, 14 October 2014 at 20:58:19 UTC, tcak wrote: I have written a struct and a mixin template, and that mixin template is mixed into that struct as follows. private mixin template TestCommonMethods(){ public bool apply( int d, int e ){ return false; } }

Re: how to call class' template constructor

2014-10-12 Thread anonymous via Digitalmars-d-learn
On Sunday, 12 October 2014 at 19:46:41 UTC, ketmar via Digitalmars-d-learn wrote: Hello. please, how to call template constructor of a class? it's completely escaped my mind. i.e. i have this class: class A { this(alias ent) (string name) { ... } } and i want to do:

Re: Using inline assembler

2014-10-09 Thread anonymous via Digitalmars-d-learn
On Thursday, 9 October 2014 at 12:37:20 UTC, Etienne wrote: I'm a bit new to the inline assembler, I'm trying to use the `movdqu` operation to move a 128 bit double quadword from a pointer location into another location like this: align(16) union __m128i { ubyte[16] data }; void

Re: Using inline assembler

2014-10-09 Thread anonymous via Digitalmars-d-learn
On Thursday, 9 October 2014 at 13:29:27 UTC, Etienne wrote: On 2014-10-09 8:54 AM, anonymous wrote: This compiles: align(16) union __m128i { ubyte[16] data; } /* note the position of the semicolon */ void store(__m128i* src, __m128i* dst) { asm { movdqu XMM0, [src]; /*

Re: (this MyType) and interface: Symbol undefined

2014-10-08 Thread anonymous via Digitalmars-d-learn
On Wednesday, 8 October 2014 at 13:00:56 UTC, andre wrote: Hi, please consider following example. I want to acces class B by interface I. Method work should print the actual class (B). The linker say: Error 42: Symbol Undefined _D3app1I17__T4workTC3app1IZ4workMFZv Is this is missing

Re: (this MyType) automatic deduction?

2014-10-08 Thread anonymous via Digitalmars-d-learn
On Wednesday, 8 October 2014 at 10:36:33 UTC, andre wrote: Hi, could you check whether it is correct, that second line in main failes with a compiler error? I think the compiler should be able to deduce the type without explicitly passing it to the method call. Kind regards André template

Re: Formatted output of range of tuples

2014-10-08 Thread anonymous via Digitalmars-d-learn
On Wednesday, 8 October 2014 at 21:21:47 UTC, antropod wrote: Hello! Consider this code: +++ import std.stdio; import std.range; import std.algorithm; void printIndexedArray1(T, Range)(T[] source, Range indexes) { foreach(row; zip(indexes, source)) {

Re: How to detect start of Unicode symbol and count amount of graphemes

2014-10-06 Thread anonymous via Digitalmars-d-learn
On Monday, 6 October 2014 at 17:28:45 UTC, Uranuz wrote: ( str[index] 0b1000 ) == 0 || ( str[index] 0b1110 ) == 0b1100 || ( str[index] 0b ) == 0b1110 || ( str[index] 0b1000 ) == 0b If it is true it means that first byte of sequence found and I can count

Re: How do I check if a function got CTFE?

2014-10-02 Thread anonymous via Digitalmars-d-learn
On Thursday, 2 October 2014 at 17:56:29 UTC, AsmMan wrote: I'd like to check if a function got CTFE, ie, the compiler was able to replace my foo(s); by the computed value at compile-time. I'm trying to convert the binary executable to assembly by using objconv tool but I'm finding it very

Re: How do I check if a function got CTFE?

2014-10-02 Thread anonymous via Digitalmars-d-learn
On Thursday, 2 October 2014 at 18:42:56 UTC, AsmMan wrote: I was thiking the dmd compiler did CTFE without someone ask for this, in the way as I've mentioned, checking for constant arguments + function's purity and if all this is true, it did the CTFE rather than generate code to compute it at

Re: find all public properties at compile time

2014-09-30 Thread anonymous via Digitalmars-d-learn
On Tuesday, 30 September 2014 at 20:04:29 UTC, gedaiu wrote: [sorry... this is the edit for the prev post] Thank you for your response! I don't think that it helps me... I wanted to get an array like this [ a, b, c ] for this class class test { int a; string b; double c; } import

Re: Recursive function call

2014-09-24 Thread anonymous via Digitalmars-d-learn
On Wednesday, 24 September 2014 at 10:57:27 UTC, Suliman wrote: string getFileName() { [...] getFilename(); //I need something similar, to call function again. You mistyped the function name, it's getFileName (capital N), and you forgot return. So: return getFileName();

Re: parallel foreach hangs

2014-09-22 Thread anonymous via Digitalmars-d-learn
On Monday, 22 September 2014 at 11:25:53 UTC, Daniel Kozak wrote: this code never end import std.stdio; import std.file; import std.parallelism : parallel; import std.algorithm : filter; void main(string[] args) { foreach(d; parallel(args[1 .. $], 1)) { auto phpFiles =

Re: Cannot deduce from type

2014-09-22 Thread anonymous via Digitalmars-d-learn
On Monday, 22 September 2014 at 14:45:31 UTC, Chris wrote: Why is that? import std.stdio, std.array void main() { auto output = appender!(string); output ~= world!; // output.data.insertInPlace(0, Hello, ); // Doesn't work auto asString = output.data; asString.insertInPlace(0, Hello,

Re: regex problems

2014-09-20 Thread anonymous via Digitalmars-d-learn
On Saturday, 20 September 2014 at 15:28:54 UTC, seany wrote: In haystack, there are two such ID : -s. once at the beginning, ID : generateWorld. and then the final, last ID However, this is returning all 5 ID-s as match what am I doing wrong? Prints ID : ID : for me. I'd advise against

Re: String[] pointer to void* and back

2014-09-19 Thread anonymous via Digitalmars-d-learn
On Friday, 19 September 2014 at 12:14:19 UTC, seany wrote: On Thursday, 18 September 2014 at 22:16:48 UTC, Ali Çehreli wrote: If you are holding an address in a void*, you must make sure that the original object is still at that location when you attempt to access the object. Does that

Re: String[] pointer to void* and back

2014-09-18 Thread anonymous via Digitalmars-d-learn
On Thursday, 18 September 2014 at 21:35:50 UTC, seany wrote: Yes, thank you, I corrected that. However, if this v is a member of a class, like import std.stdio; import std.conv; import core.vararg; struct S { void *v; } class C { S* sx = new S; void dothings() {

Re: Why does this not work?

2014-09-17 Thread anonymous via Digitalmars-d-learn
On Wednesday, 17 September 2014 at 13:20:15 UTC, Shachar wrote: On Wednesday, 17 September 2014 at 13:03:05 UTC, flamencofantasy wrote: the result of ubyte + ubyte is int I believe. Try; void func( int c ) { ubyte a; a = cast(ubyte)(cast(ubyte)c + cast(ubyte)c); } From

Re: How to cast to void*, while bypassing alias this or opCast

2014-08-28 Thread anonymous via Digitalmars-d-learn
On Thursday, 28 August 2014 at 10:45:52 UTC, monarch_dodra wrote: I'm investigating a phobos regression. From doesPointTo: // static if (isPointer!S || is(S == class) || is(S == interface)) { const m = cast(void*) source; // Basically, given a pointer like structure,

Re: Is this a bug when creating proxies in classes?

2014-08-28 Thread anonymous via Digitalmars-d-learn
On Tuesday, 26 August 2014 at 18:13:52 UTC, Gary Willoughby wrote: With that in mind what is strange is that if in my example you change the class for a struct everything works as expected. Why is that? That's because when not mixed into a class, Proxy did import std.traits: static if

Re: Building library

2014-08-28 Thread anonymous via Digitalmars-d-learn
On Thursday, 28 August 2014 at 19:29:40 UTC, papaboo wrote: My current file and module layout is test.d src/math/vector.d - module dragonfly.math.vector src/math/quaternion.d - module dragonfly.math.quaternion Compiling with $ dmd test.d src/math/vector.d src/math/quaternion.d ./test works

Re: Error: template cannot deduce function from argument types.

2014-08-24 Thread anonymous via Digitalmars-d-learn
On Sunday, 24 August 2014 at 02:53:41 UTC, Damian Day wrote: Hi, I've been trying to reduce a bug in the containers (8824). From the example below it seems the dup method is passing the constructor an array of dchars and the template is failing. Is this a compiler bug, or ? import

Re: std.stdio.tmpfile() return shared(_IO_FILE)* and not File

2014-08-24 Thread anonymous via Digitalmars-d-learn
On Sunday, 24 August 2014 at 17:55:05 UTC, simendsjo wrote: Using DMD 2.066 on GNU/Linux x86_64. This is strange: import std.stdio; void main() { auto f = tmpfile(); pragma(msg, typeof(f)); // shared(_IO_FILE)* } But stdio.d looks like the following: static File tmpfile() @safe

<    1   2   3   4   5   6   >