getting current DateTime

2014-12-30 Thread bitwise via Digitalmars-d-learn
How do you get the current DateTime? Why doesn't DateTime have DateTime.now?

Re: getting current DateTime

2014-12-30 Thread bitwise via Digitalmars-d-learn
On Wednesday, 31 December 2014 at 06:31:13 UTC, ketmar via Digitalmars-d-learn wrote: On Wed, 31 Dec 2014 06:03:04 + bitwise via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: How do you get the current DateTime? Why doesn't DateTime have DateTime.now? but it has

Re: getting current DateTime

2014-12-30 Thread bitwise via Digitalmars-d-learn
It would be nice if that cast was made implicit though. Just realizing now that DateTime doesn't have sub-second accuracy =/

Re: getting current DateTime

2014-12-31 Thread bitwise via Digitalmars-d-learn
Why do you need DateTime and not SysTime? I'm actually surprised it doesn't have that too... -Steve Initially I was looking for something that would be the equivalent to DateTime in C#. This now appears to be SysTime, not DateTime in D. It seems the only real reason to use DateTime is as

Re: Associative Array of Const Objects?

2015-03-29 Thread bitwise via Digitalmars-d-learn
I'm a little confused at this point why this doesn't work either: const(Test) test = new Test(); // fine test = new Test(); // error In C++, There is a clear distinction: const Test *test1 = nullptr; // const before type test1 = new Test(); // fine Test

Re: Associative Array of Const Objects?

2015-03-29 Thread bitwise via Digitalmars-d-learn
perhaps something like Rebindable could be used. Looking at Rebindable now, there is a useful example. There should probably be a mention of this on the const/immutable docs. For people coming from C++, this will not be obvious. auto a = Rebindable!(const Widget)(new Widget); a.y();

Re: Associative Array of Const Objects?

2015-03-29 Thread bitwise via Digitalmars-d-learn
On Sunday, 29 March 2015 at 19:04:30 UTC, anonymous wrote: Notice how you have that '*' there that allows you to distinguish the data from the reference. You can have a mutable pointer to const data in D, too: struct Test {} const(Test)* test1 = null; test1 = new Test; /* fine */

Re: Associative Array of Const Objects?

2015-03-29 Thread bitwise via Digitalmars-d-learn
Although, I suppose this is still a step up from C# which has not const at all =O

Re: Associative Array of Const Objects?

2015-03-29 Thread bitwise via Digitalmars-d-learn
1) Such placement based syntax is foreign to D. I would have to agree that this is a strange way to do things in any language. The great int* a vs int *a debate... 2) It would be special syntax just for class types. IMO, it would be worth it 3) It's not how C++ rolls. `const Test test;`

Associative Array of Const Objects?

2015-03-27 Thread bitwise via Digitalmars-d-learn
class Test{} void main() { const(Test)[string] tests; tests[test] = new Test(); } This code used to work, but after upgrading to dmd 2.067, it no longer does. --Error: cannot modify const expression tests[test] How do I insert an item into an associative array of const

Re: extern(C++) linker errors

2015-04-22 Thread bitwise via Digitalmars-d-learn
On Wed, 22 Apr 2015 02:14:40 -0400, Dan Olson zans.is.for.c...@yahoo.com wrote: bitwise bitwise@gmail.com writes: I am trying to interface to C++, and getting linker errors. Below are my 3 source files and 2 build scripts with their associated errors. Can anyone see what I'm doing wrong?

extern(C++) linker errors

2015-04-21 Thread bitwise via Digitalmars-d-learn
Hello! I am trying to interface to C++, and getting linker errors. Below are my 3 source files and 2 build scripts with their associated errors. Can anyone see what I'm doing wrong? / test.cpp #include stdio.h class Test { public: virtual void Foo(){

Destruction in D

2015-04-30 Thread bitwise via Digitalmars-d-learn
After reading GC page in the reference, it seems that class destructors are called on a separate thread, in parallel to the main thread. Is this correct? What about structs? Are the destructors called when they go out of scope in a C++ RAII fashion, or do they happen on a separate thread

Re: Destruction in D

2015-05-02 Thread bitwise via Digitalmars-d-learn
On Fri, 01 May 2015 14:37:40 -0400, Idan Arye generic...@gmail.com wrote: Structs allow you to implement ref-counting smart pointers like you can do in C++. There is an implementation in the standard library: http://dlang.org/phobos/std_typecons.html#.RefCounted Yeah, I guess I should have

Efficiently passing structs

2015-05-03 Thread bitwise via Digitalmars-d-learn
If I have a large struct that needs to be passed around, like a 4x4 matrix for example, how do I do that efficiently in D? In std.datetime, in is used for most struct parameters, but I'm confused by the docs for function parameter storage classes[1]. In C++, I would pass a large struct as

