Re: fread return value?

2025-07-30 Thread Andy Valencia via Digitalmars-d-learn
On Wednesday, 30 July 2025 at 20:03:37 UTC, 0xEAB wrote: On Wednesday, 30 July 2025 at 19:45:20 UTC, Andy Valencia wrote: but I'd like to understand what's up before just changing my code to assume 0 is a success value? AFAICT your code is wrong. The parameters of `fread()` are `ptr`, `size`,

Re: fread return value?

2025-07-30 Thread Ali Çehreli via Digitalmars-d-learn
On 7/30/25 12:45 PM, Andy Valencia wrote: > Scratching my head here. fread() I haven't used anything other than rawRead() for that purpose. rawRead() returns a slice of what it's just read: import std.algorithm; import std.exception; import std.file; import std.format; import std.stdio; void

Re: fread return value?

2025-07-30 Thread 0xEAB via Digitalmars-d-learn
On Wednesday, 30 July 2025 at 19:45:20 UTC, Andy Valencia wrote: but I'd like to understand what's up before just changing my code to assume 0 is a success value? AFAICT your code is wrong. The parameters of `fread()` are `ptr`, `size`, `n`, `stream`. Your code is attempting to read `1` unit wi

Re: fread return value?

2025-07-30 Thread monkyyy via Digitalmars-d-learn
On Wednesday, 30 July 2025 at 19:45:20 UTC, Andy Valencia wrote: Scratching my head here. fread() really appears to be the standard C idea of an fread(), so it returns a count. Instead, it returns 0. The buf[] does indeed have the expected content, but I'd like to understand what's up before

fread return value?

