Re: Creating an array of immutable objects

2017-02-14 Thread Jacob Carlborg via Digitalmars-d-learn
On 2017-02-15 01:08, David Zhang wrote: Thanks for your answers. Out of curiosity though, how could something like this be done with classes instead? You mean if FileDesc was a class? It's basically the same. You would need: Mutable array: 1. Add a constructor which sets all immutable instanc

Re: Creating an array of immutable objects

2017-02-14 Thread David Zhang via Digitalmars-d-learn
Thanks for your answers. Out of curiosity though, how could something like this be done with classes instead?

Re: Alias type with different initialiser.

2017-02-14 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, February 13, 2017 22:59:11 John Colvin via Digitalmars-d-learn wrote: > Also, it's > generally a bad idea to define `.init` for any type as code > generally expects this to be the compiler-generated property > (e.g. a value of type Initial!(int, 1) not of type int). And there's actuall

Re: Alias type with different initialiser.

2017-02-14 Thread Bastiaan Veelo via Digitalmars-d-learn
Thanks again. On Tuesday, 14 February 2017 at 14:08:31 UTC, John Colvin wrote: I would recommend making `template from(string moduleName)` global (maybe in a utils module?), there's no reason for it to be a member of Initial. Yes, I think there is high chance it will be part of Phobos, if ch

Re: Mallocator and 'shared'

2017-02-14 Thread Kagamin via Digitalmars-d-learn
On Tuesday, 14 February 2017 at 10:52:37 UTC, Johannes Pfau wrote: But if the interrupt accesses a variable and a normal function accesses the variable as well, the access needs to be 'volatile' (not cached into a register by the compiler; not closely related to this discussion) and atomic, as

Re: Policy-based design in D

2017-02-14 Thread TheGag96 via Digitalmars-d-learn
On Tuesday, 14 February 2017 at 10:05:19 UTC, TheFlyingFiddle wrote: (snip) Oh, I didn't know you could name mixin template instantiations like that! Thanks for the tip, that makes things work nicely!

Re: Mallocator and 'shared'

2017-02-14 Thread Moritz Maxeiner via Digitalmars-d-learn
On Tuesday, 14 February 2017 at 14:27:05 UTC, Kagamin wrote: On Monday, 13 February 2017 at 17:44:10 UTC, Moritz Maxeiner wrote: To be clear: While I might, in general, agree that using shared methods only for thread safe methods seems to be a sensible restriction, neither language nor compiler

Re: link.exe Error: 'Offset 38C42H Record Type 00C3'

2017-02-14 Thread realNoob via Digitalmars-d-learn
On Tuesday, 14 February 2017 at 14:04:39 UTC, Adam D. Ruppe wrote: On Tuesday, 14 February 2017 at 09:00:37 UTC, realNoob wrote: Error 1: Previous Definition Different : _D4xaru8ezFilterFAAyaAyaZAAya That is saying the function module xaru; string[] ezFilter(string[], string); is defined tw

Re: Mallocator and 'shared'

2017-02-14 Thread Johannes Pfau via Digitalmars-d-learn
Am Tue, 14 Feb 2017 14:38:32 + schrieb Kagamin : > On Tuesday, 14 February 2017 at 10:52:37 UTC, Johannes Pfau wrote: > > I remember some discussions about this some years ago and IIRC > > the final decision was that the compiler will not magically > > insert any barriers for shared variable

Re: Mallocator and 'shared'

2017-02-14 Thread Johannes Pfau via Digitalmars-d-learn
Am Tue, 14 Feb 2017 13:01:44 + schrieb Moritz Maxeiner : > > It's not supposed to. Also, your example does not implement the > same semantics as what I posted and yes, in your example, there's > no need for memory barriers. In the example I posted, > synchronization is not necessary, mem

Re: Mallocator and 'shared'

2017-02-14 Thread Kagamin via Digitalmars-d-learn
On Tuesday, 14 February 2017 at 10:52:37 UTC, Johannes Pfau wrote: I remember some discussions about this some years ago and IIRC the final decision was that the compiler will not magically insert any barriers for shared variables. It was so some years ago, not sure if it's still so. I suspect

Re: Mallocator and 'shared'

2017-02-14 Thread Kagamin via Digitalmars-d-learn
On Monday, 13 February 2017 at 17:44:10 UTC, Moritz Maxeiner wrote: To be clear: While I might, in general, agree that using shared methods only for thread safe methods seems to be a sensible restriction, neither language nor compiler require it to be so; and absence of evidence of a useful app

Re: Alias type with different initialiser.

