cloudflare/ClickHouse

Public
CodeCommitsIssuesPull requestsActionsInsightsSecurity
36ca4a9fecb0af8b696563ada80d44d171738c24

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

base/ext/identity.h

24lines · modecode

1#pragma once
2
3#include <utility>
4
5namespace 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}