Re: Efficiently passing structs

2015-05-03 Thread bitwise via Digitalmars-d-learn
On Sun, 03 May 2015 22:37:52 -0400, rsw0x anonym...@anonymous.com wrote: Use the ref storage class. You can use more than one storage class i.e, foo(in ref int x) Thanks, this should work. On Sun, 03 May 2015 23:29:59 -0400, Baz bb.t...@gmx.com wrote: it's specified in

Re: Destruction in D

2015-05-01 Thread bitwise via Digitalmars-d-learn
On Friday, 1 May 2015 at 02:35:52 UTC, Idan Arye wrote: On Thursday, 30 April 2015 at 23:27:49 UTC, bitwise wrote: Well, the third thing was just my reasoning for asking in the first place. I need to be able to acquire/release shared resources reliably, like an OpenGL texture, for example.

Re: Destruction in D

2015-04-30 Thread bitwise via Digitalmars-d-learn
On Thu, 30 Apr 2015 16:17:10 -0400, Adam D. Ruppe destructiona...@gmail.com wrote: On Thursday, 30 April 2015 at 20:07:11 UTC, bitwise wrote: destructors are called on a separate thread, in parallel to the main thread. Is this correct? Not necessarily. the way the GC works in D today is

Re: Efficiently passing structs

2015-05-04 Thread bitwise via Digitalmars-d-learn
On Mon, 04 May 2015 00:16:03 -0400, Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: D will move the argument if it can rather than copying it (e.g. if a temporary is being passed in), which reduces the need for worrying about copying like you tend to have to do

Re: Efficiently passing structs

2015-05-05 Thread bitwise via Digitalmars-d-learn
On Tue, 05 May 2015 18:58:34 -0400, Namespace rswhi...@gmail.com wrote: On Tuesday, 5 May 2015 at 21:58:57 UTC, bitwise wrote: On Tue, 05 May 2015 17:33:09 -0400, Namespace rswhi...@gmail.com wrote: I've discussed that so many times... just search for auto / scope ref... ;) It will never

Re: Efficiently passing structs

2015-05-05 Thread bitwise via Digitalmars-d-learn
On Tue, 05 May 2015 00:20:15 -0400, rsw0x anonym...@anonymous.com wrote: it does, auto ref can bind to both lvalues and rvalues. Create the function with an empty template like so, import std.stdio; struct S{ } void Foo()(auto ref S s){ } void main(){ S s; Foo(s);

Re: Efficiently passing structs

2015-05-05 Thread bitwise via Digitalmars-d-learn
On Tue, 05 May 2015 10:44:13 -0400, rsw0x anonym...@anonymous.com wrote: On Tuesday, 5 May 2015 at 14:14:51 UTC, bitwise wrote: Interesting.. Has this always worked? Theres a couple of forum conversations about trying to get auto ref to work for non-templates. The main problem seems to be

Re: Efficiently passing structs

2015-05-05 Thread bitwise via Digitalmars-d-learn
On Tue, 05 May 2015 18:27:54 -0400, Gomen go...@asai.jp wrote: I am sorry for this post, I am just testing something. The retired D forum seems to have been re-purposed for testing ;) Bit

Re: Efficiently passing structs

2015-05-05 Thread bitwise via Digitalmars-d-learn
On Tue, 05 May 2015 17:33:09 -0400, Namespace rswhi...@gmail.com wrote: I've discussed that so many times... just search for auto / scope ref... ;) It will never happen. See: http://forum.dlang.org/thread/ntsyfhesnywfxvzbe...@forum.dlang.org?page=1

Re: Efficiently passing structs

2015-05-05 Thread bitwise via Digitalmars-d-learn
On Tue, 05 May 2015 14:49:07 -0400, Ali Çehreli acehr...@yahoo.com wrote: http://ddili.org/ders/d.en/lvalue_rvalue.html#ix_lvalue_rvalue.auto%20ref,%20parameter I've actually stumbled upon this site a few times, and it has been very helpful, so thanks =D Unfortunately though, I had no idea

Re: how does 'shared' affect member variables?

2015-05-09 Thread bitwise via Digitalmars-d-learn
On Sat, 09 May 2015 21:32:42 -0400, Mike n...@none.com wrote: it looks like what you are trying to implement is what `synchronized` already provides: http://ddili.org/ders/d.en/concurrency_shared.html#ix_concurrency_shared.synchronized Mike Yes, but synchronized uses a mutex. Spin locks

Re: how does 'shared' affect member variables?

