lmi-commits
[Top][All Lists]
Advanced

[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)
         {



reply via email to

[Prev in Thread] Current Thread [Next in Thread]