Re: Ownership semantics

2016-01-31 Thread Matt Elkins via Digitalmars-d-learn
On Sunday, 31 January 2016 at 20:10:03 UTC, Matt Elkins wrote: On Sunday, 31 January 2016 at 20:07:26 UTC, Steven Schveighoffer wrote: What is likely happening is that ptr is already collected, and you are invalidly attempting to re-free it. The GC can collect this memory even though there is

Re: Ownership semantics

2016-01-31 Thread Matt Elkins via Digitalmars-d-learn
On Sunday, 31 January 2016 at 20:07:26 UTC, Steven Schveighoffer wrote: What is likely happening is that ptr is already collected, and you are invalidly attempting to re-free it. The GC can collect this memory even though there is still an outstanding root-reachable pointer to it?

Re: Ownership semantics

2016-01-31 Thread maik klein via Digitalmars-d-learn
On Sunday, 31 January 2016 at 20:20:52 UTC, Steven Schveighoffer wrote: On 1/31/16 3:15 PM, Matt Elkins wrote: On Sunday, 31 January 2016 at 20:11:07 UTC, Matt Elkins wrote: On Sunday, 31 January 2016 at 20:10:03 UTC, Matt Elkins wrote: On Sunday, 31 January 2016 at 20:07:26 UTC, Steven

Re: Ownership semantics

2016-01-31 Thread Matt Elkins via Digitalmars-d-learn
On Sunday, 31 January 2016 at 20:20:52 UTC, Steven Schveighoffer wrote: Oh, nevermind. This is actually simpler. You can't do memory operations inside a destructor during collection. I forgot about that. But the rule I stated is still in force. -Steve So this implies that the UniquePtr

Re: how do I tell if something is lvalue?

2016-01-31 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/31/16 4:48 PM, Meta wrote: This seems to do the trick, although I haven't extensively tested it. There's probably a simpler way but this is the first thing I could come up with that works. Thanks! I was surprised this is not straightforward. -Steve

Re: how do I tell if something is lvalue?

2016-01-31 Thread Meta via Digitalmars-d-learn
On Sunday, 31 January 2016 at 22:11:45 UTC, Steven Schveighoffer wrote: On 1/31/16 4:48 PM, Meta wrote: This seems to do the trick, although I haven't extensively tested it. There's probably a simpler way but this is the first thing I could come up with that works. Thanks! I was

Re: Unterminated format specifier exception keeps occuring and I don't know why.

2016-01-31 Thread Enjoys Math via Digitalmars-d-learn
On Sunday, 31 January 2016 at 19:51:34 UTC, Enjoys Math wrote: On Sunday, 31 January 2016 at 19:40:15 UTC, Enjoys Math wrote: This weird exception keeps occuring and visual D is not bringing me to the place in my code that might be calling it. [...] The exception is not listed in the

How to implement to!T(JSONValue)?

