mirror of
https://github.com/isocpp/CppCoreGuidelines.git
synced 2024-03-22 13:30:58 +08:00
Actually detect negative sizes by following ES.106 (#1586)
* 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 <johelegp@gmail.com> Co-authored-by: Johel Ernesto Guerrero Peña <johelegp@gmail.com>
This commit is contained in:
parent
d2be4cba57
commit
6f01c706a8
|
@ -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<char> 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
|
||||
|
|
Loading…
Reference in New Issue
Block a user