Capturing by reference with "visit" from std.variant

2018-02-20 Thread Smaehtin via Digitalmars-d-learn
I'm trying to understand why the following doesn't work: import std.stdio; import std.variant; void main() { Algebraic!(string, int) test = "Test"; test.tryVisit!( (ref string s) { s = "Why does this not work?"; } ); writeln(test); } But this works fine: *test.peek!str

Re: Capturing by reference with "visit" from std.variant

2018-02-20 Thread Smaehtin via Digitalmars-d-learn
On Tuesday, 20 February 2018 at 16:15:56 UTC, Radu wrote: On Tuesday, 20 February 2018 at 16:01:11 UTC, Smaehtin wrote: I'm trying to understand why the following doesn't work: import std.stdio; import std.variant; void main() { Algebraic!(string, int) test = "Test"; test.tryVisit!(

Re: Capturing by reference with "visit" from std.variant

2018-02-20 Thread Smaehtin via Digitalmars-d-learn
On Tuesday, 20 February 2018 at 16:20:45 UTC, Smaehtin wrote: On Tuesday, 20 February 2018 at 16:15:56 UTC, Radu wrote: On Tuesday, 20 February 2018 at 16:01:11 UTC, Smaehtin wrote: I'm trying to understand why the following doesn't work: import std.stdio; import std.variant; void main() {

Re: C++ std::string_view equivalent in D?

2018-02-21 Thread Smaehtin via Digitalmars-d-learn
On Wednesday, 21 February 2018 at 09:21:58 UTC, 0x wrote: What is the equivalent of C++17 std::string_view (an object that can refer to a constant contiguous sequence of char-like objects with the first element of the sequence at position zero) in D? PS: I'm getting back to D after ye