[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 0819953 7/8: Dispense with boost/operators al
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 0819953 7/8: Dispense with boost/operators altogether |
Date: |
Sun, 25 Feb 2018 17:15:14 -0500 (EST) |
branch: master
commit 0819953453f6491ba18e1543b1fef664a9c66ee2
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Dispense with boost/operators altogether
Daniel Frey distributes an operators library that might have been used
instead. It's a single self-contained header, so it doesn't suffer from
the worst drawbacks of its boost ancestor. However, lmi's long-term
maintainability is impaired by any dependency on third-party code, and
new dependencies are to be added only with utmost reluctance, no matter
how convenient they may seem today.
---
mc_enum.hpp | 32 +++++++++++++++++++++++++++-----
mc_enum.tpp | 18 ++++++++++++++++++
2 files changed, 45 insertions(+), 5 deletions(-)
diff --git a/mc_enum.hpp b/mc_enum.hpp
index d06e40d..17bfe2f 100644
--- a/mc_enum.hpp
+++ b/mc_enum.hpp
@@ -26,8 +26,6 @@
#include "datum_base.hpp"
-#include <boost/operators.hpp>
-
#include <cstddef> // size_t
#include <deque>
#include <string>
@@ -94,9 +92,6 @@ class LMI_SO mc_enum_base
template<typename T>
class mc_enum
:public mc_enum_base
- ,private boost::equality_comparable<mc_enum<T>,mc_enum<T>>
- ,private boost::equality_comparable<mc_enum<T>,T>
- ,private boost::equality_comparable<mc_enum<T>,std::string>
{
static_assert(std::is_enum<T>::value);
@@ -116,6 +111,9 @@ class mc_enum
bool operator==(mc_enum<T> const&) const;
bool operator==(T ) const;
bool operator==(std::string const&) const;
+ bool operator!=(mc_enum<T> const&) const;
+ bool operator!=(T ) const;
+ bool operator!=(std::string const&) const;
static std::size_t ordinal(std::string const&);
@@ -143,6 +141,30 @@ class mc_enum
};
template<typename U>
+bool operator==(U u, mc_enum<U> const& z)
+{
+ return z.operator==(u);
+}
+
+template<typename U>
+bool operator==(std::string const& s, mc_enum<U> const& z)
+{
+ return z.operator==(s);
+}
+
+template<typename U>
+bool operator!=(U u, mc_enum<U> const& z)
+{
+ return !z.operator==(u);
+}
+
+template<typename U>
+bool operator!=(std::string const& s, mc_enum<U> const& z)
+{
+ return !z.operator==(s);
+}
+
+template<typename U>
std::vector<std::string> const& all_strings()
{
return mc_enum<U>::s();
diff --git a/mc_enum.tpp b/mc_enum.tpp
index f46c14f..ec90305 100644
--- a/mc_enum.tpp
+++ b/mc_enum.tpp
@@ -87,6 +87,24 @@ bool mc_enum<T>::operator==(std::string const& s) const
}
template<typename T>
+bool mc_enum<T>::operator!=(mc_enum<T> const& z) const
+{
+ return !operator==(z);
+}
+
+template<typename T>
+bool mc_enum<T>::operator!=(T t) const
+{
+ return !operator==(t);
+}
+
+template<typename T>
+bool mc_enum<T>::operator!=(std::string const& s) const
+{
+ return !operator==(s);
+}
+
+template<typename T>
std::size_t mc_enum<T>::ordinal(std::string const& s)
{
std::size_t v = std::find(c(), c() + n(), s) - c();
- [lmi-commits] [lmi] master updated (0c16a43 -> 5d71aea), Greg Chicares, 2018/02/25
- [lmi-commits] [lmi] master f15d7c0 2/8: Remove unwanted postincrement operator, Greg Chicares, 2018/02/25
- [lmi-commits] [lmi] master f481f1e 1/8: Expunge commentary that has become irrelevant, Greg Chicares, 2018/02/25
- [lmi-commits] [lmi] master db53742 3/8: Define only the relational operators that have proved useful for dates, Greg Chicares, 2018/02/25
- [lmi-commits] [lmi] master 1c65496 5/8: Dispense with boost/operators for one class, Greg Chicares, 2018/02/25
- [lmi-commits] [lmi] master 340ae3c 4/8: Test mixed-mode date arithmetic, Greg Chicares, 2018/02/25
- [lmi-commits] [lmi] master 2598df5 6/8: Dispense with boost/operators for one class, Greg Chicares, 2018/02/25
- [lmi-commits] [lmi] master 5d71aea 8/8: Remove obsolete references to boost, Greg Chicares, 2018/02/25
- [lmi-commits] [lmi] master 0819953 7/8: Dispense with boost/operators altogether,
Greg Chicares <=