2015-05-09 Thread bitwise via Digitalmars-d-learn
On Sat, 09 May 2015 15:38:05 -0400, Mike n...@none.com wrote: On Saturday, 9 May 2015 at 18:41:59 UTC, bitwise wrote: Also, I wasn't able to find any thorough documentation on shared, so if someone has a link, that would be helpful. Here are a few interesting links: Iain Buclaw (lead

Re: how does 'shared' affect member variables?

2015-05-09 Thread bitwise via Digitalmars-d-learn
On Sat, 09 May 2015 15:59:57 -0400, tcak t...@gmail.com wrote: If a variable/class/struct etc is not shared, for variables and struct, you find their initial value. For class, you get null. For first timers (I started using shared keyword more than 2 years ago), do not forget that: a shared

how does 'shared' affect member variables?

2015-05-09 Thread bitwise via Digitalmars-d-learn
What does 'shared' do to member variables? It makes sense to me to put it on a global variable, but what sense does it make putting it on a member of a class? What happens if you try to access a member of a class/struct instance from another thread that is not marked 'shared'? Also, I

Re: Efficiently passing structs

2015-05-05 Thread bitwise via Digitalmars-d-learn
On Tue, 05 May 2015 11:54:53 -0400, Jonathan M Davis jmdavisp...@gmx.com wrote: On Tuesday, 5 May 2015 at 02:47:03 UTC, bitwise wrote: On Mon, 04 May 2015 00:16:03 -0400, Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: D will move the argument if it can

Re: CTFE UFCs?

2015-04-15 Thread bitwise via Digitalmars-d-learn
On Tue, 14 Apr 2015 12:46:40 -0400, ketmar ket...@ketmar.no-ip.org wrote: On Tue, 14 Apr 2015 11:20:38 -0400, bitwise wrote: i believe that you can't do what you want in a way you want, 'cause UFCS is not working for template args. but you can do this: alias base(alias CC) =

Re: CTFE UFCs?

