[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master a80dbb6 5/5: Prefer 'auto' for non-type templ
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master a80dbb6 5/5: Prefer 'auto' for non-type template parameters |
Date: |
Mon, 11 Jun 2018 19:54:38 -0400 (EDT) |
branch: master
commit a80dbb6f350b390d39daf64126ba86756d665e5a
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Prefer 'auto' for non-type template parameters
---
authenticity_test.cpp | 3 +--
mc_enum_metadata.hpp | 4 +---
miscellany.cpp | 1 +
miscellany.hpp | 4 ++--
ssize_lmi.hpp | 4 ++--
5 files changed, 7 insertions(+), 9 deletions(-)
diff --git a/authenticity_test.cpp b/authenticity_test.cpp
index 5220ab2..2a4e174 100644
--- a/authenticity_test.cpp
+++ b/authenticity_test.cpp
@@ -34,7 +34,6 @@
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/path.hpp>
-#include <cstddef> // size_t
#include <cstdio>
#include <cstring> // memcpy()
#include <fstream>
@@ -43,7 +42,7 @@
// TODO ?? Add tests for conditions and diagnostics that aren't tested yet.
-template<typename T, std::size_t n>
+template<typename T, auto n>
std::string md5_str(T(&md5sum)[n])
{
LMI_ASSERT(n == md5len);
diff --git a/mc_enum_metadata.hpp b/mc_enum_metadata.hpp
index 2a76cd8..eeb19b4 100644
--- a/mc_enum_metadata.hpp
+++ b/mc_enum_metadata.hpp
@@ -36,8 +36,6 @@
#include "config.hpp"
-#include <cstddef> // size_t
-
/// Associate an mc_enum type with its metadata through its enum type.
///
/// This class template is intended to be specialized for each type,
@@ -104,7 +102,7 @@ struct mc_enum_key
/// 'n' could have been provided as a function rather than a constant,
/// but a constant is preferable because it can be used in an ICE.
-template<typename T, std::size_t n, T const (&E)[n], char const*const (&C)[n]>
+template<typename T, auto n, T const (&E)[n], char const*const (&C)[n]>
struct mc_enum_data
{
static_assert(0 != n);
diff --git a/miscellany.cpp b/miscellany.cpp
index 8cb4518..59f1b07 100644
--- a/miscellany.cpp
+++ b/miscellany.cpp
@@ -30,6 +30,7 @@
#include <algorithm> // equal(), max()
#include <cmath> // ceil(), floor()
+#include <cstddef> // size_t
#include <cstdio> // snprintf()
#include <ctime>
#include <fstream>
diff --git a/miscellany.hpp b/miscellany.hpp
index 4715f7c..7ef97fe 100644
--- a/miscellany.hpp
+++ b/miscellany.hpp
@@ -29,7 +29,6 @@
#include <algorithm>
#include <cctype>
#include <climits> // UCHAR_MAX
-#include <cstddef> // size_t
#include <cstdio> // EOF
#include <iomanip>
#include <ios>
@@ -181,7 +180,8 @@ std::string iso_8601_datestamp_terse();
std::string iso_8601_datestamp_verbose();
-template<typename T, std::size_t n>
+// to be expunged soon: duplicates lmi::size()
+template<typename T, auto n>
inline std::size_t lmi_array_size(T(&)[n])
{
return n;
diff --git a/ssize_lmi.hpp b/ssize_lmi.hpp
index 9761b30..a400e8b 100644
--- a/ssize_lmi.hpp
+++ b/ssize_lmi.hpp
@@ -93,10 +93,10 @@ constexpr ssize_t ssize(Container const& c)
return bourn_cast<ssize_t>(c.size());
}
-template<typename T, std::size_t n>
+template<typename T, auto n>
constexpr ssize_t ssize(T const(&)[n])
{
- return bourn_cast<ssize_t>(n);
+ return {n};
}
inline ssize_t sstrlen(char const* s)