2017-02-14 Thread John Colvin via Digitalmars-d-learn
On Tuesday, 14 February 2017 at 11:34:22 UTC, Bastiaan Veelo wrote: On Monday, 13 February 2017 at 22:59:11 UTC, John Colvin wrote: Why not use a constructor instead of static opCall? I don't know, this comes from http://dlang.org/spec/struct.html#dynamic_struct_init. Your constructor looks

Re: link.exe Error: 'Offset 38C42H Record Type 00C3'

2017-02-14 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 14 February 2017 at 09:00:37 UTC, realNoob wrote: Error 1: Previous Definition Different : _D4xaru8ezFilterFAAyaAyaZAAya That is saying the function module xaru; string[] ezFilter(string[], string); is defined twice. Could be something weird in your code, but I would guess the m

Re: Alias type with different initialiser.

2017-02-14 Thread John Colvin via Digitalmars-d-learn
On Tuesday, 14 February 2017 at 10:49:19 UTC, Bastiaan Veelo wrote: On Tuesday, 14 February 2017 at 01:31:10 UTC, John Colvin wrote: On Monday, 13 February 2017 at 22:59:11 UTC, John Colvin wrote: [ snip ] sorry, made a typo, that should have been alias int1 = Initial!(int, 1); stat

Re: Mallocator and 'shared'

2017-02-14 Thread Moritz Maxeiner via Digitalmars-d-learn
On Tuesday, 14 February 2017 at 13:01:44 UTC, Moritz Maxeiner wrote: Of course, I just wanted to point out that Kagamin's post scriptum is a simplification I cannot agree with. As a best practice? Sure. As a "never do it"? No. Sorry for the double post, error in the above, please use this ins

Re: Mallocator and 'shared'

2017-02-14 Thread Moritz Maxeiner via Digitalmars-d-learn
On Tuesday, 14 February 2017 at 10:52:37 UTC, Johannes Pfau wrote: The compiler of course can't require shared methods to be thread-safe as it simply can't prove thread-safety in all cases. This is like shared/trusted: You are supposed to make sure that a function behaves as expected. The compi

Re: Alias type with different initialiser.

2017-02-14 Thread Bastiaan Veelo via Digitalmars-d-learn
On Monday, 13 February 2017 at 22:59:11 UTC, John Colvin wrote: Why not use a constructor instead of static opCall? I don't know, this comes from http://dlang.org/spec/struct.html#dynamic_struct_init. Your constructor looks a lot better. Am I missing a test case where static opCall would be

Re: Mallocator and 'shared'

2017-02-14 Thread Johannes Pfau via Digitalmars-d-learn
Am Mon, 13 Feb 2017 17:44:10 + schrieb Moritz Maxeiner : > > Thread unsafe methods shouldn't be marked shared, it doesn't > > make sense. If you don't want to provide thread-safe interface, > > don't mark methods as shared, so they will not be callable on a > > shared instance and thus the

Re: Alias type with different initialiser.

2017-02-14 Thread Bastiaan Veelo via Digitalmars-d-learn
On Tuesday, 14 February 2017 at 01:31:10 UTC, John Colvin wrote: On Monday, 13 February 2017 at 22:59:11 UTC, John Colvin wrote: [ snip ] sorry, made a typo, that should have been alias int1 = Initial!(int, 1); static assert(int1.initial == 1); // typeof(int1.initial) == int st

Re: Policy-based design in D

2017-02-14 Thread TheFlyingFiddle via Digitalmars-d-learn
On Tuesday, 14 February 2017 at 06:48:33 UTC, TheGag96 wrote: Tonight I stumbled upon Andrei's concept of policy-based design (https://en.wikipedia.org/wiki/Policy-based_design) and tried to implement their example in D with the lack of multiple inheritance in mind. https://dpaste.dzfl.pl/adc

Re: Creating an array of immutable objects

2017-02-14 Thread Jacob Carlborg via Digitalmars-d-learn
On 2017-02-14 01:59, David Zhang wrote: Hi, I have a struct with two immutable members, and I want to make an array of them. How do I to this? I'm using allocators for this. string[] paths; struct FileDesc { immutable string path; immutable uint index; } _fileDesc = /*something*/; Yo

link.exe Error: 'Offset 38C42H Record Type 00C3'

2017-02-14 Thread realNoob via Digitalmars-d-learn
Hello. I got a problem this: [LDC(ldmd2)] -- Success. C:\MyFolders\src>ldmd2 --version LDC - the LLVM D compiler (1.1.0): based on DMD v2.071.2 and LLVM 3.9.1 built with LDC - the LLVM D compiler (1.1.0) Default target: x86_64-pc