2015-04-15 Thread bitwise via Digitalmars-d-learn
On Tue, 14 Apr 2015 12:52:19 -0400, anonymous anonym...@example.com wrote: abstract class Refl { @property abstract string name() const; immutable(Refl) base() const; } class ClassRefl(T) : Refl { @property override string name() const { return T.stringof; }

CTFE UFCs?

2015-04-14 Thread bitwise via Digitalmars-d-learn
Hi. I've been building a reflection library for D, but I've hit a snag. If anyone can help out, it would be much appreciated =D In the example below, the second line of main() retrieves the reflection of a base class. Everything is well and good. Now, I am trying to come up with a more

Re: CTFE UFCs?

2015-04-15 Thread bitwise via Digitalmars-d-learn
On Tue, 14 Apr 2015 12:52:19 -0400, anonymous anonym...@example.com wrote: Parting thoughts: I don't know where you're heading with this. But so far I don't see what it would buy you over std.traits and TypeInfo/TypeInfo_Class. Forgot to mention support for runtime reflection. See here:

Re: GC Destruction Order

2015-05-19 Thread bitwise via Digitalmars-d-learn
On Tue, 19 May 2015 19:03:02 -0400, bitwise bitwise@gmail.com wrote: Maybe I worded that incorrectly, but my point is that when you're running with the GC disabled, you should only use methods marked with @nogc if you want to make sure your code doesn't leak right? that's a lot of

Re: GC Destruction Order

2015-05-19 Thread bitwise via Digitalmars-d-learn
On Tue, 19 May 2015 19:16:14 -0400, Adam D. Ruppe destructiona...@gmail.com wrote: On Tuesday, 19 May 2015 at 23:10:21 UTC, bitwise wrote: which is why I am asking if there are any plans to implement something like @nogc for entire modules or classes. At the top: @nogc: stuff here

Re: GC Destruction Order

2015-05-19 Thread bitwise via Digitalmars-d-learn
On Tue, 19 May 2015 14:19:30 -0400, Adam D. Ruppe destructiona...@gmail.com wrote: On Tuesday, 19 May 2015 at 18:15:06 UTC, bitwise wrote: Is this also true for D? Yes. The GC considers all the unreferenced memory dead at the same time and may clean up the class and its members in any

Re: GC Destruction Order

2015-05-20 Thread bitwise via Digitalmars-d-learn
On Wednesday, 20 May 2015 at 08:01:46 UTC, Kagamin wrote: On Tuesday, 19 May 2015 at 22:15:18 UTC, bitwise wrote: Thanks for confirming, but given your apparent tendency toward pinhole view points, it's unsurprising that you don't understand what I'm asking. And what you're asking. Just for

Re: GC Destruction Order

2015-05-19 Thread bitwise via Digitalmars-d-learn
On Tue, 19 May 2015 17:52:36 -0400, rsw0x anonym...@anonymous.com wrote: On Tuesday, 19 May 2015 at 21:07:52 UTC, bitwise wrote: Any idea what the plans are?. Does RefCounted become thread safe? Correct me if I'm wrong though, but even if RefCounted itself was thread-safe, RefCounted

Re: GC Destruction Order

2015-05-19 Thread bitwise via Digitalmars-d-learn
On Tue, 19 May 2015 15:36:21 -0400, rsw0x anonym...@anonymous.com wrote: On Tuesday, 19 May 2015 at 18:37:31 UTC, bitwise wrote: On Tue, 19 May 2015 14:19:30 -0400, Adam D. Ruppe destructiona...@gmail.com wrote: On Tuesday, 19 May 2015 at 18:15:06 UTC, bitwise wrote: Is this also true for

Re: GC Destruction Order

2015-05-19 Thread bitwise via Digitalmars-d-learn
On Tue, 19 May 2015 18:47:26 -0400, Steven Schveighoffer schvei...@yahoo.com wrote: On 5/19/15 5:07 PM, bitwise wrote: On Tue, 19 May 2015 15:36:21 -0400, rsw0x anonym...@anonymous.com wrote: On Tuesday, 19 May 2015 at 18:37:31 UTC, bitwise wrote: On Tue, 19 May 2015 14:19:30 -0400,

Re: Calling DLL coded in D from Java

2015-06-16 Thread bitwise via Digitalmars-d-learn
On Tue, 16 Jun 2015 18:47:03 -0400, DlangLearner bystan...@gmail.com wrote: I'd like to know if it is possible to call an DLL coded in D from Java? What you're looking for is JNI (Java Native Interface). If you export your D functions correctly, as you have done(extern(C) export) then

Conditional Compilation Multiple Versions

2015-06-12 Thread bitwise via Digitalmars-d-learn
Is there a way to compile for multiple conditions? Tried all these: version(One | Two){ } version(One || Two){ } version(One Two){ } version(One) | version(Two){ } version(One) || version(Two){ } version(One) version(Two){ } Bit

Re: Conditional Compilation Multiple Versions

2015-06-12 Thread bitwise via Digitalmars-d-learn
On Fri, 12 Jun 2015 20:55:51 -0400, Márcio Martins marcio...@gmail.com wrote: I know... I too hate that one can't use simple logic ops... Indeed... Thanks. Bit

Re: Conditional Compilation Multiple Versions

2015-06-13 Thread bitwise via Digitalmars-d-learn
On Sat, 13 Jun 2015 08:21:50 -0400, ketmar ket...@ketmar.no-ip.org wrote: On Fri, 12 Jun 2015 20:41:59 -0400, bitwise wrote: Is there a way to compile for multiple conditions? Tried all these: version(One | Two){ } version(One || Two){ } version(One Two){ } version(One) | version(Two){ }

Re: Conditional Compilation Multiple Versions

2015-06-13 Thread bitwise via Digitalmars-d-learn
On Sat, 13 Jun 2015 12:20:40 -0400, ketmar ket...@ketmar.no-ip.org wrote: On Sat, 13 Jun 2015 13:49:49 +, anonymous wrote: Taking it one step further: template Version(string name) { mixin( version(~name~) enum Version = true; else enum Version = false; ); }

GC Destruction Order

2015-05-19 Thread bitwise via Digitalmars-d-learn
In C#, it's possible that class members can actually be destroyed before the containing object. Example: class Stuff { Class1 thing1; Class2 thing2; ~Stuff() { thing1.DoSomeFinalization(); // [1] } } I forget what the exact behavior was, but basically, [1] is

Re: GC Destruction Order

2015-05-19 Thread bitwise via Digitalmars-d-learn
On Tue, 19 May 2015 14:55:55 -0400, Steven Schveighoffer schvei...@yahoo.com wrote: On 5/19/15 2:37 PM, bitwise wrote: On Tue, 19 May 2015 14:19:30 -0400, Adam D. Ruppe destructiona...@gmail.com wrote: On Tuesday, 19 May 2015 at 18:15:06 UTC, bitwise wrote: Is this also true for D? Yes.

Re: Threading Questions

2015-10-07 Thread bitwise via Digitalmars-d-learn
On Wednesday, 7 October 2015 at 09:09:36 UTC, Kagamin wrote: On Sunday, 4 October 2015 at 04:24:55 UTC, bitwise wrote: I use C#(garbage collected) for making apps/games, and while, _in_theory_, the GC is supposed to protect you from leaks, memory is not the only thing that can leak. Threads

Re: Threading Questions

2015-10-08 Thread bitwise via Digitalmars-d-learn
On Thursday, 8 October 2015 at 10:11:38 UTC, Kagamin wrote: On Thursday, 8 October 2015 at 02:31:24 UTC, bitwise wrote: If you have System.Collections.Generic.List(T) static class member, there is nothing wrong with using it from multiple threads like this: The equivalent of your D example

Re: Threading Questions

2015-10-05 Thread bitwise via Digitalmars-d-learn
On Monday, 5 October 2015 at 00:23:21 UTC, Jonathan M Davis wrote: On Sunday, October 04, 2015 14:42:48 bitwise via Digitalmars-d-learn wrote: Since D is moving towards a phobos with no GC, what will happen to things that are classes like Condition and Mutex? Phobos and druntime will always

Re: Threading Questions

2015-10-08 Thread bitwise via Digitalmars-d-learn
On Thursday, 8 October 2015 at 20:42:46 UTC, Kagamin wrote: On Thursday, 8 October 2015 at 13:44:46 UTC, bitwise wrote: That still doesn't explain what you mean about it being illegal in other languages or why you brought up C# in the first place. Illegal means the resulting program behaves

Re: Threading Questions

2015-10-03 Thread bitwise via Digitalmars-d-learn
On Tuesday, 29 September 2015 at 19:10:58 UTC, Steven Schveighoffer wrote: An object that implements the Monitor interface may not actually be a mutex. For example, a pthread_cond_t requires a pthread_mutex_t to operate properly. Right! I feel like I should have caught the fact that

Re: Threading Questions

2015-10-04 Thread bitwise via Digitalmars-d-learn
On Wednesday, 30 September 2015 at 10:32:01 UTC, Jonathan M Davis wrote: On Tuesday, September 29, 2015 22:38:42 Johannes Pfau via Digitalmars-d-learn wrote: [...] What I took from the answers to that SO question was that in general, it really doesn't matter whether a condition variable has

Re: Threading Questions

2015-10-04 Thread bitwise via Digitalmars-d-learn
On Tuesday, 29 September 2015 at 23:20:31 UTC, Steven Schveighoffer wrote: yeah, that could probably be done. One thing to note is that these classes are from ages ago (probably close to 10 years). New API suggestions may be allowed. -Steve I'm still thinking about my last rant, here...

Re: Threading Questions

2015-09-28 Thread bitwise via Digitalmars-d-learn
On Monday, 28 September 2015 at 11:47:38 UTC, Russel Winder wrote: I hadn't answered as I do not have answers to the questions you ask. My reason: people should not be doing their codes using these low-level shared memory techniques. Data parallel things should be using the std.parallelism

Re: Threading Questions

2015-10-05 Thread bitwise via Digitalmars-d-learn
On Monday, 5 October 2015 at 20:18:18 UTC, Laeeth Isharc wrote: On Monday, 5 October 2015 at 17:40:24 UTC, bitwise wrote: You may be right. I wrote a simple download manager in D using message passing. It was a little awkward at first, but in general, the spawn/send/receive API seems very

Threading Questions

2015-09-25 Thread bitwise via Digitalmars-d-learn
Hey, I've got a few questions if anybody's got a minute. I'm trying to wrap my head around the threading situation in D. So far, things seem to be working as expected, but I want to verify my solutions. 1) Are the following two snippets exactly equivalent(not just in observable behaviour)?

Re: Threading Questions

2015-09-25 Thread bitwise via Digitalmars-d-learn
Pretty please? :)

