From 10fae692519e4e33110d1c06693eb2eba48c3c23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E7=86=99=E6=9D=A5?= <617064818@qq.com> Date: Wed, 8 Jan 2025 20:09:28 +0800 Subject: [PATCH] update functional.h --- src/MyTinySTL-master/MyTinySTL/functional.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/MyTinySTL-master/MyTinySTL/functional.h b/src/MyTinySTL-master/MyTinySTL/functional.h index b445017..e1d319d 100644 --- a/src/MyTinySTL-master/MyTinySTL/functional.h +++ b/src/MyTinySTL-master/MyTinySTL/functional.h @@ -9,6 +9,7 @@ namespace mystl { // 定义一元函数的参数型别和返回值型别 +// 注意模板类的使用 template struct unarg_function { @@ -25,6 +26,7 @@ struct binary_function typedef Result result_type; }; +// 关于函数对象的四则运算 // 函数对象:加法 template struct plus :public binary_function @@ -66,7 +68,7 @@ struct negate :public unarg_function { T operator()(const T& x) const { return -x; } }; - +// 证同元素的意思是,对象与该元素做运算后,该对象仍等于自身,即零元 // 加法的证同元素 template T identity_element(plus) { return T(0); } @@ -75,6 +77,7 @@ T identity_element(plus) { return T(0); } template T identity_element(multiplies) { return T(1); } +// 关于函数对象的逻辑运算 // 函数对象:等于 template struct equal_to :public binary_function @@ -145,6 +148,7 @@ struct identity :public unarg_function const T& operator()(const T& x) const { return x; } }; +// select // 选择函数:接受一个 pair,返回第一个元素 template struct selectfirst :public unarg_function @@ -202,6 +206,8 @@ template <> struct hash \ { return static_cast(val); } \ }; +// 关于其他类型数据的HASH函数 + MYSTL_TRIVIAL_HASH_FCN(bool) MYSTL_TRIVIAL_HASH_FCN(char) @@ -235,6 +241,7 @@ MYSTL_TRIVIAL_HASH_FCN(unsigned long long) #undef MYSTL_TRIVIAL_HASH_FCN // 对于浮点数,逐位哈希 +// 逐位哈希函数 inline size_t bitwise_hash(const unsigned char* first, size_t count) { #if (_MSC_VER && _WIN64) || ((__GNUC__ || __clang__) &&__SIZEOF_POINTER__ == 8) @@ -253,6 +260,7 @@ inline size_t bitwise_hash(const unsigned char* first, size_t count) return result; } +// 单精度浮点 template <> struct hash { @@ -262,6 +270,7 @@ struct hash } }; +// 多精度浮点 template <> struct hash { @@ -271,6 +280,7 @@ struct hash } }; +// 高精度浮点 template <> struct hash {