From c147f57588dede5cf3c514796caf0644d4910b2f Mon Sep 17 00:00:00 2001 From: q66 Date: Sat, 18 Apr 2015 02:35:36 +0100 Subject: [PATCH] add functional.h (for now with operator functor defs) + skeleton for algorithm.h --- octa/algorithm.h | 14 ++++++++++++ octa/functional.h | 56 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 octa/algorithm.h create mode 100644 octa/functional.h diff --git a/octa/algorithm.h b/octa/algorithm.h new file mode 100644 index 0000000..55881aa --- /dev/null +++ b/octa/algorithm.h @@ -0,0 +1,14 @@ +/* Algorithms for OctaSTD. + * + * This file is part of OctaSTD. See COPYING.md for futher information. + */ + +#ifndef OCTA_ALGORITHM_H +#define OCTA_ALGORITHM_H + +#include "octa/functional.h" + +namespace octa { +} + +#endif \ No newline at end of file diff --git a/octa/functional.h b/octa/functional.h new file mode 100644 index 0000000..0f4fdc1 --- /dev/null +++ b/octa/functional.h @@ -0,0 +1,56 @@ +/* Function objects for OctaSTD. + * + * This file is part of OctaSTD. See COPYING.md for futher information. + */ + +#ifndef OCTA_FUNCTIONAL_H +#define OCTA_FUNCTIONAL_H + +namespace octa { +#define OCTA_DEFINE_BINARY_OP(name, op, rettype) \ + template struct name { \ + bool operator()(const T &x, const T &y) const { return x op y; } \ + struct type { \ + typedef T first; \ + typedef T second; \ + typedef rettype result; \ + }; \ + }; + + OCTA_DEFINE_BINARY_OP(Less, <, bool) + OCTA_DEFINE_BINARY_OP(LessEqual, <=, bool) + OCTA_DEFINE_BINARY_OP(Greater, >, bool) + OCTA_DEFINE_BINARY_OP(GreaterEqual, >=, bool) + OCTA_DEFINE_BINARY_OP(Equal, ==, bool) + OCTA_DEFINE_BINARY_OP(NotEqual, !=, bool) + OCTA_DEFINE_BINARY_OP(LogicalAnd, &&, bool) + OCTA_DEFINE_BINARY_OP(LogicalOr, ||, bool) + OCTA_DEFINE_BINARY_OP(Modulus, %, T) + OCTA_DEFINE_BINARY_OP(Multiplies, *, T) + OCTA_DEFINE_BINARY_OP(Divides, /, T) + OCTA_DEFINE_BINARY_OP(Plus, +, T) + OCTA_DEFINE_BINARY_OP(Minus, -, T) + OCTA_DEFINE_BINARY_OP(BitAnd, &, T) + OCTA_DEFINE_BINARY_OP(BitOr, |, T) + OCTA_DEFINE_BINARY_OP(BitXor, ^, T) + +#undef OCTA_DEFINE_BINARY_OP + + template struct LogicalNot { + bool operator()(const T &x) const { return !x; } + struct type { + typedef T argument; + typedef bool result; + }; + }; + + template struct Negate { + bool operator()(const T &x) const { return -x; } + struct type { + typedef T argument; + typedef T result; + }; + }; +} + +#endif \ No newline at end of file