Added binary comparators needed for the set implementation.
Cosmetic in type_traits.h: renamed _Tp to _T for consistency.
diff --git a/include/functional b/include/functional
new file mode 100644
index 0000000..2f4ea3d
--- /dev/null
+++ b/include/functional
@@ -0,0 +1,72 @@
+/* -*- c++ -*- */
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef ANDROID_ASTL_FUNCTIONAL__
+#define ANDROID_ASTL_FUNCTIONAL__
+
+#if defined(_T) || defined(_Arg) || defined(_Arg1) || defined(_Arg2) || \
+ defined(_Result) || defined(_Name) || defined(_Op)
+#error "Macro(s) already defined."
+#endif
+
+namespace std {
+
+template <class _Arg, class _Result>
+struct unary_function {
+ typedef _Arg argument_type;
+ typedef _Result result_type;
+};
+
+template <class _Arg1, class _Arg2, class _Result>
+struct binary_function {
+ typedef _Arg1 first_argument_type;
+ typedef _Arg2 second_argument_type;
+ typedef _Result result_type;
+};
+
+// Comparaison
+
+#define FUNCTIONAL_BINARY_COMPARAISON(_Name, _Op) \
+ template <typename _T> \
+ struct _Name : public binary_function<_T, _T, bool> \
+ { \
+ bool operator()(const _T& left, const _T& right) const \
+ { return left _Op right; } \
+ };
+
+FUNCTIONAL_BINARY_COMPARAISON(equal_to, ==)
+FUNCTIONAL_BINARY_COMPARAISON(not_equal_to, !=)
+FUNCTIONAL_BINARY_COMPARAISON(greater, >)
+FUNCTIONAL_BINARY_COMPARAISON(less, <)
+FUNCTIONAL_BINARY_COMPARAISON(greater_equal, >=)
+FUNCTIONAL_BINARY_COMPARAISON(less_equal, <=)
+
+} // namespace std
+
+#endif // ANDROID_ASTL_FUNCTIONAL__
diff --git a/include/type_traits.h b/include/type_traits.h
index 14a3664..bc7cc0b 100644
--- a/include/type_traits.h
+++ b/include/type_traits.h
@@ -153,8 +153,8 @@
// Only classes will match the first declaration (pointer to member).
// TODO: newer version of gcc have these is_class built in.
-template<typename _Tp> sfinae_types::one test_pod_type(int _Tp::*);
-template<typename _Tp> sfinae_types::two& test_pod_type(...);
+template<typename _T> sfinae_types::one test_pod_type(int _T::*);
+template<typename _T> sfinae_types::two& test_pod_type(...);
template<typename _T>
struct is_pod: public integral_constant<bool, sizeof(test_pod_type<_T>(0)) != sizeof(sfinae_types::one)> { };
diff --git a/tests/Android.mk b/tests/Android.mk
index 432dece..825d1eb 100644
--- a/tests/Android.mk
+++ b/tests/Android.mk
@@ -62,9 +62,10 @@
sources := \
test_algorithm.cpp \
+ test_functional.cpp \
test_string.cpp \
test_type_traits.cpp \
- test_uninitialized.cpp \
+ test_uninitialized.cpp \
test_vector.cpp
# Disable all optimization for the host target to help test tools (valgrind...)
diff --git a/tests/test_functional.cpp b/tests/test_functional.cpp
new file mode 100644
index 0000000..ba72f80
--- /dev/null
+++ b/tests/test_functional.cpp
@@ -0,0 +1,61 @@
+/* -*- c++ -*- */
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include "../include/functional"
+#ifndef ANDROID_ASTL_FUNCTIONAL__
+#error "Wrong header included!!"
+#endif
+
+#include "common.h"
+
+
+namespace android {
+
+
+bool testInteger() {
+ EXPECT_TRUE(std::equal_to<int>()(10, 10));
+ EXPECT_TRUE(std::not_equal_to<int>()(10, 11));
+
+ EXPECT_TRUE(std::greater<int>()(10, 5));
+ EXPECT_TRUE(std::less<int>()(5, 10));
+
+ EXPECT_TRUE(std::greater_equal<int>()(10, 5));
+ EXPECT_TRUE(std::less_equal<int>()(5, 10));
+
+ EXPECT_TRUE(std::greater_equal<int>()(10, 10));
+ EXPECT_TRUE(std::less_equal<int>()(10, 10));
+ return true;
+}
+
+} // namespace android
+
+int main(int argc, char **argv)
+{
+ FAIL_UNLESS(testInteger);
+}