This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Remove algo duplication


On Mon, 16 Sep 2013, Paolo Carlini wrote:

On 09/16/2013 04:54 PM, Marc Glisse wrote:
By the way, I thought someone had contributed less<void> and the others already, but I can't see them. Did I imagine that patch?
Humm, I guess so :-) Jon has definitely some work in the making but I don't think he mentioned it. Thus, I suppose we are looking for volunteers ;)

How much do you hate macros? What would you think of something like this (with better macro names)? Does this C++03 emulation even make sense?
(not sure how to handle doxygen with this)

#if __cplusplus >= 201103L
#define _DECL(OP) \
  template <class T, class U> auto operator()(T&& t, U&& u) const \
    -> decltype(std::forward<T>(t) OP std::forward<U>(u)) \
    { return std::forward<T>(t) OP std::forward<U>(u); }
#else
#define _HELP(OP, D) \
  D(OP,,) D(OP,,const) D(OP,,volatile) D(OP,,const volatile) \
  D(OP,const,) D(OP,const,const) \
  D(OP,const,volatile) D(OP,const,const volatile) \
  D(OP,volatile,) D(OP,volatile,const) \
  D(OP,volatile,volatile) D(OP,volatile,const volatile) \
  D(OP,const volatile,) D(OP,const volatile,const) \
  D(OP,const volatile,volatile) D(OP,const volatile,const volatile)
#define _FUN(OP, CV1, CV2) \
  template<class T, class U> bool operator()(T CV1& t, U CV2& u) const \
  { return static_cast<bool>(t OP u); }
#define _DECL(OP) _HELP(OP, _FUN)
#endif

#define _TOT(NAME, OP) \
template<typename _Tp = void> \
struct NAME : public binary_function<_Tp, _Tp, bool> \
{ \
  bool operator()(const _Tp& __x, const _Tp& __y) const { return __x OP __y; } \
}; \
template <> struct NAME<void> { \
  _DECL(OP) \
  typedef void is_transparent; \
};

_TOT(equal_to,==)
_TOT(not_equal_to,!=)
_TOT(greater,>)
_TOT(less,<)
_TOT(greater_equal,>=)
_TOT(less_equal,<=)

#undef _TOT
#undef _FUN
#undef _HELP
#undef _DECL


--
Marc Glisse


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]