From 65fb75d8ab9cc73e998df8ee56d0ab5cbeead0fd Mon Sep 17 00:00:00 2001 From: q66 Date: Sun, 2 Aug 2015 14:56:10 +0100 Subject: [PATCH] add function object EqualWithCstr to consider char pointers strings --- ostd/functional.hh | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/ostd/functional.hh b/ostd/functional.hh index b674d0e..dd22c58 100644 --- a/ostd/functional.hh +++ b/ostd/functional.hh @@ -47,6 +47,37 @@ OSTD_DEFINE_BINARY_OP(BitXor, ^, T) #undef OSTD_DEFINE_BINARY_OP +namespace detail { + template, char>::value> + struct CharEqual { + using FirstArgument = T *; + using SecondArgument = T *; + using Result = bool; + bool operator()(T *x, T *y) const { + return !strcmp(x, y); + } + }; + + template struct CharEqual { + using FirstArgument = T *; + using SecondArgument = T *; + using Result = bool; + bool operator()(T *x, T *y) const { + return x == y; + } + }; +} + +template struct EqualWithCstr { + using FirstArgument = T; + using SecondArgument = T; + bool operator()(const T &x, const T &y) const { + return x == y; + } +}; + +template struct EqualWithCstr: detail::CharEqual {}; + template struct LogicalNot { bool operator()(const T &x) const { return !x; } using Argument = T;