2025-07-30 Thread Andy Valencia via Digitalmars-d-learn
Scratching my head here. fread() really appears to be the standard C idea of an fread(), so it returns a count. Instead, it returns 0. The buf[] does indeed have the expected content, but I'd like to understand what's up before just changing my code to assume 0 is a success value? (Linux,

Re: Looking to get typeof parseXML return value

2021-09-07 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 7 September 2021 at 05:00:50 UTC, Chris Piker wrote: On Tuesday, 7 September 2021 at 04:40:25 UTC, jfondren wrote: typeof(parseXML!simpleXML("")) xml; Hey, I like this trick! I was wondering what to use for the const(char)[] variable in the typeof statement. It's blindingly

Re: Looking to get typeof parseXML return value

2021-09-07 Thread bauss via Digitalmars-d-learn
On Tuesday, 7 September 2021 at 08:27:33 UTC, JN wrote: On Tuesday, 7 September 2021 at 04:13:08 UTC, Chris Piker wrote: Like almost all new users to D I'm tripping over how to save and pass around variables since nothing has an understandable type anymore and you can't use "auto" for *class me

Re: Looking to get typeof parseXML return value

2021-09-07 Thread JN via Digitalmars-d-learn
On Tuesday, 7 September 2021 at 04:13:08 UTC, Chris Piker wrote: Like almost all new users to D I'm tripping over how to save and pass around variables since nothing has an understandable type anymore and you can't use "auto" for *class member* storage types. I struggle with this often. Templ

Re: Looking to get typeof parseXML return value

2021-09-06 Thread Chris Piker via Digitalmars-d-learn
On Tuesday, 7 September 2021 at 04:40:25 UTC, jfondren wrote: typeof(parseXML!simpleXML("")) xml; Hey, I like this trick! I was wondering what to use for the const(char)[] variable in the typeof statement. It's blindingly obvious in retrospect. Wouldn't work so well if there wasn't a

Re: Looking to get typeof parseXML return value

2021-09-06 Thread Chris Piker via Digitalmars-d-learn
On Tuesday, 7 September 2021 at 04:13:08 UTC, Chris Piker wrote: Any ideas on how to get the return type of `parseXML` below: ``` import dxml.parser; const(char)[] _mmfile; //_mmfile initialization TYPE??? _entityRng = parseXML!(simpleXML)(_mmfile); ``` Though it's ususally bad form to respond

Re: Looking to get typeof parseXML return value

2021-09-06 Thread jfondren via Digitalmars-d-learn
On Tuesday, 7 September 2021 at 04:13:08 UTC, Chris Piker wrote: Any ideas on how to get the return type of `parseXML` below: ``` import dxml.parser; const(char)[] _mmfile; //_mmfile initialization TYPE??? _entityRng = parseXML!(simpleXML)(_mmfile); ``` *before* calling parseXML, so that it can

Looking to get typeof parseXML return value

2021-09-06 Thread Chris Piker via Digitalmars-d-learn
Hi D I'm using the **dxml** library since I like it's "pull here for more data" mentality. I've come across the need to save an entity range created by the `parseXML` function as a class member so that I can tuck it away and pull more data as needed. Like almost all new users to D I'm trip

Re: Return Value Optimization: specification, requirements?

2019-02-02 Thread Eugene Wissner via Digitalmars-d-learn
On Saturday, 2 February 2019 at 09:58:25 UTC, XavierAP wrote: I've heard here and there that D guarantees RVO, or is even specified to do so... Is it spelled out in the language specification or elsewhere? I haven't found it. The D spec is often not the right place to look for the specifica

Return Value Optimization: specification, requirements?

2019-02-02 Thread XavierAP via Digitalmars-d-learn
I've heard here and there that D guarantees RVO, or is even specified to do so... Is it spelled out in the language specification or elsewhere? I haven't found it. Do you know the exact requirements for RVO or NRVO to be possible in theory, and to be guaranteed in practice in D? Does it depe

Re: Return value in BetterC mode.

2018-02-18 Thread meppl via Digitalmars-d-learn
On Saturday, 17 February 2018 at 13:47:28 UTC, meppl wrote: On Saturday, 17 February 2018 at 07:58:40 UTC, ANtlord wrote: ... ... sadly I have no good idea how to name the title of that issue :/ I looked at it again and came up with a title name: https://issues.dlang.org/show_bug.cgi?id=184

Re: Return value in BetterC mode.

2018-02-17 Thread meppl via Digitalmars-d-learn
On Saturday, 17 February 2018 at 07:58:40 UTC, ANtlord wrote: Hello! Yesterday I found an interesting issue for myself while I was implementing unique pointer for my project in BetterC. When I was trying to return new instance from a `move` method I got calling of destructor the instance. When

Return value in BetterC mode.

2018-02-17 Thread ANtlord via Digitalmars-d-learn
Hello! Yesterday I found an interesting issue for myself while I was implementing unique pointer for my project in BetterC. When I was trying to return new instance from a `move` method I got calling of destructor the instance. When the instance is out of scope the calling is happens again. I

Re: Missing return value error not present with template

2017-11-15 Thread Tony via Digitalmars-d-learn
On Wednesday, 15 November 2017 at 11:20:24 UTC, Biotronic wrote: Thanks Biotronic! I found this on the html documentation for templates: "The body of the TemplateDeclaration must be syntactically correct even if never instantiated. Semantic analysis is not done until instantiated", and that is

Re: Missing return value error not present with template

2017-11-15 Thread Biotronic via Digitalmars-d-learn
On Wednesday, 15 November 2017 at 08:43:01 UTC, Tony wrote: Error: function test_warnings.MyClass.SomeMethod has no return statement, but is expected to return a value of type int but if I make it a template class: class MyClass(T) { there is no compile error. I don't know why the error isn't

Re: Missing return value error not present with template

2017-11-15 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 15 November 2017 at 08:43:01 UTC, Tony wrote: This code: class MyClass { public: int SomeMethod () { } } void main() { } gets a compile error: Error: function test_warnings.MyClass.SomeMethod has no return statement, but is expected to return a value of type int b

Missing return value error not present with template

2017-11-15 Thread Tony via Digitalmars-d-learn
This code: class MyClass { public: int SomeMethod () { } } void main() { } gets a compile error: Error: function test_warnings.MyClass.SomeMethod has no return statement, but is expected to return a value of type int but if I make it a template class: class MyClass(T) { there

Re: Returning the address of a reference return value in @safe code - 2.072 regression?

2017-02-22 Thread Kagamin via Digitalmars-d-learn
On Monday, 20 February 2017 at 20:49:43 UTC, Johan Engelen wrote: The error is: "cannot take address of ref return of this.foo() in @safe function bar". Maybe a bugfix in safety system? Should it go through deprecation process?

Re: Returning the address of a reference return value in @safe code - 2.072 regression?

2017-02-21 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Monday, 20 February 2017 at 21:05:17 UTC, Jack Stouffer wrote: On Monday, 20 February 2017 at 20:54:31 UTC, Jack Stouffer wrote: On Monday, 20 February 2017 at 20:49:43 UTC, Johan Engelen wrote: ... Yeah, this is another regression caused by DIP1000. Christ. For the record, the current

Re: Returning the address of a reference return value in @safe code - 2.072 regression?

2017-02-20 Thread Jack Stouffer via Digitalmars-d-learn
On Monday, 20 February 2017 at 20:54:31 UTC, Jack Stouffer wrote: On Monday, 20 February 2017 at 20:49:43 UTC, Johan Engelen wrote: ... Yeah, this is another regression caused by DIP1000. Christ. For the record, the current list of regressions caused by DIP1000 https://issues.dlang.org/sho

Re: Returning the address of a reference return value in @safe code - 2.072 regression?

2017-02-20 Thread Jack Stouffer via Digitalmars-d-learn
On Monday, 20 February 2017 at 20:49:43 UTC, Johan Engelen wrote: ... Yeah, this is another regression caused by DIP1000. Christ.

Returning the address of a reference return value in @safe code - 2.072 regression?

2017-02-20 Thread Johan Engelen via Digitalmars-d-learn
This code compiles with 2.071, but not with 2.072 nor 2.073: ``` struct S { int i; auto ref foo() @safe { return i; } auto bar() @safe { return &foo(); // <-- Error } } void main() { auto s = S(); s.bar(

Re: Template overloads involving `string` and `char[constant]` return value

2016-09-21 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 21 September 2016 at 12:39:57 UTC, Johan Engelen wrote: It should really be mentioned in the documentation of toHexString, with an actual example instead of a unittest. Do you use my dpldocs.info? I add such notes there from time to time: http://dpldocs.info/experimental-docs/s

Re: Template overloads involving `string` and `char[constant]` return value

2016-09-21 Thread Johan Engelen via Digitalmars-d-learn
On Wednesday, 21 September 2016 at 13:06:08 UTC, Adam D. Ruppe wrote: the variable you are assigning the result to never does anything with regard to overloads or template args. Gotcha, thanks.

Re: Template overloads involving `string` and `char[constant]` return value

2016-09-21 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 21 September 2016 at 12:29:54 UTC, Johan Engelen wrote: Wouldn't something like this be possible? `T toHexString(string toHexString(Order order = Order.increasing, LetterCase letterCase = LetterCase.upper, T)(.) if (T == string)` I'm not sure what that's supposed to be.

Re: Template overloads involving `string` and `char[constant]` return value

2016-09-21 Thread Johan Engelen via Digitalmars-d-learn
On Wednesday, 21 September 2016 at 12:20:14 UTC, Adam D. Ruppe wrote: This is a pretty common pitfall (and IMO one of the most egregious design flaws in the language), I see it all the time. I write very little D code, so I guess it had to happen at some point then. Man, this is really bad :

Re: Template overloads involving `string` and `char[constant]` return value

2016-09-21 Thread Johan Engelen via Digitalmars-d-learn
On Wednesday, 21 September 2016 at 12:20:14 UTC, Adam D. Ruppe wrote: It is neither, the compiler chose the right overload (remember, overloads are chosen based on the arguments alone, the type you specify for the variable holding the return value isn't a consideration there) an

Re: Template overloads involving `string` and `char[constant]` return value

2016-09-21 Thread Adam D. Ruppe via Digitalmars-d-learn
It is neither, the compiler chose the right overload (remember, overloads are chosen based on the arguments alone, the type you specify for the variable holding the return value isn't a consideration there) and the implementation of each overload is correct. But the horribly wrong imp

Template overloads involving `string` and `char[constant]` return value

2016-09-21 Thread Johan Engelen via Digitalmars-d-learn
What's the bug in the following code: ```d import std.digest.md; import std.stdio; pragma(inline, false) // just in case string getHash() { ubyte[16] hash = [1,2,3,4,5,6,6,78,8,8,7,7,6,3,2,3]; string a = toHexString(hash); return a; } pragma(inline, false) // just in case void destr

Re: mismatch and return value

2016-07-13 Thread celavek via Digitalmars-d-learn
Thank you both for the very good insights. Community wise +1 :)

Re: mismatch and return value

2016-07-13 Thread ketmar via Digitalmars-d-learn
On Wednesday, 13 July 2016 at 11:11:51 UTC, celavek wrote: I misunderstood the doc and I got a bit confused by the range - in C++ I would have incremented the iterators but here I did not know what to do exactly as I could not match the 2 different concepts in functionality. it mostly maps to

Re: mismatch and return value

2016-07-13 Thread ketmar via Digitalmars-d-learn
eturn an empty tuple rather than a tuple of two empty ranges. Being more specific about the return value is only a few extra words that I wouldn't judge as being "too wordy". probably you are right. it is somewhat hard to judge when you know the concept "by your heart"

Re: mismatch and return value

2016-07-13 Thread Mike Parker via Digitalmars-d-learn
On Wednesday, 13 July 2016 at 11:11:51 UTC, celavek wrote: Thank you for the example. I misunderstood the doc and I got a bit confused by the range - in C++ I would have incremented the iterators but here I did not know what to do exactly as I could not match the 2 different concepts in funct

Re: mismatch and return value

2016-07-13 Thread Mike Parker via Digitalmars-d-learn
has achieved a certain level of comfort and familiarity with ranges and the range-based functions in Phobos. This particular function could just as easily be inferred to return an empty tuple rather than a tuple of two empty ranges. Being more specific about the return value is only a few extra words that I wouldn't judge as being "too wordy".

Re: mismatch and return value

2016-07-13 Thread celavek via Digitalmars-d-learn
Thank you for the example. I misunderstood the doc and I got a bit confused by the range - in C++ I would have incremented the iterators but here I did not know what to do exactly as I could not match the 2 different concepts in functionality.

Re: mismatch and return value

2016-07-13 Thread ketmar via Digitalmars-d-learn
On Wednesday, 13 July 2016 at 11:06:56 UTC, celavek wrote: On Wednesday, 13 July 2016 at 10:41:44 UTC, ketmar wrote: I understand your point but it should not be a matter of guessing. It should be explicitly stated by the documentation. then people will start to complain that documentation is

Re: mismatch and return value

2016-07-13 Thread celavek via Digitalmars-d-learn
On Wednesday, 13 July 2016 at 10:41:44 UTC, ketmar wrote: let's read the doc again: "Returns a tuple with the reduced ranges that start with the two mismatched values." simple logic allows us to guess that it should return tuple with two empty ranges. and it really does. I understand your

Re: mismatch and return value

2016-07-13 Thread Mike Parker via Digitalmars-d-learn
inite loop. What does mismatch return when it cannot actually find a mismatch? Is the return value immutable? I do not get any warnings from the compiler(dmd). The return value is described as: "a tuple with the reduced ranges that start with the two mismatched values" This means

Re: mismatch and return value

2016-07-13 Thread ketmar via Digitalmars-d-learn
ic allows us to guess that it should return tuple with two empty ranges. and it really does. Is the return value immutable? as with most other std.algo functions, the returned range has same properties as source range.

Re: mismatch and return value

2016-07-13 Thread Mike Parker via Digitalmars-d-learn
On Wednesday, 13 July 2016 at 09:59:30 UTC, celavek wrote: As a side note the documentation of the standard library is not digestible to say the least - there is missing info(e.g. what does mismatch return if no mismatch found) and lacks user-friendliness and details. Whenever you find areas

mismatch and return value

2016-07-13 Thread celavek via Digitalmars-d-learn
lly find a mismatch? Is the return value immutable? I do not get any warnings from the compiler(dmd). As a side note the documentation of the standard library is not digestible to say the least - there is missing info(e.g. what does mismatch return if no mismatch found) and lacks user-friendliness and details.

Re: Testing Return Value Optimization (RVO)

2015-09-28 Thread chmike via Digitalmars-d-learn
Oops found it my self. I had to use auto x = foo();

Re: Testing Return Value Optimization (RVO)

2015-09-28 Thread chmike via Digitalmars-d-learn
I tried your code as this and it doesn't work. #!/usr/bin/rdmd -O import std.stdio; struct S { int a; @disable this(this); }; S foo() { S v; v.a = 1; writeln(&v); return v; } void main() { S x; x = foo(); writeln(&x); } I even tried with dmd -O without su

Re: Testing Return Value Optimization (RVO)

2015-09-27 Thread Rene Zwanenburg via Digitalmars-d-learn
On Sunday, 27 September 2015 at 13:55:02 UTC, chmike wrote: Can someone please explain me why this doesn't work as I would expect RVO to work ? I'm not an expert on the subject so this may contain some inaccuracies, but the gist of it is: As the name implies, NRVO is an optimization and ther

Testing Return Value Optimization (RVO)

2015-09-27 Thread chmike via Digitalmars-d-learn
doesn't do RVO as I expected it would do it. Here is the D code. It is very similar to the C code I tested with gcc and clang : --- #!/usr/bin/rdmd -O import std.stdio; struct S { int a, b; }; S foo(S* p) { S v = {1, 2}; writeln("foo: return value optimization: ", p == &a

Re: Encapsulate return value in scoped

2015-06-18 Thread Ali Çehreli via Digitalmars-d-learn
On 06/18/2015 05:25 PM, Yuxuan Shui wrote: > What problem can moving a scoped cause when there's > no reference to its inner class? I am curious as well. Could it be related to the object's 'monitor'? Perhaps some other code may have a reference to monitor? And that reference does not constitu

Re: Encapsulate return value in scoped

2015-06-18 Thread Yuxuan Shui via Digitalmars-d-learn
On Friday, 19 June 2015 at 00:00:50 UTC, Ali Çehreli wrote: On 06/18/2015 04:53 PM, Yuxuan Shui wrote: > On Thursday, 11 June 2015 at 21:38:59 UTC, Ali Çehreli wrote: >> About returning scoped!C, I think it works: > I just find out that the document of scoped says that "It's Thanks for fixing

Re: Encapsulate return value in scoped

2015-06-18 Thread Ali Çehreli via Digitalmars-d-learn
On 06/18/2015 04:53 PM, Yuxuan Shui wrote: > On Thursday, 11 June 2015 at 21:38:59 UTC, Ali Çehreli wrote: >> About returning scoped!C, I think it works: > I just find out that the document of scoped says that "It's Thanks for fixing the typo there. (The documentations has lower case: "it's".

Re: Encapsulate return value in scoped

2015-06-18 Thread Yuxuan Shui via Digitalmars-d-learn
On Thursday, 11 June 2015 at 21:38:59 UTC, Ali Çehreli wrote: On 06/11/2015 12:51 PM, Yuxuan Shui wrote: > On Thursday, 11 June 2015 at 19:23:49 UTC, Ali Çehreli wrote: >> [...] > > Can you explain more about why the destructor is not called when > returning a struct? Are you asking in general

Re: Encapsulate return value in scoped

2015-06-11 Thread Yuxuan Shui via Digitalmars-d-learn
On Thursday, 11 June 2015 at 19:23:49 UTC, Ali Çehreli wrote: On 06/11/2015 11:43 AM, Yuxuan Shui wrote: On Thursday, 11 June 2015 at 17:34:56 UTC, Steven Schveighoffer wrote: On 6/11/15 1:28 PM, Yuxuan Shui wrote: On Thursday, 11 June 2015 at 09:11:47 UTC, Daniel Kozák wrote: On Thu, 11 Jun

Re: Encapsulate return value in scoped

2015-06-11 Thread Ali Çehreli via Digitalmars-d-learn
On 06/11/2015 11:43 AM, Yuxuan Shui wrote: On Thursday, 11 June 2015 at 17:34:56 UTC, Steven Schveighoffer wrote: On 6/11/15 1:28 PM, Yuxuan Shui wrote: On Thursday, 11 June 2015 at 09:11:47 UTC, Daniel Kozák wrote: On Thu, 11 Jun 2015 09:01:04 + Yuxuan Shui via Digitalmars-d-learn wrote

Re: Encapsulate return value in scoped

2015-06-11 Thread Yuxuan Shui via Digitalmars-d-learn
On Thursday, 11 June 2015 at 17:34:56 UTC, Steven Schveighoffer wrote: On 6/11/15 1:28 PM, Yuxuan Shui wrote: On Thursday, 11 June 2015 at 09:11:47 UTC, Daniel Kozák wrote: On Thu, 11 Jun 2015 09:01:04 + Yuxuan Shui via Digitalmars-d-learn wrote: A x = scoped!A(10); use auto x = s

Re: Encapsulate return value in scoped

2015-06-11 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/11/15 1:28 PM, Yuxuan Shui wrote: On Thursday, 11 June 2015 at 09:11:47 UTC, Daniel Kozák wrote: On Thu, 11 Jun 2015 09:01:04 + Yuxuan Shui via Digitalmars-d-learn wrote: A x = scoped!A(10); use auto x = scoped!A(10); Thanks! Curious question, why doesn't compiler reject thi

Re: Encapsulate return value in scoped

2015-06-11 Thread Yuxuan Shui via Digitalmars-d-learn
On Thursday, 11 June 2015 at 09:11:47 UTC, Daniel Kozák wrote: On Thu, 11 Jun 2015 09:01:04 + Yuxuan Shui via Digitalmars-d-learn wrote: A x = scoped!A(10); use auto x = scoped!A(10); Thanks! Curious question, why doesn't compiler reject this code?

Re: Encapsulate return value in scoped

2015-06-11 Thread Daniel Kozák via Digitalmars-d-learn
On Thu, 11 Jun 2015 09:01:04 + Yuxuan Shui via Digitalmars-d-learn wrote: > A x = scoped!A(10); use auto x = scoped!A(10);

Re: Encapsulate return value in scoped

2015-06-11 Thread Yuxuan Shui via Digitalmars-d-learn
On Thursday, 11 June 2015 at 08:48:22 UTC, Yuxuan Shui wrote: Is there a way to encapsulate return value into scoped? Say I have a function that returns a new object: X new_x(T t...) { //Super complex input processing return new X(something); } And I want to encapsulate the result

Encapsulate return value in scoped

2015-06-11 Thread Yuxuan Shui via Digitalmars-d-learn
Is there a way to encapsulate return value into scoped? Say I have a function that returns a new object: X new_x(T t...) { //Super complex input processing return new X(something); } And I want to encapsulate the result using scoped, is that possible? Can I just do: return scoped

Re: Better Return Value for findSplit*()

2015-05-16 Thread via Digitalmars-d-learn
On Saturday, 16 May 2015 at 10:47:36 UTC, Jakob Ovrum wrote: Nice! Should I make a PR? I think that would be very welcome. https://github.com/D-Programming-Language/phobos/pull/3288

Re: Better Return Value for findSplit*()

2015-05-16 Thread Jakob Ovrum via Digitalmars-d-learn
On Saturday, 16 May 2015 at 10:28:11 UTC, Per Nordlöw wrote: Nice! Should I make a PR? I think that would be very welcome.

Re: Better Return Value for findSplit*()

2015-05-16 Thread via Digitalmars-d-learn
On Saturday, 16 May 2015 at 09:56:22 UTC, Jakob Ovrum wrote: It can be implemented in a backwards-compatible way as a subtype of a Tuple. struct FindSplit(R) { Tuple!(R, "pre", R, "separator", R, "post") asTuple; bool opCast(T : bool)() { return !asTuple.separator.empty;

Re: Better Return Value for findSplit*()

2015-05-16 Thread Jakob Ovrum via Digitalmars-d-learn
On Saturday, 16 May 2015 at 09:36:30 UTC, Per Nordlöw wrote: After having written a lot of text pattern matching functions using Phobos' findSplit, findSplitBefore, findSplitAfter, and some more I've written myself I've come to the conclusion that I would like to enhance these functions to inst

Better Return Value for findSplit*()

2015-05-16 Thread via Digitalmars-d-learn
After having written a lot of text pattern matching functions using Phobos' findSplit, findSplitBefore, findSplitAfter, and some more I've written myself I've come to the conclusion that I would like to enhance these functions to instead return a struct instead of tuples. This struct would typi

Re: Appender.put return value

2014-07-24 Thread monarch_dodra via Digitalmars-d-learn
On Thursday, 24 July 2014 at 17:43:36 UTC, JR wrote: Is there a big reason why Appender.put doesn't return &this? http://dpaste.dzfl.pl/bb840e3e349e It would allow for convenient chaining. :< AFAIK, no reason no. That said, it wouldn't be useable in generic code.

Re: Appender.put return value

2014-07-24 Thread Temtaime via Digitalmars-d-learn
Offtop It's better to return "this" and have return type "ref auto" i think.

Appender.put return value

2014-07-24 Thread JR via Digitalmars-d-learn
Is there a big reason why Appender.put doesn't return &this? http://dpaste.dzfl.pl/bb840e3e349e It would allow for convenient chaining. :<

Re: const ref type as return value

2013-11-29 Thread Namespace
On Friday, 29 November 2013 at 09:05:50 UTC, Oleg B wrote: [code] import std.stdio; struct A { int val; } A a; class X { const ref A func() { return a; } } void main() { auto x = new X; x.func().val = 5; writeln( a ); } [/code] in this case 'const' mean 'const method' and variabl

const ref type as return value

2013-11-29 Thread Oleg B
[code] import std.stdio; struct A { int val; } A a; class X { const ref A func() { return a; } } void main() { auto x = new X; x.func().val = 5; writeln( a ); } [/code] in this case 'const' mean 'const method' and variable 'a' changed. if write [code] class X { const(ref A) func(

Re: Bug: Accessing return value of type static array with length 1 or 2 by index.

2013-04-21 Thread deed
bug submitted: http://d.puremagic.com/issues/show_bug.cgi?id=9969 Thanks for reporting. By the way, I was compiling for Windows and had only compile time errors.

Re: Bug: Accessing return value of type static array with length 1 or 2 by index.

2013-04-20 Thread John Colvin
On Saturday, 20 April 2013 at 13:37:55 UTC, John Colvin wrote: On Saturday, 20 April 2013 at 12:23:20 UTC, deed wrote: import std.stdio : writeln; template Template (uint n, T) { T[n] statArr() { T[n] arr; return arr; } T[] dynArr() { T[] dynArr = new T[n];

Re: Bug: Accessing return value of type static array with length 1 or 2 by index.

2013-04-20 Thread John Colvin
On Saturday, 20 April 2013 at 12:23:20 UTC, deed wrote: import std.stdio : writeln; template Template (uint n, T) { T[n] statArr() { T[n] arr; return arr; } T[] dynArr() { T[] dynArr = new T[n]; return dynArr; } } void main() { alias

Re: Bug: Accessing return value of type static array with length 1 or 2 by index.

2013-04-20 Thread John Colvin
On Saturday, 20 April 2013 at 13:37:55 UTC, John Colvin wrote: On Saturday, 20 April 2013 at 12:23:20 UTC, deed wrote: import std.stdio : writeln; template Template (uint n, T) { T[n] statArr() { T[n] arr; return arr; } T[] dynArr() { T[] dynArr = new T[n];

Re: Bug: Accessing return value of type static array with length 1 or 2 by index.

2013-04-20 Thread John Colvin
On Saturday, 20 April 2013 at 12:23:20 UTC, deed wrote: import std.stdio : writeln; template Template (uint n, T) { T[n] statArr() { T[n] arr; return arr; } T[] dynArr() { T[] dynArr = new T[n]; return dynArr; } } void main() { alias

Re: Bug: Accessing return value of type static array with length 1 or 2 by index.

2013-04-20 Thread deed
Made available on dpaste: http://dpaste.dzfl.pl/7b5c36f8 On dpaste, the struct with an int didn't compile. (Same error message) It turns out that Template!(2, Sint).statArr()[0].writeln(); compiles with $ dmd test.d -m64 but not with $ dmd test.d

Bug: Accessing return value of type static array with length 1 or 2 by index.

2013-04-20 Thread deed
import std.stdio : writeln; template Template (uint n, T) { T[n] statArr() { T[n] arr; return arr; } T[] dynArr() { T[] dynArr = new T[n]; return dynArr; } } void main() { alias statArr9 = Template!(9, int).statArr; alias statArr3

Re: Address of return value.

2012-12-11 Thread Artur Skawina
On 12/11/12 22:05, monarch_dodra wrote: > On Tuesday, 11 December 2012 at 21:00:11 UTC, Timon Gehr wrote: >> On 12/11/2012 05:58 PM, monarch_dodra wrote: >>> On Tuesday, 11 December 2012 at 16:45:54 UTC, cal wrote: On Tuesday, 11 December 2012 at 15:38:38 UTC, monarch_dodra wrote: > On Tue

Re: Address of return value.

2012-12-11 Thread monarch_dodra
On Tuesday, 11 December 2012 at 21:00:11 UTC, Timon Gehr wrote: On 12/11/2012 05:58 PM, monarch_dodra wrote: On Tuesday, 11 December 2012 at 16:45:54 UTC, cal wrote: On Tuesday, 11 December 2012 at 15:38:38 UTC, monarch_dodra wrote: On Tuesday, 11 December 2012 at 14:57:27 UTC, monarch_dodra w

Re: Address of return value.

2012-12-11 Thread Timon Gehr
On 12/11/2012 05:58 PM, monarch_dodra wrote: On Tuesday, 11 December 2012 at 16:45:54 UTC, cal wrote: On Tuesday, 11 December 2012 at 15:38:38 UTC, monarch_dodra wrote: On Tuesday, 11 December 2012 at 14:57:27 UTC, monarch_dodra wrote: :/ I got it to work with a cast, which removes the ambig

Re: Address of return value.

2012-12-11 Thread monarch_dodra
On Tuesday, 11 December 2012 at 16:45:54 UTC, cal wrote: On Tuesday, 11 December 2012 at 15:38:38 UTC, monarch_dodra wrote: On Tuesday, 11 December 2012 at 14:57:27 UTC, monarch_dodra wrote: :/ I got it to work with a cast, which removes the ambiguity: auto p = &cast(int)s.front; But it fee

Re: Address of return value.

2012-12-11 Thread cal
On Tuesday, 11 December 2012 at 15:38:38 UTC, monarch_dodra wrote: On Tuesday, 11 December 2012 at 14:57:27 UTC, monarch_dodra wrote: :/ I got it to work with a cast, which removes the ambiguity: auto p = &cast(int)s.front; But it feels hackish. Any other way? auto p = &(s.front()); Not s

Re: Address of return value.

2012-12-11 Thread monarch_dodra
On Tuesday, 11 December 2012 at 14:57:27 UTC, monarch_dodra wrote: :/ I got it to work with a cast, which removes the ambiguity: auto p = &cast(int)s.front; But it feels hackish. Any other way?

Address of return value.

2012-12-11 Thread monarch_dodra
I feel incredibly stupid asking this one, but how does one extract the address of return value of a member function that returns by ref? Case in point: // struct S { int i; ref front() @property { return i; } } void foo(int*){} void main() { auto s = S

Re: Optional extra return value? Multiple return values with auto?

2012-08-15 Thread ReneSac
On Wednesday, 15 August 2012 at 01:22:41 UTC, Era Scarecrow wrote: On Wednesday, 15 August 2012 at 00:37:32 UTC, ReneSac wrote: And my last question of my first post: I can't use "auto" for the "out" values right? An enhancement proposal like this would be compatible with D? I would say

Re: Optional extra return value? Multiple return values with auto?

2012-08-14 Thread Era Scarecrow
On Wednesday, 15 August 2012 at 01:42:11 UTC, Ali Çehreli wrote: Agreed. The function code must be compiled to use certain amount of data from the program stack for that particular parameter. That size of that parameter must be known at compile time. The compiler could in theory examine the e

Re: Optional extra return value? Multiple return values with auto?

2012-08-14 Thread Ali Çehreli
On 08/14/2012 06:22 PM, Era Scarecrow wrote: > On Wednesday, 15 August 2012 at 00:37:32 UTC, ReneSac wrote: >> And my last question of my first post: I can't use "auto" for the >> "out" values right? An enhancement proposal like this would be >> compatible with D? > > I would say No. Maybe if

Re: Optional extra return value? Multiple return values with auto?

2012-08-14 Thread Era Scarecrow
On Wednesday, 15 August 2012 at 00:37:32 UTC, ReneSac wrote: And my last question of my first post: I can't use "auto" for the "out" values right? An enhancement proposal like this would be compatible with D? I would say No. Maybe if it was a union, but I don't think so;.It still needs t

Re: Optional extra return value? Multiple return values with auto?

2012-08-14 Thread ReneSac
Thanks, this indeed works. One "obvious" (when your program starts to behave weirdly...) down side of this solution: it needs a different dummy for each optional out value of a function, or else multiple variables will be modifying the same dummy. And, of course, a different dummy for each typ

Re: Optional extra return value? Multiple return values with auto?

2012-08-11 Thread Timon Gehr
There is no compiler bug. You cannot pass immutable/rvalue by reference to mutable.

Re: Optional extra return value? Multiple return values with auto?

2012-08-11 Thread Ali Çehreli
On 08/11/2012 03:48 PM, ReneSac wrote: > On Tuesday, 24 July 2012 at 05:30:49 UTC, Ali Çehreli wrote: >> - Use an out parameter, which can have a default lvalue: >> >> int g_default_param; >> >> void foo(ref int i = g_default_param) >> { >> if (&i == &g_param) { >> // The caller is not interested

Re: Optional extra return value? Multiple return values with auto?

2012-08-11 Thread ReneSac
On Tuesday, 24 July 2012 at 05:30:49 UTC, Ali Çehreli wrote: The options that I can think of: - Return a struct (or a class) where one of the members is not filled-in - Similarly, return a tuple This is awkward, and doesn't look good for performance. - Use an out parameter, which can hav

Re: Optional extra return value? Multiple return values with auto?

2012-07-24 Thread bearophile
It seems forum.dlang.org hides my first answer, I don't know why: http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D.learn&article_id=37708 Bye, bearophile

Re: Optional extra return value? Multiple return values with auto?

2012-07-24 Thread Chris NS
On Tuesday, 24 July 2012 at 08:56:21 UTC, David wrote: Am 24.07.2012 05:25, schrieb ReneSac: I whish there was: auto foo() { return Tuple!("foo", "bar", 1, new Custum()); } void main() { auto (s1, s2, i, c) = foo(); } I think the main blocker to something like that right now is the

Re: Optional extra return value? Multiple return values with auto?

2012-07-24 Thread bearophile
On Tuesday, 24 July 2012 at 03:25:55 UTC, ReneSac wrote: How I can return multiple values in D, but one of them being optional? One of the ways to to it is to return a tuple with your arguments, where the last item of the tuple is a Nullable of the optional element: import std.stdio, std.t

Re: Optional extra return value? Multiple return values with auto?

2012-07-24 Thread David
Am 24.07.2012 05:25, schrieb ReneSac: I whish there was: auto foo() { return Tuple!("foo", "bar", 1, new Custum()); } void main() { auto (s1, s2, i, c) = foo(); }

Re: Optional extra return value? Multiple return values with auto?

2012-07-24 Thread Chris NS
On Tuesday, 24 July 2012 at 03:25:55 UTC, ReneSac wrote: Do I really have to duplicate the function, in order to achieve this? In a nutshell, yes. Or else resort to bizarre sorcery such as may rot the very heart from one's chest (or template ninjitsu, whatever). But is it really so bad?

Re: Optional extra return value? Multiple return values with auto?

2012-07-23 Thread Ali Çehreli
ctions in D can also have a single return value. The most common workaround in C and C++ has been an out parameter (pointer in C and pointer or reference in C++). The options that I can think of: - Return a struct (or a class) where one of the members is not filled-in - Similarly, return a tupl

Optional extra return value? Multiple return values with auto?

2012-07-23 Thread ReneSac
How I can return multiple values in D, but one of them being optional? I tried the 'out' hack to achieve multiple return values, but it didn't accepted a default argument: it needed a lvalue in the calling function. In Lua, for example, one can do: function foo(input) -- calculations --

  1   2   >