[vte/vte-0-60] lib: Fix exception thrown from std::clamp



commit 0b475b132bd20ca80e0254f38b967fae8bc86d16
Author: Christian Persch <chpe src gnome org>
Date:   Thu Apr 9 21:10:19 2020 +0200

    lib: Fix exception thrown from std::clamp
    
    Add vte::clamp which doesn't throw when max<min.
    
    https://gitlab.gnome.org/GNOME/vte/-/issues/228#note_764989
    (cherry picked from commit a201edeee522d7153ae4a3b7b2ee5e67dfe2eb86)

 src/vte.cc         |  2 +-
 src/vteinternal.hh | 12 ++++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)
---
diff --git a/src/vte.cc b/src/vte.cc
index cba606e8..2f0d81d3 100644
--- a/src/vte.cc
+++ b/src/vte.cc
@@ -1530,7 +1530,7 @@ Terminal::confine_grid_row(vte::grid::row_t const& row) const
         auto first_row = first_displayed_row();
         auto last_row = last_displayed_row();
 
-        return std::clamp(row, first_row, last_row);
+        return vte::clamp(row, first_row, last_row);
 }
 
 /*
diff --git a/src/vteinternal.hh b/src/vteinternal.hh
index 93e90527..b37272ad 100644
--- a/src/vteinternal.hh
+++ b/src/vteinternal.hh
@@ -78,6 +78,18 @@ enum {
 };
 
 namespace vte {
+
+// This is like std::clamp, except that it doesn't throw when
+// max_v<min_v, but instead returns min_v in that case.
+template<typename T>
+constexpr inline T const&
+clamp(T const& v,
+      T const& min_v,
+      T const& max_v)
+{
+        return std::max(std::min(v, max_v), min_v);
+}
+
 namespace platform {
 
 /*


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]