35 #ifndef EASTL_FUNCTIONAL_H 36 #define EASTL_FUNCTIONAL_H 39 #include <stk_util/util/config_eastl.h> 40 #include <stk_util/util/type_traits_eastl.h> 50 template <
typename Argument,
typename Result>
53 typedef Argument argument_type;
54 typedef Result result_type;
58 template <
typename Argument1,
typename Argument2,
typename Result>
59 struct binary_function
61 typedef Argument1 first_argument_type;
62 typedef Argument2 second_argument_type;
63 typedef Result result_type;
68 struct plus :
public binary_function<T, T, T>
70 T operator()(
const T& a,
const T& b)
const 75 struct minus :
public binary_function<T, T, T>
77 T operator()(
const T& a,
const T& b)
const 82 struct multiplies :
public binary_function<T, T, T>
84 T operator()(
const T& a,
const T& b)
const 89 struct divides :
public binary_function<T, T, T>
91 T operator()(
const T& a,
const T& b)
const 96 struct modulus :
public binary_function<T, T, T>
98 T operator()(
const T& a,
const T& b)
const 102 template <
typename T>
103 struct negate :
public unary_function<T, T>
105 T operator()(
const T& a)
const 109 template <
typename T>
110 struct equal_to :
public binary_function<T, T, bool>
112 bool operator()(
const T& a,
const T& b)
const 116 template <
typename T,
typename Compare>
117 bool validate_equal_to(
const T& a,
const T& b, Compare compare)
119 return compare(a, b) == compare(b, a);
122 template <
typename T>
123 struct not_equal_to :
public binary_function<T, T, bool>
125 bool operator()(
const T& a,
const T& b)
const 129 template <
typename T,
typename Compare>
130 bool validate_not_equal_to(
const T& a,
const T& b, Compare compare)
132 return compare(a, b) == compare(b, a);
149 template <
typename T>
152 bool operator()(T a, T b)
const 154 while(*a && (*a == *b))
163 template <
typename T>
164 struct greater :
public binary_function<T, T, bool>
166 bool operator()(
const T& a,
const T& b)
const 170 template <
typename T,
typename Compare>
171 bool validate_greater(
const T& a,
const T& b, Compare compare)
173 return !compare(a, b) || !compare(b, a);
176 template <
typename T>
177 struct less :
public binary_function<T, T, bool>
179 bool operator()(
const T& a,
const T& b)
const 183 template <
typename T,
typename Compare>
184 bool validate_less(
const T& a,
const T& b, Compare compare)
186 return !compare(a, b) || !compare(b, a);
189 template <
typename T>
190 struct greater_equal :
public binary_function<T, T, bool>
192 bool operator()(
const T& a,
const T& b)
const 196 template <
typename T,
typename Compare>
197 bool validate_greater_equal(
const T& a,
const T& b, Compare compare)
199 return !compare(a, b) || !compare(b, a);
202 template <
typename T>
203 struct less_equal :
public binary_function<T, T, bool>
205 bool operator()(
const T& a,
const T& b)
const 209 template <
typename T,
typename Compare>
210 bool validate_less_equal(
const T& a,
const T& b, Compare compare)
212 return !compare(a, b) || !compare(b, a);
215 template <
typename T>
216 struct logical_and :
public binary_function<T, T, bool>
218 bool operator()(
const T& a,
const T& b)
const 222 template <
typename T>
223 struct logical_or :
public binary_function<T, T, bool>
225 bool operator()(
const T& a,
const T& b)
const 229 template <
typename T>
230 struct logical_not :
public unary_function<T, bool>
232 bool operator()(
const T& a)
const 242 template <
typename T,
typename U>
243 struct equal_to_2 :
public binary_function<T, U, bool>
245 bool operator()(
const T& a,
const U& b)
const 249 template <
typename T,
typename U>
250 struct not_equal_to_2 :
public binary_function<T, U, bool>
252 bool operator()(
const T& a,
const U& b)
const 256 template <
typename T,
typename U>
257 struct less_2 :
public binary_function<T, U, bool>
259 bool operator()(
const T& a,
const U& b)
const 268 template <
typename Predicate>
269 class unary_negate :
public unary_function<typename Predicate::argument_type, bool>
272 Predicate mPredicate;
276 bool operator()(
const typename Predicate::argument_type& a)
const 277 {
return !mPredicate(a); }
280 template <
typename Predicate>
288 template <
typename Predicate>
289 class binary_negate :
public binary_function<typename Predicate::first_argument_type, typename Predicate::second_argument_type, bool>
292 Predicate mPredicate;
296 bool operator()(
const typename Predicate::first_argument_type& a,
const typename Predicate::second_argument_type& b)
const 297 {
return !mPredicate(a, b); }
300 template <
typename Predicate>
313 template <
typename Operation>
314 class binder1st :
public unary_function<typename Operation::second_argument_type, typename Operation::result_type>
317 typename Operation::first_argument_type value;
321 binder1st(
const Operation& x,
const typename Operation::first_argument_type& y)
322 : value(y), op(x) { }
324 typename Operation::result_type operator()(
const typename Operation::second_argument_type& x)
const 325 {
return op(value, x); }
327 typename Operation::result_type operator()(
typename Operation::second_argument_type& x)
const 328 {
return op(value, x); }
332 template <
typename Operation,
typename T>
335 typedef typename Operation::first_argument_type value;
342 template <
typename Operation>
343 class binder2nd :
public unary_function<typename Operation::first_argument_type, typename Operation::result_type>
347 typename Operation::second_argument_type value;
350 binder2nd(
const Operation& x,
const typename Operation::second_argument_type& y)
351 : op(x), value(y) { }
353 typename Operation::result_type operator()(
const typename Operation::first_argument_type& x)
const 354 {
return op(x, value); }
356 typename Operation::result_type operator()(
typename Operation::first_argument_type& x)
const 357 {
return op(x, value); }
361 template <
typename Operation,
typename T>
364 typedef typename Operation::second_argument_type value;
386 template <
typename Arg,
typename Result>
390 Result (*mpFunction)(Arg);
397 : mpFunction(pFunction) { }
399 Result operator()(Arg x)
const 400 {
return mpFunction(x); }
412 template <
typename Arg,
typename Result>
430 template <
typename Arg1,
typename Arg2,
typename Result>
434 Result (*mpFunction)(Arg1, Arg2);
441 : mpFunction(pFunction) {}
443 Result operator()(Arg1 x, Arg2 y)
const 444 {
return mpFunction(x, y); }
454 template <
typename Arg1,
typename Arg2,
typename Result>
477 template <
typename Result,
typename T>
481 typedef Result (T::*MemberFunction)();
483 EA_FORCE_INLINE
explicit mem_fun_t(MemberFunction pMemberFunction)
484 : mpMemberFunction(pMemberFunction)
489 EA_FORCE_INLINE Result operator()(T* pT)
const 491 return (pT->*mpMemberFunction)();
495 MemberFunction mpMemberFunction;
503 template <
typename Result,
typename T,
typename Argument>
504 class mem_fun1_t :
public binary_function<T*, Argument, Result>
507 typedef Result (T::*MemberFunction)(Argument);
509 EA_FORCE_INLINE
explicit mem_fun1_t(MemberFunction pMemberFunction)
510 : mpMemberFunction(pMemberFunction)
515 EA_FORCE_INLINE Result operator()(T* pT, Argument arg)
const 517 return (pT->*mpMemberFunction)(arg);
521 MemberFunction mpMemberFunction;
532 template <
typename Result,
typename T>
536 typedef Result (T::*MemberFunction)()
const;
538 EA_FORCE_INLINE
explicit const_mem_fun_t(MemberFunction pMemberFunction)
539 : mpMemberFunction(pMemberFunction)
544 EA_FORCE_INLINE Result operator()(
const T* pT)
const 546 return (pT->*mpMemberFunction)();
550 MemberFunction mpMemberFunction;
561 template <
typename Result,
typename T,
typename Argument>
565 typedef Result (T::*MemberFunction)(Argument)
const;
568 : mpMemberFunction(pMemberFunction)
573 EA_FORCE_INLINE Result operator()(
const T* pT, Argument arg)
const 575 return (pT->*mpMemberFunction)(arg);
579 MemberFunction mpMemberFunction;
592 template <
typename Result,
typename T>
599 template <
typename Result,
typename T,
typename Argument>
600 EA_FORCE_INLINE mem_fun1_t<Result, T, Argument>
601 mem_fun(Result (T::*MemberFunction)(Argument))
606 template <
typename Result,
typename T>
607 EA_FORCE_INLINE const_mem_fun_t<Result, T>
608 mem_fun(Result (T::*MemberFunction)()
const)
613 template <
typename Result,
typename T,
typename Argument>
614 EA_FORCE_INLINE const_mem_fun1_t<Result, T, Argument>
615 mem_fun(Result (T::*MemberFunction)(Argument)
const)
632 template <
typename Result,
typename T>
636 typedef Result (T::*MemberFunction)();
638 EA_FORCE_INLINE
explicit mem_fun_ref_t(MemberFunction pMemberFunction)
639 : mpMemberFunction(pMemberFunction)
644 EA_FORCE_INLINE Result operator()(T& t)
const 646 return (t.*mpMemberFunction)();
650 MemberFunction mpMemberFunction;
656 template <
typename Result,
typename T,
typename Argument>
660 typedef Result (T::*MemberFunction)(Argument);
662 EA_FORCE_INLINE
explicit mem_fun1_ref_t(MemberFunction pMemberFunction)
663 : mpMemberFunction(pMemberFunction)
668 EA_FORCE_INLINE Result operator()(T& t, Argument arg)
const 670 return (t.*mpMemberFunction)(arg);
674 MemberFunction mpMemberFunction;
680 template <
typename Result,
typename T>
684 typedef Result (T::*MemberFunction)()
const;
687 : mpMemberFunction(pMemberFunction)
692 EA_FORCE_INLINE Result operator()(
const T& t)
const 694 return (t.*mpMemberFunction)();
698 MemberFunction mpMemberFunction;
704 template <
typename Result,
typename T,
typename Argument>
708 typedef Result (T::*MemberFunction)(Argument)
const;
711 : mpMemberFunction(pMemberFunction)
716 EA_FORCE_INLINE Result operator()(
const T& t, Argument arg)
const 718 return (t.*mpMemberFunction)(arg);
722 MemberFunction mpMemberFunction;
732 template <
typename Result,
typename T>
739 template <
typename Result,
typename T,
typename Argument>
740 EA_FORCE_INLINE mem_fun1_ref_t<Result, T, Argument>
746 template <
typename Result,
typename T>
747 EA_FORCE_INLINE const_mem_fun_ref_t<Result, T>
753 template <
typename Result,
typename T,
typename Argument>
754 EA_FORCE_INLINE const_mem_fun1_ref_t<Result, T, Argument>
755 mem_fun_ref(Result (T::*MemberFunction)(Argument)
const)
767 template <
typename T>
struct hash;
769 template <
typename T>
struct hash<T*>
770 {
size_t operator()(T* p)
const {
return size_t(uintptr_t(p)); } };
772 template <>
struct hash<bool>
773 {
size_t operator()(
bool val)
const {
return static_cast<size_t>(val); } };
775 template <>
struct hash<char>
776 {
size_t operator()(
char val)
const {
return static_cast<size_t>(val); } };
778 template <>
struct hash<signed char>
779 {
size_t operator()(
signed char val)
const {
return static_cast<size_t>(val); } };
781 template <>
struct hash<unsigned char>
782 {
size_t operator()(
unsigned char val)
const {
return static_cast<size_t>(val); } };
784 #ifndef EA_WCHAR_T_NON_NATIVE // If wchar_t is a native type instead of simply a define to an existing type... 785 template <>
struct hash<wchar_t>
786 {
size_t operator()(
wchar_t val)
const {
return static_cast<size_t>(val); } };
789 template <>
struct hash<signed short>
790 {
size_t operator()(
short val)
const {
return static_cast<size_t>(val); } };
792 template <>
struct hash<unsigned short>
793 {
size_t operator()(
unsigned short val)
const {
return static_cast<size_t>(val); } };
795 template <>
struct hash<signed int>
796 {
size_t operator()(
signed int val)
const {
return static_cast<size_t>(val); } };
798 template <>
struct hash<unsigned int>
799 {
size_t operator()(
unsigned int val)
const {
return static_cast<size_t>(val); } };
801 template <>
struct hash<signed long>
802 {
size_t operator()(
signed long val)
const {
return static_cast<size_t>(val); } };
804 template <>
struct hash<unsigned long>
805 {
size_t operator()(
unsigned long val)
const {
return static_cast<size_t>(val); } };
807 template <>
struct hash<signed long long>
808 {
size_t operator()(
signed long long val)
const {
return static_cast<size_t>(val); } };
810 template <>
struct hash<unsigned long long>
811 {
size_t operator()(
unsigned long long val)
const {
return static_cast<size_t>(val); } };
813 template <>
struct hash<float>
814 {
size_t operator()(
float val)
const {
return static_cast<size_t>(val); } };
816 template <>
struct hash<double>
817 {
size_t operator()(
double val)
const {
return static_cast<size_t>(val); } };
819 template <>
struct hash<long double>
820 {
size_t operator()(
long double val)
const {
return static_cast<size_t>(val); } };
835 template <>
struct hash<char8_t*>
837 size_t operator()(
const char8_t* p)
const 839 size_t c, result = 2166136261U;
840 while((c = (uint8_t)*p++) != 0)
841 result = (result * 16777619) ^ c;
842 return (
size_t)result;
846 template <>
struct hash<const char8_t*>
848 size_t operator()(
const char8_t* p)
const 850 size_t c, result = 2166136261U;
851 while((c = (uint8_t)*p++) != 0)
852 result = (result * 16777619) ^ c;
853 return (
size_t)result;
857 template <>
struct hash<char16_t*>
859 size_t operator()(
const char16_t* p)
const 861 size_t c, result = 2166136261U;
862 while((c = (uint16_t)*p++) != 0)
863 result = (result * 16777619) ^ c;
864 return (
size_t)result;
868 template <>
struct hash<const char16_t*>
870 size_t operator()(
const char16_t* p)
const 872 size_t c, result = 2166136261U;
873 while((c = (uint16_t)*p++) != 0)
874 result = (result * 16777619) ^ c;
875 return (
size_t)result;
879 template <>
struct hash<char32_t*>
881 size_t operator()(
const char32_t* p)
const 883 size_t c, result = 2166136261U;
884 while((c = (uint32_t)*p++) != 0)
885 result = (result * 16777619) ^ c;
886 return (
size_t)result;
890 template <>
struct hash<const char32_t*>
892 size_t operator()(
const char32_t* p)
const 894 size_t c, result = 2166136261U;
895 while((c = (uint32_t)*p++) != 0)
896 result = (result * 16777619) ^ c;
897 return (
size_t)result;
908 template <
typename String>
912 typedef typename String::value_type value_type;
913 typedef typename eastl::add_unsigned<value_type>::type unsigned_value_type;
917 const unsigned_value_type* p = (
const unsigned_value_type*)s.c_str();
918 size_t c, result = 2166136261U;
919 while((c = *p++) != 0)
920 result = (result * 16777619) ^ c;
921 return (
size_t)result;
929 #endif // Header include guard
pointer_to_unary_function< Arg, Result > ptr_fun(Result(*pFunction)(Arg))
EA_FORCE_INLINE mem_fun_ref_t< Result, T > mem_fun_ref(Result(T::*MemberFunction)())
EA_FORCE_INLINE mem_fun_t< Result, T > mem_fun(Result(T::*MemberFunction)())
EA Standard Template Library.