From dea65112cb473e4885db0c4859ff91e2fd45f4db Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Wed, 24 Jul 2024 09:25:10 +0800 Subject: [PATCH] Synchronize `identity` with C++20 Making it not a template. --- MyTinySTL/functional.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/MyTinySTL/functional.h b/MyTinySTL/functional.h index b445017..165ac1a 100644 --- a/MyTinySTL/functional.h +++ b/MyTinySTL/functional.h @@ -139,10 +139,10 @@ struct logical_not :public unarg_function }; // 证同函数:不会改变元素,返回本身 -template -struct identity :public unarg_function +struct identity { - const T& operator()(const T& x) const { return x; } + template + constexpr T&& operator()(T&& x) const noexcept { return static_cast(x); } }; // 选择函数:接受一个 pair,返回第一个元素