Correctly implementing a bidirectional range on a linked list?
Jonathan M Davis via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Jul 7 02:34:55 PDT 2015
On Monday, July 06, 2015 21:58:30 anonymous via Digitalmars-d-learn wrote:
> Off topic: I think `@trusted:` is horrible. It's easy to forget
> that you're in a @trusted environment when editing things later.
> And even worse, you're trusting everything that's passed through
> template parameters.
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
More information about the Digitalmars-d-learn
mailing list