2016-01-31 Thread crimaniak via Digitalmars-d-learn
Hi! I need to read bad-formed json files in type-tolerant mode, and my idea is to make JSONValue-specific 'to' method which will convert it to target type if applicable, else throw exception. Like this: import std.json; unittest { JSONValue s="123"; JSONValue i=123; JSONValue

Declaring rvalue function arguments

2016-01-31 Thread Matt Elkins via Digitalmars-d-learn
I know I can mark an argument ref to require lvalues, so I'm wondering whether there is an equivalent for rvalues; that is, is there a way to specify that an argument to a function MUST be an rvalue? For example, in C++ I can do this: [code] void foo(int && x) {...} foo(5); // Works fine int

Re: Declaring rvalue function arguments

2016-01-31 Thread maik klein via Digitalmars-d-learn
On Sunday, 31 January 2016 at 17:42:19 UTC, anonymous wrote: On 31.01.2016 18:21, Matt Elkins wrote: I know I can mark an argument ref to require lvalues, so I'm wondering whether there is an equivalent for rvalues; that is, is there a way to specify that an argument to a function MUST be an

Re: Declaring rvalue function arguments

2016-01-31 Thread Matt Elkins via Digitalmars-d-learn
Errr, ignore the makeFoo() line. Left that in by accident, has no bearing on the issue.

Re: Ownership semantics

2016-01-31 Thread Matt Elkins via Digitalmars-d-learn
On Sunday, 31 January 2016 at 19:34:43 UTC, maik klein wrote: I recently asked a question about ownership semantics in D https://stackoverflow.com/questions/35115702/how-do-i-express-ownership-semantics-in-d But a few minutes ago I found an answer on SO that could potentially explain a lot.

Re: Declaring rvalue function arguments

2016-01-31 Thread Matt Elkins via Digitalmars-d-learn
On Sunday, 31 January 2016 at 18:02:19 UTC, Matt Elkins wrote: Here is the one I am using right now: Actually, here is the whole module in case you are interested in the unittests/usage: [code] import std.algorithm; import std.traits; struct ResourceHandle(T, alias Deleter, T Default =

casting & templates

2016-01-31 Thread Robert M. Münch via Digitalmars-d-learn
I have: class OperatorV(T) : Value { T impl; this(T impl) { this.impl = impl; } ... and use it like this: makeOperator((IntV a, IntV b) => new IntV(a.num + b.num)); Now I want to do: opWord.get() returns a Value OperatorV *op = cast(OperatorV*)(opWord.get()); and get: Error: class

Unterminated format specifier exception keeps occuring and I don't know why.

2016-01-31 Thread Enjoys Math via Digitalmars-d-learn
This weird exception keeps occuring and visual D is not bringing me to the place in my code that might be calling it. Message: First-chance exception: std.format.FormatException Unterminated format specifier: "%" at C:\D\dmd2\windows\bin\..\..\src\phobos\std\format.d(830) I've gotten rid

Re: Ownership semantics

2016-01-31 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/31/16 2:34 PM, maik klein wrote: I recently asked a question about ownership semantics in D https://stackoverflow.com/questions/35115702/how-do-i-express-ownership-semantics-in-d But a few minutes ago I found an answer on SO that could potentially explain a lot.

how do I tell if something is lvalue?

2016-01-31 Thread Steven Schveighoffer via Digitalmars-d-learn
struct S { int x; ref int y() { return x; } int z() { return 1; } } What can I use, given S, to determine that x and y yield lvalues, while z yields an rvalue? I was expecting something like isLvalue somewhere, but cannot find it. __traits(isRef, ...) doesn't work. -Steve

Re: Unterminated format specifier exception keeps occuring and I don't know why.

2016-01-31 Thread Enjoys Math via Digitalmars-d-learn
On Sunday, 31 January 2016 at 19:40:15 UTC, Enjoys Math wrote: This weird exception keeps occuring and visual D is not bringing me to the place in my code that might be calling it. [...] The exception is not listed in the Exception Settings checkable list. I will try commenting out the D

Re: Ownership semantics

2016-01-31 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/31/16 3:15 PM, Matt Elkins wrote: On Sunday, 31 January 2016 at 20:11:07 UTC, Matt Elkins wrote: On Sunday, 31 January 2016 at 20:10:03 UTC, Matt Elkins wrote: On Sunday, 31 January 2016 at 20:07:26 UTC, Steven Schveighoffer wrote: What is likely happening is that ptr is already

Problem when calling toJSON()

2016-01-31 Thread Alex Herrmann via Digitalmars-d-learn
Hello all, I'm having a *really* weird problem (at least I think so). I have a function on a struct that converts it into JSON. Everything works, no big deal. But when I try to turn that JSONValue into a string, I get a UTF-8 Error. What makes it even weirder, is that if I call toJSON

Re: Declaring rvalue function arguments

2016-01-31 Thread maik klein via Digitalmars-d-learn
On Sunday, 31 January 2016 at 17:21:54 UTC, Matt Elkins wrote: I know I can mark an argument ref to require lvalues, so I'm wondering whether there is an equivalent for rvalues; that is, is there a way to specify that an argument to a function MUST be an rvalue? For example, in C++ I can do

Re: Ownership semantics

2016-01-31 Thread Matt Elkins via Digitalmars-d-learn
On Sunday, 31 January 2016 at 20:11:07 UTC, Matt Elkins wrote: On Sunday, 31 January 2016 at 20:10:03 UTC, Matt Elkins wrote: On Sunday, 31 January 2016 at 20:07:26 UTC, Steven Schveighoffer wrote: What is likely happening is that ptr is already collected, and you are invalidly attempting to

Re: C Macro deeper meaning?

2016-01-31 Thread Alex Parrill via Digitalmars-d-learn
On Sunday, 31 January 2016 at 02:58:28 UTC, Andrew Edwards wrote: If I understand correctly, this piece of code: enum NOTUSED(v) do { (void)(1 ? (void)0 : ( (void)(v) ) ); } while(0) can be converted to the following in D: void notUsed(T)(T v) { return cast(void)0; }; since it

chain(const(array of class)) fails

2016-01-31 Thread SimonN via Digitalmars-d-learn
Hi, we start with the following code snippet, which works. import std.algorithm; import std.range; import std.stdio; class A { int val; } class B : A { this() { val = 3; } } class C : A { this() { val = 4; } } B[] b = [new B(), new B()]; C[] c = [new C(),

Re: Declaring rvalue function arguments

2016-01-31 Thread anonymous via Digitalmars-d-learn
On 31.01.2016 18:21, Matt Elkins wrote: I know I can mark an argument ref to require lvalues, so I'm wondering whether there is an equivalent for rvalues; that is, is there a way to specify that an argument to a function MUST be an rvalue? For example, in C++ I can do this: [code] void foo(int

Re: Declaring rvalue function arguments

2016-01-31 Thread Matt Elkins via Digitalmars-d-learn
On Sunday, 31 January 2016 at 17:42:19 UTC, anonymous wrote: I don't know if this works in all cases, but it passes that simple test: @disable void foo(ref int x); void foo(int x) {} void main() { foo(5); /* works */ int y = 5; foo(y); /* error */ } My fault, I should

Memory profiling D applications

2016-01-31 Thread Griffon26 via Digitalmars-d-learn
I would like to get a view of the amount of memory that my application requires over time, but this does not seem to be trivial in D. 1) I assume the garbage collector could keep around memory that my application is no longer using. If this is the case then no external memory profiler is

Re: Declaring rvalue function arguments

2016-01-31 Thread maik klein via Digitalmars-d-learn
On Sunday, 31 January 2016 at 17:55:53 UTC, Matt Elkins wrote: Errr, ignore the makeFoo() line. Left that in by accident, has no bearing on the issue. I have found an interesting SO answer http://stackoverflow.com/a/35114945/944430 This would explain everything that we would need. I am just

Re: Declaring rvalue function arguments

2016-01-31 Thread Matt Elkins via Digitalmars-d-learn
On Sunday, 31 January 2016 at 17:48:53 UTC, maik klein wrote: The problem is that x will be copied afaik which is not what you want if you want to deal with ownership. I think that can be solved by wrapping the resource in a struct that deals with passing the ownership. Here is the one I am

Re: Declaring rvalue function arguments

2016-01-31 Thread Matt Elkins via Digitalmars-d-learn
On Sunday, 31 January 2016 at 17:55:53 UTC, Matt Elkins wrote: Errr, ignore the makeFoo() line. Left that in by accident, has no bearing on the issue. Ok, I think I understand why this doesn't work, at least. The Foo passed into bar() is, of course, an lvalue itself. So I can achieve this

Ownership semantics

2016-01-31 Thread maik klein via Digitalmars-d-learn
I recently asked a question about ownership semantics in D https://stackoverflow.com/questions/35115702/how-do-i-express-ownership-semantics-in-d But a few minutes ago I found an answer on SO that could potentially explain a lot. http://stackoverflow.com/a/35114945/944430 Sadly it has some

Re: casting & templates

2016-01-31 Thread Chris Wright via Digitalmars-d-learn
On Sun, 31 Jan 2016 19:59:01 +0100, Robert M. Münch wrote: > I have: > > class OperatorV(T) : Value { > T impl; > > this(T impl) { > this.impl = impl; > } > ... This expands to: template OperatorV(T) { class OperatorV { ... } } If you're just typing `OperatorV` with no

Re: how do I tell if something is lvalue?

2016-01-31 Thread Meta via Digitalmars-d-learn
On Sunday, 31 January 2016 at 20:49:43 UTC, Steven Schveighoffer wrote: struct S { int x; ref int y() { return x; } int z() { return 1; } } What can I use, given S, to determine that x and y yield lvalues, while z yields an rvalue? I was expecting something like isLvalue somewhere, but

Re: Problem when calling toJSON()

2016-01-31 Thread Ali Çehreli via Digitalmars-d-learn
On 01/31/2016 02:52 PM, Alex Herrmann wrote: > Note that I am running 2.070.0. Then it's probably a bug related to this change: http://dlang.org/changelog/2.070.0.html#json-encode-control-characters Ali

Re: How to set array length for multidimensional static arrays

2016-01-31 Thread Namal via Digitalmars-d-learn
On Monday, 1 February 2016 at 07:41:33 UTC, Namal wrote: I understand that I cannot pass a variable to the static array like in C++, and have to use dynamic arrays. But how can I set the length for them without using a loop? I mean std::vector in C++, not array.

Re: How to set array length for multidimensional static arrays

2016-01-31 Thread cym13 via Digitalmars-d-learn
On Monday, 1 February 2016 at 07:42:56 UTC, Namal wrote: On Monday, 1 February 2016 at 07:41:33 UTC, Namal wrote: I understand that I cannot pass a variable to the static array like in C++, and have to use dynamic arrays. But how can I set the length for them without using a loop? I mean

Octree implementation?

2016-01-31 Thread Tofu Ninja via Digitalmars-d-learn
Just out of curiosity, does anyone have an octree implementation for D laying around? Just looking to save some time.

Re: Declaring rvalue function arguments

2016-01-31 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, January 31, 2016 17:48:53 maik klein via Digitalmars-d-learn wrote: > On Sunday, 31 January 2016 at 17:42:19 UTC, anonymous wrote: > > On 31.01.2016 18:21, Matt Elkins wrote: > > I don't know if this works in all cases, but it passes that > > simple test: > > > > > > @disable void

Re: Problem when calling toJSON()

2016-01-31 Thread Alex Herrmann via Digitalmars-d-learn
On Monday, 1 February 2016 at 00:24:06 UTC, Ali Çehreli wrote: On 01/31/2016 02:52 PM, Alex Herrmann wrote: > Note that I am running 2.070.0. Then it's probably a bug related to this change: http://dlang.org/changelog/2.070.0.html#json-encode-control-characters Ali This problem is

Re: chain(const(array of class)) fails

2016-01-31 Thread Nicholas Wilson via Digitalmars-d-learn
On Sunday, 31 January 2016 at 21:22:06 UTC, SimonN wrote: Hi, we start with the following code snippet, which works. import std.algorithm; import std.range; import std.stdio; class A { int val; } class B : A { this() { val = 3; } } class C : A { this() { val = 4; }

Re: how do I tell if something is lvalue?

2016-01-31 Thread Ali Çehreli via Digitalmars-d-learn
On 01/31/2016 01:48 PM, Meta wrote: This seems to do the trick, although I haven't extensively tested it. There is hasLvalueElements() as well. Its implementation my be similar or give other ideas: https://dlang.org/phobos/std_range_primitives.html#hasLvalueElements Ali

Re: Problem when calling toJSON()

2016-01-31 Thread anonymous via Digitalmars-d-learn
On 01.02.2016 01:29, Alex Herrmann wrote: This problem is solved! Sorry for not updating the question. It was actually a problem with me not iduping it, and the memory being reclaimed or something similar. I did also change to stdx.data.json (std_data_json on dub). You don't seem to be clear

Re: how do I tell if something is lvalue?

2016-01-31 Thread Meta via Digitalmars-d-learn
On Monday, 1 February 2016 at 00:20:00 UTC, Ali Çehreli wrote: On 01/31/2016 01:48 PM, Meta wrote: This seems to do the trick, although I haven't extensively tested it. There is hasLvalueElements() as well. Its implementation my be similar or give other ideas:

Error: no property 'select' for type 'ddbc.core.Statement'

2016-01-31 Thread Suliman via Digitalmars-d-learn
I hope that here I will get answer faster then on https://github.com/buggins/ddbc/issues/18 I am using ddbc diver for access to mysql. I need to return result of request to struct. My code is next: import std.stdio; import ddbc.all; import std.stdio; import std.conv; void main() {

Region allocator strage error

2016-01-31 Thread ref2401 via Digitalmars-d-learn
I am getting runtime error: core.exception.AssertError@std\experimental\allocator\building_blocks\region.d(235): Assertion failure if LEN equals to 3, 5, 7, 9, ... void main(string[] args) { ubyte[1024] memory; auto stackAlloc = Region!NullAllocator(memory); IAllocator