cloudflare/ClickHouse
Publicbase/ext/identity.h
24lines · modecode
unknown
| 1 | #pragma once |
| 2 | |
| 3 | #include <utility> |
| 4 | |
| 5 | namespace ext |
| 6 | { |
| 7 | /// \brief Identity function for use with other algorithms as a pass-through. |
| 8 | class identity |
| 9 | { |
| 10 | /** \brief Function pointer type template for converting identity to a function pointer. |
| 11 | * Presumably useless, provided for completeness. */ |
| 12 | template <typename T> using function_ptr_t = T &&(*)(T &&); |
| 13 | |
| 14 | /** \brief Implementation of identity as a non-instance member function for taking function pointer. */ |
| 15 | template <typename T> static T && invoke(T && t) { return std::forward<T>(t); } |
| 16 | |
| 17 | public: |
| 18 | /** \brief Returns the value passed as a sole argument using perfect forwarding. */ |
| 19 | template <typename T> T && operator()(T && t) const { return std::forward<T>(t); } |
| 20 | |
| 21 | /** \brief Allows conversion of identity instance to a function pointer. */ |
| 22 | template <typename T> operator function_ptr_t<T>() const { return &invoke; }; |
| 23 | }; |
| 24 | } |