From 39759805ac98b0291852c0551ad3678614ed6ce8 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Mon, 9 Sep 2019 07:37:37 +1000 Subject: [PATCH] functor: add the identity functor --- functor.hpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/functor.hpp b/functor.hpp index 9b0e4f85..4900d604 100644 --- a/functor.hpp +++ b/functor.hpp @@ -13,6 +13,20 @@ namespace cruft::functor { + /// Returns the supplied argument unchanged + /// + /// CXX#20: Revisit when C++20 support is available. This is just a + /// trivial implementation of std::identity. + struct identity { + template + ValueT&& + operator() (ValueT &&val) + { + return std::forward (val); + } + }; + + /// A trivial functor that wraps std::begin without any static typing. struct begin { template