On Thursday, 2 May 2024 at 07:46:48 UTC, Jonathan M Davis wrote:
>That being said, one concern that I can think of is that it arguably makes
cast() inconsistent. Right now, casting with an attribute only works with
type qualifiers, so it makes sense that cast() would remove all type
qualifiers. However, if stuff like cast(pure) or cast(nothrow) is legal,
then I could see someone expecting that cast() would remove those as well,
which seems like it would be a bad idea in practice (as well as being a
breaking change). But if we don't make cast() remove pure, nothrow, etc.,
then it could be argued that that's inconsistent. I'm not sure that that
inconsistency is worth worrying about, but I could see it coming up at some
point.
Another good argument to add @gc
and @impure
. Then, one can cast(@gc)
to remove a @nogc
attribute.
Another option would be to extend cast
to allow for negated stuff: cast(!const)
would remove const
, but not other type qualifiers, e.g. inout
or shared
. In particular, cast(!shared)
would be useful to remove shared
whilst not touching const
accidentally. Same would work for function attributes: const(!pure)
removes pure
, but doesn’t touch type qualifiers or other attributes.