summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndre Marin <aamarin@us.ibm.com>2018-05-02 14:54:16 -0500
committerDaniel M. Crowell <dcrowell@us.ibm.com>2018-05-10 22:09:52 -0400
commit89bbfaf84a74f09c2865a87e7f13a020b12f01a0 (patch)
tree7e6832eeb4cbe7bd9eb6a05ce9770a58ee15394c
parente33bd00b1ee96d9b54f24c91ffa89c3cd256e224 (diff)
downloadtalos-hostboot-89bbfaf84a74f09c2865a87e7f13a020b12f01a0.tar.gz
talos-hostboot-89bbfaf84a74f09c2865a87e7f13a020b12f01a0.zip
Add additional comparison function objects into functional header
Change-Id: I6314ec8582e1d9cc284adf877e115433e95a168e Reviewed-on: http://ralgit01.raleigh.ibm.com/gerrit1/58217 Tested-by: Jenkins Server <pfd-jenkins+hostboot@us.ibm.com> Tested-by: Jenkins OP Build CI <op-jenkins+hostboot@us.ibm.com> Tested-by: Jenkins OP HW <op-hw-jenkins+hostboot@us.ibm.com> Tested-by: FSP CI Jenkins <fsp-CI-jenkins+hostboot@us.ibm.com> Reviewed-by: Daniel M. Crowell <dcrowell@us.ibm.com>
-rw-r--r--src/include/functional138
-rw-r--r--src/usr/testcore/lib/stl_functional.H62
2 files changed, 169 insertions, 31 deletions
diff --git a/src/include/functional b/src/include/functional
index ddefe2bf9..180f5f500 100644
--- a/src/include/functional
+++ b/src/include/functional
@@ -1,11 +1,11 @@
/* IBM_PROLOG_BEGIN_TAG */
/* This is an automatically generated prolog. */
/* */
-/* $Source: src/include/functional.C $ */
+/* $Source: src/include/functional $ */
/* */
/* OpenPOWER HostBoot Project */
/* */
-/* Contributors Listed Below - COPYRIGHT 2011,2014 */
+/* Contributors Listed Below - COPYRIGHT 2011,2018 */
/* [+] International Business Machines Corp. */
/* */
/* */
@@ -30,26 +30,27 @@
namespace std
{
template<typename A1, typename A2, typename R>
- struct binary_function
- {
- typedef A1 first_argument_type; ///< type of the first argument
- typedef A2 second_argument_type; ///< type of the second argument
- typedef R result_type; ///< type of the return type
- };
+ struct binary_function
+ {
+ typedef A1 first_argument_type; ///< type of the first argument
+ typedef A2 second_argument_type; ///< type of the second argument
+ typedef R result_type; ///< type of the return type
+ };
template<typename A, typename R>
- struct unary_function
- {
- typedef A argument_type;
- typedef R result_type;
- };
+ struct unary_function
+ {
+ typedef A argument_type;
+ typedef R result_type;
+ };
/**
* less template
*/
template<typename T>
- struct less : public binary_function<T, T, bool>
+ struct less : public binary_function<T, T, bool>
{
+
/**
* operator()
* @param[in] x first object
@@ -62,8 +63,29 @@ namespace std
}
};
+ /**
+ * less_equal template
+ */
+ template<typename T>
+ struct less_equal : public binary_function<T, T, bool>
+ {
+ /**
+ * operator()
+ * @param[in] x first object
+ * @param[in] y second object
+ * @return true if x <= y otherwise false
+ */
+ bool operator()(const T& x, const T& y) const
+ {
+ return x <= y;
+ }
+ };
+
+ /**
+ * greater template
+ */
template<typename T>
- struct greater : public binary_function<T, T, bool>
+ struct greater : public binary_function<T, T, bool>
{
/**
* operator()
@@ -72,7 +94,63 @@ namespace std
* @return true if x > y otherwise false
*/
bool operator()(const T& x, const T& y) const
- { return x > y; }
+ {
+ return x > y;
+ }
+ };
+
+ /**
+ * greater_equal template
+ */
+ template<typename T>
+ struct greater_equal : public binary_function<T, T, bool>
+ {
+ /**
+ * operator()
+ * @param[in] x first object
+ * @param[in] y second object
+ * @return true if x >= y otherwise false
+ */
+ bool operator()(const T& x, const T& y) const
+ {
+ return x >= y;
+ }
+ };
+
+ /**
+ * not_equal_to template
+ */
+ template<typename T>
+ struct not_equal_to : public binary_function<T, T, bool>
+ {
+ /**
+ * operator()
+ * @param[in] x first object
+ * @param[in] y second object
+ * @return true if x != y otherwise false
+ */
+ bool operator()(const T& x, const T& y) const
+ {
+ return x != y;
+ }
+ };
+
+ /**
+ * equal_to template
+ */
+ template<typename T>
+ struct equal_to : public binary_function<T, T, bool>
+ {
+ /**
+ * operator()
+ * @param[in] x first object
+ * @param[in] y second object
+ * @return true if x == y otherwise false
+ */
+ bool operator()(const T& x, const T& y) const
+ {
+ return x == y;
+ }
};
// --------------- ptr_fun templates --------------- //
@@ -130,7 +208,7 @@ namespace std
protected:
Result (X::*func)() const;
};
-
+
template<typename Result, typename X>
mem_fun_t<Result, X> mem_fun(Result (X::*f)())
{
@@ -198,7 +276,7 @@ namespace std
protected:
Result (X::*func)() const;
};
-
+
template<typename Result, typename X>
mem_fun_ref_t<Result, X> mem_fun_ref(Result (X::*f)())
{
@@ -248,9 +326,9 @@ namespace std
// --------------- bind1st templates --------------- //
template<typename AdaptableBinaryFunction>
- struct binder1st :
+ struct binder1st :
public unary_function<
- typename AdaptableBinaryFunction::second_argument_type,
+ typename AdaptableBinaryFunction::second_argument_type,
typename AdaptableBinaryFunction::result_type
>
{
@@ -258,10 +336,10 @@ namespace std
typename AdaptableBinaryFunction::first_argument_type c) :
func(F), arg(c) {}
- typename AdaptableBinaryFunction::result_type
- operator()(const typename
+ typename AdaptableBinaryFunction::result_type
+ operator()(const typename
AdaptableBinaryFunction::second_argument_type& x) const
- {
+ {
return func(arg, x);
}
@@ -275,16 +353,16 @@ namespace std
bind1st(const AdaptableBinaryFunction& F,
const T& c)
{
- return binder1st<AdaptableBinaryFunction>(F,
+ return binder1st<AdaptableBinaryFunction>(F,
typename AdaptableBinaryFunction::first_argument_type(c));
};
// --------------- bind2nd templates --------------- //
template<typename AdaptableBinaryFunction>
- struct binder2nd :
+ struct binder2nd :
public unary_function<
- typename AdaptableBinaryFunction::first_argument_type,
+ typename AdaptableBinaryFunction::first_argument_type,
typename AdaptableBinaryFunction::result_type
>
{
@@ -292,10 +370,10 @@ namespace std
typename AdaptableBinaryFunction::second_argument_type c) :
func(F), arg(c) {}
- typename AdaptableBinaryFunction::result_type
- operator()(const typename
+ typename AdaptableBinaryFunction::result_type
+ operator()(const typename
AdaptableBinaryFunction::first_argument_type& x) const
- {
+ {
return func(x, arg);
}
@@ -309,7 +387,7 @@ namespace std
bind2nd(const AdaptableBinaryFunction& F,
const T& c)
{
- return binder2nd<AdaptableBinaryFunction>(F,
+ return binder2nd<AdaptableBinaryFunction>(F,
typename AdaptableBinaryFunction::second_argument_type(c));
};
diff --git a/src/usr/testcore/lib/stl_functional.H b/src/usr/testcore/lib/stl_functional.H
index 4b3fe6ea0..0129d0a8c 100644
--- a/src/usr/testcore/lib/stl_functional.H
+++ b/src/usr/testcore/lib/stl_functional.H
@@ -5,7 +5,7 @@
/* */
/* OpenPOWER HostBoot Project */
/* */
-/* Contributors Listed Below - COPYRIGHT 2014,2016 */
+/* Contributors Listed Below - COPYRIGHT 2014,2018 */
/* [+] International Business Machines Corp. */
/* */
/* */
@@ -22,6 +22,9 @@
/* permissions and limitations under the License. */
/* */
/* IBM_PROLOG_END_TAG */
+
+
+
#ifndef __LIB_STL_FUNCTIONAL_H
#define __LIB_STL_FUNCTIONAL_H
@@ -169,6 +172,63 @@ class STLFunctionalTest : public CxxTest::TestSuite
}
+ void test_lessFun()
+ {
+ TS_ASSERT( std::less<uint32_t>()(1,2) );
+ TS_ASSERT( std::less<uint16_t>()(5,20) );
+ TS_ASSERT( !std::less<uint8_t>()(100,2) );
+ TS_ASSERT( !std::less<int>()(-40,-40) );
+ TS_ASSERT( !std::less<int32_t>()(-40,-30) );
+ }
+
+ void test_lessEqualFun()
+ {
+ TS_ASSERT( std::less_equal<int>()(-40,-40) );
+ TS_ASSERT( std::less_equal<uint8_t>()(4,4) );
+ TS_ASSERT( std::less_equal<uint8_t>()(4,200) );
+ TS_ASSERT( std::less_equal<uint32_t>()(5,20) );
+ TS_ASSERT( !std::less_equal<uint16_t>()(300,50) );
+ }
+
+ void test_greaterFun()
+ {
+ TS_ASSERT( !std::greater<int>()(-40,-40) );
+ TS_ASSERT( !std::greater<uint8_t>()(4,4) );
+ TS_ASSERT( !std::greater<uint8_t>()(4,200) );
+ TS_ASSERT( !std::greater<uint32_t>()(5,20) );
+ TS_ASSERT( std::greater<int64_t>()(-5,-20) );
+ TS_ASSERT( std::greater<uint16_t>()(300,50) );
+ }
+
+ void test_greaterEqualFun()
+ {
+ TS_ASSERT( std::greater_equal<int>()(-40,-40) );
+ TS_ASSERT( std::greater_equal<uint8_t>()(4,4) );
+ TS_ASSERT( !std::greater_equal<uint8_t>()(4,200) );
+ TS_ASSERT( !std::greater_equal<uint32_t>()(5,20) );
+ TS_ASSERT( std::greater_equal<int64_t>()(-5,-20) );
+ TS_ASSERT( std::greater_equal<uint16_t>()(300,50) );
+ }
+
+ void test_equalTolFun()
+ {
+ TS_ASSERT( std::equal_to<int>()(-40,-40) );
+ TS_ASSERT( std::equal_to<uint8_t>()(4,4) );
+ TS_ASSERT( !std::equal_to<uint8_t>()(4,200) );
+ TS_ASSERT( !std::equal_to<uint32_t>()(5,20) );
+ TS_ASSERT( !std::equal_to<int64_t>()(-5,-20) );
+ TS_ASSERT( !std::equal_to<uint16_t>()(300,50) );
+ }
+
+ void test_NotEqualTolFun()
+ {
+ TS_ASSERT( std::not_equal_to<int>()(-40,-40) );
+ TS_ASSERT( std::not_equal_to<uint8_t>()(4,4) );
+ TS_ASSERT( !std::not_equal_to<uint8_t>()(4,200) );
+ TS_ASSERT( !std::not_equal_to<uint32_t>()(5,20) );
+ TS_ASSERT( !std::not_equal_to<int64_t>()(-5,-20) );
+ TS_ASSERT( !std::not_equal_to<uint16_t>()(300,50) );
+ }
};
#endif
OpenPOWER on IntegriCloud