[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 32888b1 2/2: Add a static assertion that was
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 32888b1 2/2: Add a static assertion that was not possible before C++11 |
Date: |
Wed, 11 Jan 2017 12:13:58 +0000 (UTC) |
branch: master
commit 32888b14c8592e8a671f3f9f4d47b8119eaf0927
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Add a static assertion that was not possible before C++11
std::numeric_limits<T>::max() now returns constexpr T.
---
tn_range_test.cpp | 5 ++++-
tn_range_test_aux.hpp | 10 +++-------
2 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/tn_range_test.cpp b/tn_range_test.cpp
index 7dfd349..d070660 100644
--- a/tn_range_test.cpp
+++ b/tn_range_test.cpp
@@ -31,7 +31,10 @@
#include <sstream>
// This should fail to compile:
-// template class tn_range<double, std::string>;
+// template class tn_range<double, std::string>;
+
+// This should fail to compile:
+// tn_range<bool, percentage_trammel<bool> > boolean_percentage;
template<typename T>
class nonnegative
diff --git a/tn_range_test_aux.hpp b/tn_range_test_aux.hpp
index cf2aecc..3b28686 100644
--- a/tn_range_test_aux.hpp
+++ b/tn_range_test_aux.hpp
@@ -27,21 +27,17 @@
#include "tn_range_fwd.hpp"
#include <istream>
+#include <limits>
#include <ostream>
-// The derived trammel class must be defined here so that its size is
+// Each derived trammel class must be defined here so that its size is
// known to all translation units that might use it.
-// An assertion such as
-// static_assert(100 <= std::numeric_limits<T>::max(), "");
-// cannot work: the macro's argument must be an integral constant
-// expression, so it can't involve a function call and can't perform
-// any non-integer operation.
-
template<typename T>
class percentage_trammel
:public trammel_base<T>
{
+ static_assert(100 <= std::numeric_limits<T>::max(), "");
T nominal_minimum() const override {return 0;}
T default_value() const override {return 0;}
T nominal_maximum() const override {return 100;}