digitalmars.D.learn - opIndex vs. opSlice for empty slices
- Mike Parker (7/7) May 21 2015 I've always used opSlice to produce empty slices, but having
- weaselcat (2/9) May 21 2015 http://forum.dlang.org/thread/luadir$t0g$1@digitalmars.com#post-luadir:2...
- Mike Parker (2/3) May 21 2015 Thanks!
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (8/13) May 21 2015 For convenience, here are the two sections that cover my understanding
- Mike Parker (18/21) May 22 2015 Thanks, Ali. I've actually looked over that already and it's part
- Steven Schveighoffer (3/16) May 22 2015 This is news to me, and very cool!
I've always used opSlice to produce empty slices, but having recently read the documentation at [1], I see this: "To overload a[], simply define opIndex with no parameters:" And no mention that opSlice can fill the same role. Am I right to infer that we should prefer opIndex over opSlice for this? If so, what's the rationale? [1] http://dlang.org/operatoroverloading.html#slice
May 21 2015
On Friday, 22 May 2015 at 05:47:28 UTC, Mike Parker wrote:I've always used opSlice to produce empty slices, but having recently read the documentation at [1], I see this: "To overload a[], simply define opIndex with no parameters:" And no mention that opSlice can fill the same role. Am I right to infer that we should prefer opIndex over opSlice for this? If so, what's the rationale? [1] http://dlang.org/operatoroverloading.html#slicehttp://forum.dlang.org/thread/luadir$t0g$1 digitalmars.com#post-luadir:24t0g:241:40digitalmars.com
May 21 2015
On Friday, 22 May 2015 at 05:49:17 UTC, weaselcat wrote:http://forum.dlang.org/thread/luadir$t0g$1 digitalmars.com#post-luadir:24t0g:241:40digitalmars.comThanks!
May 21 2015
On 05/21/2015 11:20 PM, Mike Parker wrote:On Friday, 22 May 2015 at 05:49:17 UTC, weaselcat wrote:For convenience, here are the two sections that cover my understanding of this topic: http://ddili.org/ders/d.en/operator_overloading.html#ix_operator_overloading.opSlice http://ddili.org/ders/d.en/templates_more.html#ix_templates_more.overloading,%20operator Alihttp://forum.dlang.org/thread/luadir$t0g$1 digitalmars.com#post-luadir:24t0g:241:40digitalmars.comThanks!
May 21 2015
On Friday, 22 May 2015 at 06:28:16 UTC, Ali Çehreli wrote:http://ddili.org/ders/d.en/operator_overloading.html#ix_operator_overloading.opSlice http://ddili.org/ders/d.en/templates_more.html#ix_templates_more.overloading,%20operator AliThanks, Ali. I've actually looked over that already and it's part of the reason I postes the question in the first place. The docs indicate that opIndex can be used for the empty slice on a single-dimensional array, but your text says it's used for multi-dimensional slicing and opSlice is for the empty, single dimensional form. Then, in the thread linked above, H.S. Teoh's post seems to side with the docs. Additionally, there's the bit in the docs that I missed earlier about the non-templated opSlice being kept for backward compatibility, but the DoubleEndedQueue in your first link use the non-templated opSlice rather than the templated form that H.S. Teoh's post demonstrated. I've only recently started digging into the different sources of documentation on D to understand the why of things and, in the process, have managed to confuse myself about topics I thought I understood. I'm finding it hard to discern which source is correct and why.
May 22 2015
On 5/22/15 1:49 AM, weaselcat wrote:On Friday, 22 May 2015 at 05:47:28 UTC, Mike Parker wrote:This is news to me, and very cool! -SteveI've always used opSlice to produce empty slices, but having recently read the documentation at [1], I see this: "To overload a[], simply define opIndex with no parameters:" And no mention that opSlice can fill the same role. Am I right to infer that we should prefer opIndex over opSlice for this? If so, what's the rationale? [1] http://dlang.org/operatoroverloading.html#slicehttp://forum.dlang.org/thread/luadir$t0g$1 digitalmars.com#post-luadir:24t0g:241:40digitalmars.com
May 22 2015