diff options
Diffstat (limited to 'src/lib/netlist/plib/ptypes.h')
-rw-r--r-- | src/lib/netlist/plib/ptypes.h | 43 |
1 files changed, 12 insertions, 31 deletions
diff --git a/src/lib/netlist/plib/ptypes.h b/src/lib/netlist/plib/ptypes.h index a3b11b65e74..84f6453e8f2 100644 --- a/src/lib/netlist/plib/ptypes.h +++ b/src/lib/netlist/plib/ptypes.h @@ -81,38 +81,19 @@ namespace plib template<typename... Ts> inline void unused_var(Ts&&...) {} - - - //============================================================ - // penum - strongly typed enumeration - //============================================================ - - struct penum_base - { - protected: - static int from_string_int(const char *str, const char *x); - static std::string nthstr(int n, const char *str); - }; - } // namespace plib -#define P_ENUM(ename, ...) \ - struct ename : public plib::penum_base { \ - enum E { __VA_ARGS__ }; \ - ename (E v) : m_v(v) { } \ - bool set_from_string (const std::string &s) { \ - static char const *const strings = # __VA_ARGS__; \ - int f = from_string_int(strings, s.c_str()); \ - if (f>=0) { m_v = static_cast<E>(f); return true; } else { return false; } \ - } \ - operator E() const {return m_v;} \ - bool operator==(const ename &rhs) const {return m_v == rhs.m_v;} \ - bool operator==(const E &rhs) const {return m_v == rhs;} \ - std::string name() const { \ - static char const *const strings = # __VA_ARGS__; \ - return nthstr(static_cast<int>(m_v), strings); \ - } \ - private: E m_v; }; - +//============================================================ +// Define a "has member" trait. +//============================================================ + +#define PDEFINE_HAS_MEMBER(name, member) \ + template <typename T> class name \ + { \ + template <typename U> static long test(decltype(&U:: member)); \ + template <typename U> static char test(...); \ + public: \ + static constexpr const bool value = sizeof(test<T>(nullptr)) == sizeof(long); \ + } #endif /* PTYPES_H_ */ |