On Wednesday, February 27, 2013 21:10:15 Walter Bright wrote: > > Also, I'd point out that even for strings, doing something like this means > > wrapping them, because their empty isn't defined in a manner which works > > with isSentinelRange. > > For D strings, yes, for C strings, no need to wrap them.
But you have to deal with D strings, not C strings if you're dealing with ranges. char* isn't a range. So, unless you're talking about wrapping a char* in a range, char* isn't going to work. And simply appending 0 to the end of a D string isn't enough, because isSentinelnputRange would fail, because std.array.empty doesn't match it. So, you need a wrapper even if it's only to pass the template constraint. That being the case, regardless of whether you're dealing with char* or string, you need a wrapper. And what ranges other than strings can take advantage of anything like this? There's no way to append a value to range other than chain, which means that you're forced to either construct ranges specifically with the idea that they'll be used as sentinel ranges (in which case, they're a wrapper around whatever they're using to hold the data internally - probably an array - and if you're doing that, why not just use an array in the first place?), or you're forced to wrap an existing range (which would then require it to check for empty on each popFront so that it can make its front be 0 when it's empty). What are we gaining here that can't be gained by simply using a few static ifs to special case strings? And I don't see how this idea is gaining us much of anything outside of strings and maybe arrays - both of which have to be wrapped in order for their empty to act appropriately (even if they can avoid the extra empty checks internally by appending the sentinel value to their end). So, why not just special case strings or arrays in the few situations where something like this is needed, especially when it would be so easy to do? - Jonathan M Davis
