lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master 97416cf 7/9: Emulate C++23 to_underlying<>()


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 97416cf 7/9: Emulate C++23 to_underlying<>()
Date: Sat, 23 Oct 2021 18:32:44 -0400 (EDT)

branch: master
commit 97416cf55eda997ce06593159a5ed2a763bab955
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>

    Emulate C++23 to_underlying<>()
---
 test_coding_rules.cpp | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/test_coding_rules.cpp b/test_coding_rules.cpp
index d50ea97..3562ba8 100644
--- a/test_coding_rules.cpp
+++ b/test_coding_rules.cpp
@@ -255,6 +255,14 @@ bool file::is_of_phylum(enum_phylum z) const
     return z & phylum();
 }
 
+/// Helper, to be deprecated for C++23.
+
+template<typename E>
+constexpr std::underlying_type_t<E> to_underlying(E e) noexcept
+{
+    return static_cast<std::underlying_type_t<E>>(e);
+}
+
 /// Ascertain whether a file appertains to the given category.
 ///
 /// This relation may be read as "has the X-nature". For example,
@@ -266,7 +274,7 @@ bool file::is_of_phylum(enum_kingdom z) const
     // though this is safe here because enum_kingdom only contains combinations
     // of primitive phyla from enum_phylum, so cast to the underlying type to
     // avoid warnings/errors about this generally unsafe operation.
-    return static_cast<std::underlying_type_t<enum_kingdom>>(z) & phylum();
+    return to_underlying(z) & phylum();
 }
 
 /// Analyze a file's name to determine its phylum.



reply via email to

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