Re: struct: default construction or lazy initialization.

2017-02-01 Thread bitwise via Digitalmars-d-learn
On Wednesday, 1 February 2017 at 01:52:40 UTC, Adam D. Ruppe wrote: On Wednesday, 1 February 2017 at 00:43:39 UTC, bitwise wrote: Container!int c; // = Container!int() -> can't do this. Can you live with Container!int c = Container!int.create(); because D supports that and can force the

Re: struct: default construction or lazy initialization.

2017-02-01 Thread bitwise via Digitalmars-d-learn
On Wednesday, 1 February 2017 at 23:24:27 UTC, kinke wrote: It's not that bad. D just doesn't support a default ctor for structs at all and simply initializes each instance with T.init. Your `s2` initialization is most likely seen as explicit default initialization (again with T.init).

Re: struct: default construction or lazy initialization.

2017-01-31 Thread bitwise via Digitalmars-d-learn
On Tuesday, 31 January 2017 at 23:52:31 UTC, Ali Çehreli wrote: On 01/31/2017 03:15 PM, bitwise wrote: [...] Thanks for the response, but this doesn't really solve the problem. > If the object is defined at module scope as shared static > immutable It is indeed possible to initialize

Re: struct: default construction or lazy initialization.

2017-01-31 Thread bitwise via Digitalmars-d-learn
C#'s "Dispose" pattern comes to mind here. You don't leak memory, you just leak file handles and graphics resources instead when you forget to explicitly call Dispose().

