Reuse of variables referencing const objects
Chris Nicholson-Sauls
ibisbasenji at gmail.com
Mon Mar 9 11:50:08 PDT 2009
Sergey Kovrov wrote:
> On 3/6/2009 11:29 PM, Steven Schveighoffer wrote:
>> std.typecons.Rebindable
>>
>> http://www.digitalmars.com/d/2.0/phobos/std_typecons.html#Rebindable
>
> Thanks Steve,
>
> this is what I've been looking for, the only thing missing is comparing
> against null (is null).
>
>
> -- serg.
While not strictly intuitive, you could do this:
auto var = Rebindable!(const Foo)(new Foo);
assert(var.opDot !is null);
As 'opDot' returns the wrapped object (with const intact). The downside
to that, however, is that it won't work in those cases where
Rebindable's template parameter was mutable, as then it simply aliases
it. This shouldn't be a problem in general use, though. Only in
generic code, which could try to check for Rebindable.
-- Christopher Nicholson-Sauls
More information about the Digitalmars-d-learn
mailing list