[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 379fcf3 4/4: Change lmi::ssize_t to accommoda
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 379fcf3 4/4: Change lmi::ssize_t to accommodate LP64 |
Date: |
Sun, 11 Nov 2018 10:18:08 -0500 (EST) |
branch: master
commit 379fcf316228d9806340079457e295a6e8ccc91b
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Change lmi::ssize_t to accommodate LP64
See:
https://lists.nongnu.org/archive/html/lmi/2018-11/msg00019.html
---
ssize_lmi.hpp | 8 +++++++-
ssize_lmi_test.cpp | 5 +++--
2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/ssize_lmi.hpp b/ssize_lmi.hpp
index a400e8b..a05462a 100644
--- a/ssize_lmi.hpp
+++ b/ssize_lmi.hpp
@@ -36,6 +36,12 @@
/// numeric_limits<std::make_signed_t<std::size_t>>::max()
/// . Throws, or fails to compile, if violated.
///
+/// Type lmi::ssize_t is simply 'int'. An earlier version had used
+/// using ssize_t = std::make_signed_t<std::size_t>;
+/// but that is 'long int' for LP64:
+/// https://lists.nongnu.org/archive/html/lmi/2018-11/msg00006.html
+/// whereas 'int' is preferred as explained below.
+///
/// Motivation: to avoid error-prone mixing of signed and unsigned.
///
/// https://github.com/ericniebler/stl2/issues/182
@@ -85,7 +91,7 @@
namespace lmi
{
-using ssize_t = std::make_signed_t<std::size_t>;
+using ssize_t = int;
template<typename Container>
constexpr ssize_t ssize(Container const& c)
diff --git a/ssize_lmi_test.cpp b/ssize_lmi_test.cpp
index d367db5..a92a31f 100644
--- a/ssize_lmi_test.cpp
+++ b/ssize_lmi_test.cpp
@@ -62,7 +62,7 @@
///
/// and the compiler should emit a diagnostic if an array with more
/// than SCHAR_MAX elements is passed. Because the standard does not
-/// specify this precisely, it seems best to use type std::size_t for
+/// specify this precisely, it seems best to use a deduced type for
/// array-bound template parameters and convert their values to the
/// desired return type using a facility such as bourn_cast or a
/// braced-init-list that ensures value preservation.
@@ -92,7 +92,8 @@
/// might specify std::size_t for the non-type parameter, especially
/// in light of the [temp.deduct.type] quote above, but it seems even
/// better to use auto, again as in f0g(), and to specify the return
-/// type of lmi::ssize() as the signed analogue of std::size_t.
+/// type of lmi::ssize() as lmi::ssize_t (which is the signed analogue
+/// of std::size_t for 32-bit architectures, but not for LP64, e.g.).
namespace experimental
{