From 6f01c706a8274a2096a619c17945e27d7aed2ffc Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Thu, 26 Mar 2020 12:38:07 -0600 Subject: [PATCH] Actually detect negative sizes by following ES.106 (#1586) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Actually detect negative sizes by following ES.106 And don't use senseless one letter names * fix grammar Co-Authored-By: Johel Ernesto Guerrero Peña Co-authored-by: Johel Ernesto Guerrero Peña --- CppCoreGuidelines.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/CppCoreGuidelines.md b/CppCoreGuidelines.md index 5c86b56..2a0b99b 100644 --- a/CppCoreGuidelines.md +++ b/CppCoreGuidelines.md @@ -20320,20 +20320,20 @@ and errors (when we didn't deal correctly with semi-constructed objects consiste class Picture { - size_t mx; - size_t my; + ptrdiff_t mx; + ptrdiff_t my; vector data; - static size_t check_size(size_t s) + static ptrdiff_t check_size(ptrdiff_t size) { // invariant check - Expects(s > 0); - return s; + Expects(size > 0); + return size; } public: - // even more better would be a class for a 2D Size as one single parameter - Picture(size_t x, size_t y) + // even better would be a class for a 2D Size as one single parameter + Picture(ptrdiff_t x, ptrdiff_t y) : mx(check_size(x)) , my(check_size(y)) // now we know x and y have a valid size