Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Make generated accessor for bitfields @safe pure nothrow. #583

Merged
merged 1 commit into from

2 participants

@alexrp
Collaborator

No description provided.

@jmdavis jmdavis merged commit bb46824 into D-Programming-Language:master
@jmdavis
Collaborator

Merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 13, 2012
This page is out of date. Refresh to see the latest.
Showing with 29 additions and 4 deletions.
  1. +29 −4 std/bitmanip.d
View
33 std/bitmanip.d
@@ -80,17 +80,17 @@ private template createAccessors(
static assert(len == 1);
enum result =
// getter
- "@property bool " ~ name ~ "() const { return "
+ "@property @safe bool " ~ name ~ "() pure nothrow const { return "
~"("~store~" & "~myToString(maskAllElse)~") != 0;}\n"
// setter
- ~"@property void " ~ name ~ "(bool v){"
+ ~"@property @safe void " ~ name ~ "(bool v) pure nothrow {"
~"if (v) "~store~" |= "~myToString(maskAllElse)~";"
~"else "~store~" &= ~"~myToString(maskAllElse)~";}\n";
}
else
{
// getter
- enum result = "@property "~T.stringof~" "~name~"() const { auto result = "
+ enum result = "@property @safe "~T.stringof~" "~name~"() pure nothrow const { auto result = "
"("~store~" & "
~ myToString(maskAllElse) ~ ") >>"
~ myToString(offset) ~ ";"
@@ -100,7 +100,7 @@ private template createAccessors(
: "")
~ " return cast("~T.stringof~") result;}\n"
// setter
- ~"@property void "~name~"("~T.stringof~" v){ "
+ ~"@property @safe void "~name~"("~T.stringof~" v) pure nothrow { "
~"assert(v >= "~name~"_min); "
~"assert(v <= "~name~"_max); "
~store~" = cast(typeof("~store~"))"
@@ -205,6 +205,31 @@ template bitfields(T...)
unittest
{
+ struct Test
+ {
+ mixin(bitfields!(bool, "a", 1,
+ uint, "b", 3,
+ short, "c", 4));
+ }
+
+ @safe void test() pure nothrow
+ {
+ Test t;
+
+ t.a = true;
+ t.b = 5;
+ t.c = 2;
+
+ assert(t.a);
+ assert(t.b == 5);
+ assert(t.c == 2);
+ }
+
+ test();
+}
+
+unittest
+{
static struct Integrals {
bool checkExpectations(bool eb, int ei, short es) { return b == eb && i == ei && s == es; }
Something went wrong with that request. Please try again.