struct: default construction or lazy initialization.

2017-01-31 Thread bitwise via Digitalmars-d-learn
Unless I'm missing something, it seems that neither of these are actually possible. Consider an object which needs internal state to function. The obvious answer is to create it in the constructor: struct Foo(T) { T* payload; this() { payload =

Safely moving structs in D

2017-01-23 Thread bitwise via Digitalmars-d-learn
Is it ok to memcpy/memmove a struct in D? Quote from here: https://dlang.org/spec/garbage.html "Do not have pointers in a struct instance that point back to the same instance. The trouble with this is if the instance gets moved in memory, the pointer will point back to where it came from,

Re: Safely moving structs in D

2017-01-23 Thread bitwise via Digitalmars-d-learn
I'm confused about what the rules would be here. It would make sense to call the postblit if present, but std.Array currently does not: https://github.com/dlang/phobos/blob/04cca5c85ddf2be25381fc63c3e941498b17541b/std/container/array.d#L884

Re: Safely moving structs in D

2017-01-23 Thread bitwise via Digitalmars-d-learn
On Monday, 23 January 2017 at 23:04:45 UTC, Ali Çehreli wrote: On 01/23/2017 02:58 PM, bitwise wrote: I'm confused about what the rules would be here. It would make sense to call the postblit if present, but std.Array currently does not:

Re: returning 'ref inout(T)' - not an lvalue?

2017-01-25 Thread bitwise via Digitalmars-d-learn
On Wednesday, 25 January 2017 at 21:04:50 UTC, Adam D. Ruppe wrote: On Wednesday, 25 January 2017 at 20:42:52 UTC, bitwise wrote: Is it not possible to return a ref from an inout function? It isn't the inout that's getting you, it is the const object in main(). const(List!int) c; Make

returning 'ref inout(T)' - not an lvalue?

2017-01-25 Thread bitwise via Digitalmars-d-learn
Compiling the code below gives these errors: main.d(92): Error: cast(inout(int))this.list.data[cast(uint)(this.pos + i)] is not an lvalue main.d(101): Error: template instance main.Iterator!(const(List!int)) error instantiating main.d(108): instantiated from here: first!(const(List!int))

Re: Safely moving structs in D

2017-01-25 Thread bitwise via Digitalmars-d-learn
On Tuesday, 24 January 2017 at 11:46:47 UTC, Jonathan M Davis wrote: On Monday, January 23, 2017 22:26:58 bitwise via Digitalmars-d-learn wrote: [...] Moving structs is fine. The postblit constructor is for when they're copied. A copy is unnecessary if the original isn't around anymore

Re: Mallocator and 'shared'

2017-02-12 Thread bitwise via Digitalmars-d-learn
On Saturday, 11 February 2017 at 04:32:37 UTC, Michael Coulombe wrote: On Friday, 10 February 2017 at 23:57:18 UTC, bitwise wrote: [...] A shared method means that it can only be called on a shared instance of the struct/class, which will have shared fields. A shared method should be

Mallocator and 'shared'

2017-02-10 Thread bitwise via Digitalmars-d-learn
https://github.com/dlang/phobos/blob/cd7846eb96ea7d2fa65ccb04b4ca5d5b0d1d4a63/std/experimental/allocator/mallocator.d#L63-L65 Looking at Mallocator, the use of 'shared' doesn't seem correct to me. The logic stated in the comment above is that 'malloc' is thread safe, and therefore all

__dtor vs __xdtor

2017-08-11 Thread bitwise via Digitalmars-d-learn
What do they do? What's the difference? Thanks

Re: __dtor vs __xdtor

2017-08-11 Thread bitwise via Digitalmars-d-learn
On Friday, 11 August 2017 at 17:02:20 UTC, HyperParrow wrote: On Friday, 11 August 2017 at 16:53:02 UTC, bitwise wrote: What do they do? What's the difference? Thanks __xdtor() also calls the __dtor() that are mixed with template mixins while __dtor() only call the __dtor() that matches to

Re: __dtor vs __xdtor

2017-08-11 Thread bitwise via Digitalmars-d-learn
On Friday, 11 August 2017 at 17:06:40 UTC, HyperParrow wrote: [...] int i; struct Foo { template ToMix(){ ~this(){i;}} ~this(){++i;} mixin ToMix; } void main() { Foo* foo = new Foo; foo.__xdtor; assert(i==3); Foo* other = new Foo; foo.__dtor;

Re: __dtor vs __xdtor

2017-08-11 Thread bitwise via Digitalmars-d-learn
On Friday, 11 August 2017 at 17:20:18 UTC, HyperParrow wrote: [...] I made a mistake but it's not about i, which is a global. I meant "other.__dtor." just before the last assert. This doesn't change the results. hmm...indeed ;) On Friday, 11 August 2017 at 17:24:17 UTC, HyperParrow wrote:

