From: Alex Rousskov Date: Mon, 7 Jan 2013 17:14:28 +0000 (-0700) Subject: Provide a safer version of a "is set" operator and X-Git-Tag: SQUID_3_5_0_1~444^2~90 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=99b1961024b13dafe028f58d5e17b24bcafe5384;p=thirdparty%2Fsquid.git Provide a safer version of a "is set" operator and its explicitly named equivalent. --- diff --git a/src/ipc/mem/Page.h b/src/ipc/mem/Page.h index e7ff8c5667..0d2d481bb8 100644 --- a/src/ipc/mem/Page.h +++ b/src/ipc/mem/Page.h @@ -20,7 +20,12 @@ class PageId public: PageId(): pool(0), number(0), purpose(maxPurpose) {} - operator bool() const { return pool && number; } + /// true if and only if both critical components have been initialized + bool set() const { return pool && number; } + + // safer than bool which would enable silent casts to int + typedef const uint32_t PageId::*SaferBool; + operator SaferBool() const { return set() ? &PageId::number : NULL; } uint32_t pool; ///< page pool ID within Squid // uint32_t segment; ///< memory segment ID within the pool; unused for now