Correctly implementing a bidirectional range on a linked list?

Gary Willoughby via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jul 7 10:40:17 PDT 2015


On Tuesday, 7 July 2015 at 09:35:12 UTC, Jonathan M Davis wrote:
> This is why you almost never use @trusted on templated 
> functions. You should
> _never_ mark anything with @trusted unless you can guarantee 
> that it's
> actually @safe. @safe is inferred for templated functions, so 
> unless you're
> doing @system operations in a templated function, there is no 
> need for
> @trusted, and if you are doing @system operations, then they 
> need to be
> segregated in a way that you can mark that section of code as 
> @trusted
> and guarantee that it's @safe regardless of what the template 
> argument is.
> But you should _never_ mark code as @trusted if it involves 
> calling
> functions that you can't guarantee are @safe, which almost 
> always means that
> you should not mark code which calls functions on template 
> arguments as
> @trusted.
>
> That being said, @trusted is very much a necessity in certain 
> types of code, so it would be really bad if we didn't have it. 
> But if you're marking much code as @trusted, or if you're 
> marking templated code as @trusted, then you really need to be 
> examining what you're doing. Very little code should need to be 
> marked as @trusted, and every time that it is, you need to be 
> able to absolutely guarantee that it's actually @safe in spite 
> of the @system operations that you're doing in that code.
>
> - Jonathan M Davis

Thanks for the advice.


More information about the Digitalmars-d-learn mailing list