We need something like source_location in D
Steven Schveighoffer
schveiguy at gmail.com
Mon Aug 5 14:42:18 UTC 2019
On 7/30/19 9:39 PM, Andrej Mitrovic wrote:
> From C++20:
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1208r5.pdf
>
> Instead of having to constantly declare "file = __FILE__, line =
> __LINE__" everywhere, it would be so much more useful to just have a
> single built-in type which we can default initialize . For example:
>
> -----
> import std.algorithm;
>
> void checkAndThrow (lazy bool expression, Loc loc = __LOCATION__)
> {
> if (!expression)
> throw new Exception("Failed", loc.file, loc.line);
> }
>
> void main ()
> {
> auto arr = [1, 1, 1, 1];
> checkAndThrow(arr.sum == 4);
>
> // should throw with file+line of this statement
> checkAndThrow(arr.sum == 5);
> }
> -----
This was my suggestion a while back:
https://issues.dlang.org/show_bug.cgi?id=18919
The biggest problem I see with using string and size_t is that those are
common parameter types that can be confused with actual parameters.
Having a Location type solves that.
-Steve
More information about the Digitalmars-d
mailing list