returning D string from C++?

2017-08-05 Thread bitwise via Digitalmars-d-learn
I have a Windows native window class in C++, and I need a function to return the window title. So in D, I have this: // isn't D's ABI stable enough to just return this from C++ // and call it a string in the extern(C++) interface? anyways.. struct DString { size_t length;

Re: returning D string from C++?

2017-08-06 Thread bitwise via Digitalmars-d-learn
On Saturday, 5 August 2017 at 21:18:29 UTC, Jeremy DeHaan wrote: On Saturday, 5 August 2017 at 20:17:23 UTC, bitwise wrote: I have a Windows native window class in C++, and I need a function to return the window title. [...] As long as you have a reachable reference to the GC memory

Re: returning D string from C++?

2017-08-06 Thread bitwise via Digitalmars-d-learn
On Sunday, 6 August 2017 at 05:31:51 UTC, Marco Leise wrote: Am Sat, 05 Aug 2017 20:17:23 + schrieb bitwise : [...] In due diligence, you are casting an ANSI string into a UTF-8 string which will result in broken Unicode for non-ASCII window titles. In any case it is

Re: lambda function with "capture by value"

2017-08-06 Thread bitwise via Digitalmars-d-learn
On Saturday, 5 August 2017 at 18:17:49 UTC, Simon Bürger wrote: If a lambda function uses a local variable, that variable is captured using a hidden this-pointer. But this capturing is always by reference. Example: int i = 1; auto dg = (){ writefln("%s", i); }; i = 2; dg(); //

Re: returning D string from C++?

2017-08-06 Thread bitwise via Digitalmars-d-learn
On Sunday, 6 August 2017 at 16:46:40 UTC, Mike Parker wrote: On Sunday, 6 August 2017 at 16:23:01 UTC, bitwise wrote: So I guess you're saying I'm covered then? I guess there's no reason I can think of for the GC to stop scanning at the language boundary, let alone any way to actually do that

Re: struct field initialization

2017-08-16 Thread bitwise via Digitalmars-d-learn
On Wednesday, 16 August 2017 at 18:11:05 UTC, bitwise wrote: [...] I'm asking this because I need to forward args to a container's node's value. Something like this: struct Node(T) { int flags; T value; // maybe const this(Args...)(int flags, auto ref Args args) {

Re: struct field initialization

2017-08-16 Thread bitwise via Digitalmars-d-learn
On Wednesday, 16 August 2017 at 18:17:36 UTC, kinke wrote: On Wednesday, 16 August 2017 at 18:11:05 UTC, bitwise wrote: If I define a non-default constructor for a struct, are the fields initialized to T.init by the time it's called? The struct instance is initialized with T.init before

struct field initialization

2017-08-16 Thread bitwise via Digitalmars-d-learn
If I define a non-default constructor for a struct, are the fields initialized to T.init by the time it's called? or am I responsible for initializing all fields in that constructor? ..or do structs follow the same rules as classes? https://dlang.org/spec/class.html#field-init Thanks

Re: extern(C) enum

2017-09-15 Thread bitwise via Digitalmars-d-learn
On Friday, 15 September 2017 at 07:24:34 UTC, Jonathan M Davis wrote: On Friday, September 15, 2017 04:15:57 bitwise via Digitalmars-d-learn wrote: I translated the headers for FreeType2 to D, and in many cases, enums are used as struct members. If I declare an extern(C) enum in D

Re: extern(C) enum

2017-09-15 Thread bitwise via Digitalmars-d-learn
On Friday, 15 September 2017 at 06:57:31 UTC, rikki cattermole wrote: On 15/09/2017 5:15 AM, bitwise wrote: I translated the headers for FreeType2 to D, and in many cases, enums are used as struct members. If I declare an extern(C) enum in D, is it guaranteed to have the same underlying type

Re: Ranges suck!

2017-09-15 Thread bitwise via Digitalmars-d-learn
On Thursday, 14 September 2017 at 23:53:20 UTC, Your name wrote: [...] I understand your frustration. The fact that "inout" is actually a keyword makes it hard not to think that some very strange fetishes were at play during the creation of this language. As a whole though, the language

extern(C) enum

2017-09-14 Thread bitwise via Digitalmars-d-learn
I translated the headers for FreeType2 to D, and in many cases, enums are used as struct members. If I declare an extern(C) enum in D, is it guaranteed to have the same underlying type and size as it would for a C compiler on the same platform?

detect implicitly convertible typeid's?

