July 16, 2010 [Issue 4471] New: rebindable() helper function | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=4471 Summary: rebindable() helper function Product: D Version: D2 Platform: All OS/Version: All Status: NEW Keywords: patch Severity: enhancement Priority: P2 Component: DMD AssignedTo: nobody@puremagic.com ReportedBy: bearophile_hugs@eml.cc --- Comment #0 from bearophile_hugs@eml.cc 2010-07-16 05:21:15 PDT --- A helper function for Rebindable!() can help remove some noise from the code, this is a first try: import std.typecons, std.traits; template isImmutable(T) { enum bool isImmutable = is(const(T) == T) || is(immutable(T) == T); } Rebindable!T rebindable(T)(T obj) if ((is(T == class) || is(T == interface) || isArray!T) && isImmutable!T) { return Rebindable!T(obj); } // usage example import std.stdio; class Foo {} void main() { auto a = rebindable(new immutable(Foo)); assert(a.sizeof == 4); a = new immutable(Foo); } I don't know if isImmutable!() works well in all cases, I have not tested it much. But a template like isImmutable can be useful in Phobos. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
August 15, 2010 [Issue 4471] rebindable() helper function | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=4471 bearophile_hugs@eml.cc changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |FIXED --- Comment #1 from bearophile_hugs@eml.cc 2010-08-15 10:05:41 PDT --- Fixed in: http://dsource.org/projects/phobos/changeset/1849 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation