[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master a00f295 09/16: Avoid std::ptrdiff_t where it'
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master a00f295 09/16: Avoid std::ptrdiff_t where it's excessively wide for 64-bit builds |
Date: |
Thu, 15 Nov 2018 17:37:04 -0500 (EST) |
branch: master
commit a00f295b44a06f382ac3f170c09cf12c7dc178cb
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Avoid std::ptrdiff_t where it's excessively wide for 64-bit builds
---
ce_product_name.cpp | 18 +++++++++---------
ce_skin_name.cpp | 18 +++++++++---------
mc_enum.tpp | 13 ++++++++-----
3 files changed, 26 insertions(+), 23 deletions(-)
diff --git a/ce_product_name.cpp b/ce_product_name.cpp
index 3966139..4b870ed 100644
--- a/ce_product_name.cpp
+++ b/ce_product_name.cpp
@@ -24,6 +24,7 @@
#include "ce_product_name.hpp"
#include "alert.hpp"
+#include "bourn_cast.hpp"
#include "contains.hpp"
#include "facets.hpp"
#include "global_settings.hpp"
@@ -35,7 +36,6 @@
#include <boost/filesystem/path.hpp>
#include <algorithm> // find()
-#include <cstddef> // ptrdiff_t
namespace
{
@@ -124,14 +124,14 @@ bool ce_product_name::operator==(std::string const& s)
const
int ce_product_name::ordinal(std::string const& s)
{
- std::ptrdiff_t v =
- std::find
- (product_names().begin()
- ,product_names().end()
- ,s
- )
- - product_names().begin()
- ;
+ auto v = bourn_cast<int>
+ ( std::find
+ (product_names().begin()
+ ,product_names().end()
+ ,s
+ )
+ - product_names().begin()
+ );
if(v == lmi::ssize(product_names()))
{
alarum()
diff --git a/ce_skin_name.cpp b/ce_skin_name.cpp
index 94be41e..a9787b0 100644
--- a/ce_skin_name.cpp
+++ b/ce_skin_name.cpp
@@ -24,6 +24,7 @@
#include "ce_skin_name.hpp"
#include "alert.hpp"
+#include "bourn_cast.hpp"
#include "contains.hpp"
#include "facets.hpp"
#include "global_settings.hpp"
@@ -36,7 +37,6 @@
#include <boost/filesystem/path.hpp>
#include <algorithm> // find()
-#include <cstddef> // ptrdiff_t
namespace
{
@@ -121,14 +121,14 @@ bool ce_skin_name::operator==(std::string const& s) const
int ce_skin_name::ordinal(std::string const& s)
{
- std::ptrdiff_t v =
- std::find
- (skin_names().begin()
- ,skin_names().end()
- ,s
- )
- - skin_names().begin()
- ;
+ auto v = bourn_cast<int>
+ ( std::find
+ (skin_names().begin()
+ ,skin_names().end()
+ ,s
+ )
+ - skin_names().begin()
+ );
if(v == lmi::ssize(skin_names()))
{
alarum()
diff --git a/mc_enum.tpp b/mc_enum.tpp
index f3ca523..b700014 100644
--- a/mc_enum.tpp
+++ b/mc_enum.tpp
@@ -23,11 +23,11 @@
#include "mc_enum_metadata.hpp"
#include "alert.hpp"
+#include "bourn_cast.hpp"
#include "facets.hpp"
#include "rtti_lmi.hpp"
#include <algorithm> // find()
-#include <cstddef> // ptrdiff_t
#include <typeinfo>
/// The header that defines class mc_enum is by design unaware of its
@@ -108,7 +108,7 @@ bool mc_enum<T>::operator!=(std::string const& s) const
template<typename T>
int mc_enum<T>::ordinal(std::string const& s)
{
- std::ptrdiff_t v = std::find(c(), c() + n(), s) - c();
+ auto v = bourn_cast<int>(std::find(c(), c() + n(), s) - c());
if(v == n())
{
alarum()
@@ -153,7 +153,7 @@ void mc_enum<T>::enforce_proscription()
template<typename T>
int mc_enum<T>::ordinal() const
{
- std::ptrdiff_t i = std::find(e(), e() + n(), value_) - e();
+ auto i = bourn_cast<int>(std::find(e(), e() + n(), value_) - e());
if(i == n())
{
alarum()
@@ -238,10 +238,13 @@ std::istream& mc_enum<T>::read(std::istream& is)
is >> s;
is.imbue(old_locale);
- std::ptrdiff_t v = std::find(c(), c() + n(), s) - c();
+ auto v = bourn_cast<int>(std::find(c(), c() + n(), s) - c());
if(n() == v)
{
- v = std::find(c(), c() + n(), provide_for_backward_compatibility(s)) -
c();
+ v = bourn_cast<int>
+ ( std::find(c(), c() + n(), provide_for_backward_compatibility(s))
+ - c()
+ );
}
if(n() == v)
{
- [lmi-commits] [lmi] master d425a61 10/16: Suppress some 86_64-linux-gnu gcc-8 '-Wconversion' diagnostics, (continued)
- [lmi-commits] [lmi] master d425a61 10/16: Suppress some 86_64-linux-gnu gcc-8 '-Wconversion' diagnostics, Greg Chicares, 2018/11/15
- [lmi-commits] [lmi] master 9c34f2a 12/16: Don't mix std::size_t with fixed-width integer types, Greg Chicares, 2018/11/15
- [lmi-commits] [lmi] master 89e939b 16/16: Prefer lmi::ssize() to member size(), Greg Chicares, 2018/11/15
- [lmi-commits] [lmi] master 0c4c5b6 01/16: Improve gcc dialect defaults, Greg Chicares, 2018/11/15
- [lmi-commits] [lmi] master 96dc6f5 07/16: Suppress certain diagnostics for another old boost library, Greg Chicares, 2018/11/15
- [lmi-commits] [lmi] master 5548922 14/16: Avoid gratuitous use of member size(), Greg Chicares, 2018/11/15
- [lmi-commits] [lmi] master fc8cf69 13/16: Prefer lmi::ssize() to member size(); rewrite a function out of line, Greg Chicares, 2018/11/15
- [lmi-commits] [lmi] master f0fd0dc 15/16: Use bourn_cast to convert arithmetic types safely, Greg Chicares, 2018/11/15
- [lmi-commits] [lmi] master c0a4dde 04/16: Reliably multiply suseconds_t by double, Greg Chicares, 2018/11/15
- [lmi-commits] [lmi] master 0d09e74 05/16: Make a macro definition conditional, Greg Chicares, 2018/11/15
- [lmi-commits] [lmi] master a00f295 09/16: Avoid std::ptrdiff_t where it's excessively wide for 64-bit builds,
Greg Chicares <=