2017-09-23 Thread bitwise via Digitalmars-d-learn
Is it possible to tell if two objects represented by TypeInfo's are convertible to each other? Basically, is there a built in way to do this? int x; long y; assert(typeid(x).isImplicitlyConvertibleTo(typeid(y)); Thanks

Re: extern(C) enum

2017-09-17 Thread bitwise via Digitalmars-d-learn
On Saturday, 16 September 2017 at 12:34:58 UTC, nkm1 wrote: On Saturday, 16 September 2017 at 03:06:24 UTC, Timothy Foster wrote: [...] [...] So it appears I'm screwed then. Example: typedef enum FT_Size_Request_Type_ { FT_SIZE_REQUEST_TYPE_NOMINAL, FT_SIZE_REQUEST_TYPE_REAL_DIM,

Re: extern(C) enum

2017-09-17 Thread bitwise via Digitalmars-d-learn
On Sunday, 17 September 2017 at 18:44:47 UTC, nkm1 wrote: On Sunday, 17 September 2017 at 17:06:10 UTC, bitwise wrote: [...] Just put the burden on the users then. It's implementation defined, so they are in position to figure it out... This isn't something that can really be done with

Re: extern(C) enum

2017-09-17 Thread bitwise via Digitalmars-d-learn
On Monday, 18 September 2017 at 00:12:49 UTC, Mike Parker wrote: On Sunday, 17 September 2017 at 19:16:06 UTC, bitwise wrote: [...] I've been maintaining bindings to multiple C libraries (including Freetype 2 bindings) for 13 years now. I have never encountered an issue with an enum size

Re: extern(C) enum

2017-09-15 Thread bitwise via Digitalmars-d-learn
On Friday, 15 September 2017 at 19:35:50 UTC, nkm1 wrote: On Friday, 15 September 2017 at 19:21:02 UTC, Timothy Foster wrote: I believe C enum size is implementation defined. A C compiler can pick the underlying type (1, 2, or 4 bytes, signed or unsigned) that fits the values in the enum.

Re: Is compiling for Android/iOS possible?

2017-09-07 Thread bitwise via Digitalmars-d-learn
On Wednesday, 6 September 2017 at 18:34:28 UTC, Timothy Foster wrote: I'm just wondering if I made an application for Windows/Mac/Linux if I could get it to also work on mobile devices, or would I have to rewrite the application in another language to get it to work? If it's possible, what

Re: detect implicitly convertible typeid's?

2017-09-26 Thread bitwise via Digitalmars-d-learn
On Tuesday, 26 September 2017 at 17:27:02 UTC, Steven Schveighoffer wrote: -Steve About Variant - I was considering a pull request for retrieving a pointer to the internal data, but figured that it was left out on purpose due to @safety. OTOH, I was looking through dmd commits, and it

Re: detect implicitly convertible typeid's?

2017-09-26 Thread bitwise via Digitalmars-d-learn
On Tuesday, 26 September 2017 at 19:31:56 UTC, Steven Schveighoffer wrote: [...] I just recently fixed Variant so it could accept shared data (so you could pass shared data using std.concurrency), and part of that depends on the fact that I know nothing else can point at the data (so no

Re: Is it possible to avoid call to destructor for structs?

2017-09-24 Thread bitwise via Digitalmars-d-learn
On Sunday, 24 September 2017 at 17:11:26 UTC, Haridas wrote: In the following code, Bar is an element of struct Foo. Is there a way to avoid a call to ~Bar when ~Foo is getting executed? Don't construct it to begin with. struct Bar { import std.stdio : writeln; int a = 123;

Re: Is it possible to avoid call to destructor for structs?

2017-09-24 Thread bitwise via Digitalmars-d-learn
On Monday, 25 September 2017 at 01:46:15 UTC, Haridas wrote: [...] It all works well so far. But as soon as I create an instance of Bar inside a Dlang class (say Foo) or as part of a Dlang dynamic array, hell follows. At some point, Dlang's GC kicks in and Bar's destructor gets called from

Re: Is it possible to avoid call to destructor for structs?

2017-09-25 Thread bitwise via Digitalmars-d-learn
On Monday, 25 September 2017 at 08:39:26 UTC, Adrian Matoga wrote: [...] You shouldn't store the pointer to barBuffer inside Foo. The language allows moving the structure around with a simple memcpy, so _bar is likely to point into garbage soon after it's assigned. Good point - but it's a

Re: detect implicitly convertible typeid's?

2017-09-25 Thread bitwise via Digitalmars-d-learn
On Monday, 25 September 2017 at 13:20:03 UTC, Steven Schveighoffer wrote: On 9/23/17 11:52 AM, bitwise wrote: Is it possible to tell if two objects represented by TypeInfo's are convertible to each other? Basically, is there a built in way to do this? int x; long y;

  1   2   >