Re: why won't byPair work with a const AA?

2017-08-03 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/3/17 4:30 AM, Olivier FAURE wrote: I understand the general concept you're describing, but what exactly are tail modifiers? It's the first time I see this name, and my google-fu gives me nothing. tail modifiers are modifiers that only apply to the "tail" of the type. For example

Re: why won't byPair work with a const AA?

2017-08-03 Thread Olivier FAURE via Digitalmars-d-learn
On Wednesday, 2 August 2017 at 18:06:03 UTC, H. S. Teoh wrote: On Wed, Aug 02, 2017 at 01:15:44PM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: [...] The real answer is to have tail modifiers for structs, so you can do the same thing an array does. Note that if Result is an array,

Re: why won't byPair work with a const AA?

2017-08-02 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Aug 02, 2017 at 11:06:03AM -0700, H. S. Teoh via Digitalmars-d-learn wrote: [...] > auto byPair(AA)(inout(AA) aa) > { > alias Modifiers = std.traits.getModifiers!AA; > struct Result { > std.traits.ApplyModifiers!(Slot*,

Re: why won't byPair work with a const AA?

2017-08-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/2/17 2:06 PM, H. S. Teoh via Digitalmars-d-learn wrote: On Wed, Aug 02, 2017 at 01:15:44PM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: [...] It's not currently legal, you can't have inout members of a struct. This could be added, but it still wouldn't work, because you

Re: why won't byPair work with a const AA?

2017-08-02 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Aug 02, 2017 at 01:15:44PM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: [...] > It's not currently legal, you can't have inout members of a struct. > This could be added, but it still wouldn't work, because you can't > "strip off" the inout part upon return. > > The real

Re: why won't byPair work with a const AA?

2017-08-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/2/17 11:52 AM, H. S. Teoh via Digitalmars-d-learn wrote: On Wed, Aug 02, 2017 at 08:20:23AM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: On 8/1/17 7:44 PM, H. S. Teoh via Digitalmars-d-learn wrote: [...] You can iterate a const AA, but if you want to iterate a non-const

Re: why won't byPair work with a const AA?

2017-08-02 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Aug 02, 2017 at 08:20:23AM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: > On 8/1/17 7:44 PM, H. S. Teoh via Digitalmars-d-learn wrote: [...] > You can iterate a const AA, but if you want to iterate a non-const AA, > you need a different type. > > For instance, if your AA is

Re: why won't byPair work with a const AA?

2017-08-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/1/17 7:44 PM, H. S. Teoh via Digitalmars-d-learn wrote: On Tue, Aug 01, 2017 at 07:31:41PM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: On 8/1/17 7:15 PM, H. S. Teoh via Digitalmars-d-learn wrote: On Tue, Aug 01, 2017 at 07:09:45PM -0400, Steven Schveighoffer via

Re: why won't byPair work with a const AA?

2017-08-01 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Aug 01, 2017 at 07:31:41PM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: > On 8/1/17 7:15 PM, H. S. Teoh via Digitalmars-d-learn wrote: > > On Tue, Aug 01, 2017 at 07:09:45PM -0400, Steven Schveighoffer via > > Digitalmars-d-learn wrote: > > > If this were a true

Re: why won't byPair work with a const AA?

2017-08-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/1/17 7:15 PM, H. S. Teoh via Digitalmars-d-learn wrote: On Tue, Aug 01, 2017 at 07:09:45PM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: If this were a true implementation without the opaqueness, it would not work properly. [...] Actually, a proper implementation would

Re: why won't byPair work with a const AA?

2017-08-01 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Aug 01, 2017 at 07:09:45PM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: > On 8/1/17 6:50 PM, H. S. Teoh via Digitalmars-d-learn wrote: [...] > > Actually, there's nothing about the implementation of both > > byKeyValue (the underlying implementation in druntime) and byPair

Re: why won't byPair work with a const AA?

2017-08-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/1/17 6:50 PM, H. S. Teoh via Digitalmars-d-learn wrote: On Tue, Aug 01, 2017 at 10:04:18AM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: On 7/30/17 12:19 AM, Matthew Gamble wrote: [...] import std.array; import std.algorithm; class A { this() { aa = ["a":1, "b" : 2,

Re: why won't byPair work with a const AA?

2017-08-01 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Aug 01, 2017 at 10:04:18AM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: > On 7/30/17 12:19 AM, Matthew Gamble wrote: [...] > > import std.array; > > import std.algorithm; > > > > class A > > { > > this() { aa = ["a":1, "b" : 2, "c" : 3]; } > > auto pairs()

Re: why won't byPair work with a const AA?

2017-08-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/30/17 12:19 AM, Matthew Gamble wrote: I have a class member function from which I'm trying to return a sorted array of key, value tuples stored in an associative array as a private member. The member function should be able to be marked const to prevent the AA from being modified. I have

Re: why won't byPair work with a const AA?

2017-07-29 Thread Ali Çehreli via Digitalmars-d-learn
On 07/29/2017 10:15 PM, Matthew Gamble wrote: >> I think it should work. I think a cast to unqualified is a safe >> workaround in this case: >> >> auto pairs() @property const { return >> (cast(int[string])aa).byPair.array.sort().release; } As your question reveals, casting away const is

Re: why won't byPair work with a const AA?

2017-07-29 Thread Matthew Gamble via Digitalmars-d-learn
On Sunday, 30 July 2017 at 04:36:19 UTC, Ali Çehreli wrote: On 07/29/2017 09:19 PM, Matthew Gamble wrote: I have a class member function from which I'm trying to return a sorted array of key, value tuples stored in an associative array as a private member. The member function should be able to

Re: why won't byPair work with a const AA?

2017-07-29 Thread Ali Çehreli via Digitalmars-d-learn
On 07/29/2017 09:19 PM, Matthew Gamble wrote: I have a class member function from which I'm trying to return a sorted array of key, value tuples stored in an associative array as a private member. The member function should be able to be marked const to prevent the AA from being modified. I have