void main()
{
int[string] test;
test["hello"] = 42;
if (auto it = "hello" in test)
{
}
}
Is there a way to get the value instead of a pointer? while keeping the conciseness (one line)
Thread overview | |||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
August 31 Associative Array, get value instead of poiter using `if (auto ..)`, possible? | ||||
---|---|---|---|---|
| ||||
Is there a way to get the value instead of a pointer? while keeping the conciseness (one line) |
August 31 Re: Associative Array, get value instead of poiter using `if (auto ..)`, possible? | ||||
---|---|---|---|---|
| ||||
Posted in reply to ryuukk_ | On Saturday, 31 August 2024 at 12:47:25 UTC, ryuukk_ wrote: >
Is there a way to get the value instead of a pointer? while keeping the conciseness (one line) Maybe if(auto it = test.get(“hello”, 0)) -Steve |
August 31 Re: Associative Array, get value instead of poiter using `if (auto ..)`, possible? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On Saturday, 31 August 2024 at 13:00:42 UTC, Steven Schveighoffer wrote: >On Saturday, 31 August 2024 at 12:47:25 UTC, ryuukk_ wrote: >
Is there a way to get the value instead of a pointer? while keeping the conciseness (one line) Maybe if(auto it = test.get(“hello”, 0)) -Steve Now i can't use 0 as a value, that's not a solution |
August 31 Re: Associative Array, get value instead of poiter using `if (auto ..)`, possible? | ||||
---|---|---|---|---|
| ||||
Posted in reply to ryuukk_ | On Saturday, 31 August 2024 at 12:47:25 UTC, ryuukk_ wrote: >
Is there a way to get the value instead of a pointer? while keeping the conciseness (one line) Once the next release of Phobos comes out, with PR 9039 merged, you'll be able to do it like this:
|
August 31 Re: Associative Array, get value instead of poiter using `if (auto ..)`, possible? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Paul Backus | On Saturday, 31 August 2024 at 14:25:29 UTC, Paul Backus wrote: >On Saturday, 31 August 2024 at 12:47:25 UTC, ryuukk_ wrote: >
Is there a way to get the value instead of a pointer? while keeping the conciseness (one line) Once the next release of Phobos comes out, with PR 9039 merged, you'll be able to do it like this:
See, that's the thing i hate about D, solving simple problem requires templates + import + function call I already lost interest, i'll solve that problem with something else |
August 31 Re: Associative Array, get value instead of poiter using `if (auto ..)`, possible? | ||||
---|---|---|---|---|
| ||||
Posted in reply to ryuukk_ | Let's see how other languages do it:
No imports, no templates, ONE LINER Please submit PRs to DMD, not phobos |
August 31 Re: Associative Array, get value instead of poiter using `if (auto ..)`, possible? | ||||
---|---|---|---|---|
| ||||
Posted in reply to ryuukk_ | On Saturday, 31 August 2024 at 15:38:49 UTC, ryuukk_ wrote: >Let's see how other languages do it:
No imports, no templates, ONE LINER Please submit PRs to DMD, not phobos It's good you're not in charge here because that is hideous. |
August 31 Re: Associative Array, get value instead of poiter using `if (auto ..)`, possible? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Lance Bachmeier | On Saturday, 31 August 2024 at 16:34:00 UTC, Lance Bachmeier wrote: >On Saturday, 31 August 2024 at 15:38:49 UTC, ryuukk_ wrote: >Let's see how other languages do it:
No imports, no templates, ONE LINER Please submit PRs to DMD, not phobos It's good you're not in charge here because that is hideous. Paul Backup solution is infinity better, i apologies I'll now leave, just like everyone else, sorry for the noise, who am i to expect improvements, i should have known better |
August 31 Re: Associative Array, get value instead of poiter using `if (auto ..)`, possible? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Paul Backus | On Saturday, 31 August 2024 at 14:25:29 UTC, Paul Backus wrote: >[...]
Is that functionally different from
? |
September 01 Re: Associative Array, get value instead of poiter using `if (auto ..)`, possible? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Lance Bachmeier |
On 01/09/2024 4:34 AM, Lance Bachmeier wrote:
> On Saturday, 31 August 2024 at 15:38:49 UTC, ryuukk_ wrote:
>> Let's see how other languages do it:
>>
>> ```zig
>> map.put("hello", 42);
>>
>> // get pointer
>> if (map.get("hello")) |*it| {
>> std.log.debug("{}", .{it});
>> }
>>
>> // get value
>> if (map.get("hello")) |it| {
>> std.log.debug("{}", .{it});
>> }
>> ```
>>
>> No imports, no templates, ONE LINER
>>
>> Please submit PRs to DMD, not phobos
>
> It's good you're not in charge here because that is hideous.
Hey now, there is no need to get personal, ryuukk is evaluating out ideas and there is nothing wrong with this.
|