LLVM  16.0.0git
identity.h
Go to the documentation of this file.
1 //===- llvm/ADT/Identity.h - Provide std::identity from C++20 ---*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file provides an implementation of std::identity from C++20.
10 //
11 // No library is required when using these functions.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_ADT_IDENTITY_H
16 #define LLVM_ADT_IDENTITY_H
17 
18 
19 namespace llvm {
20 
21 // Similar to `std::identity` from C++20.
22 template <class Ty> struct identity {
23  using is_transparent = void;
24  using argument_type = Ty;
25 
26  Ty &operator()(Ty &self) const {
27  return self;
28  }
29  const Ty &operator()(const Ty &self) const {
30  return self;
31  }
32 };
33 
34 } // end namespace llvm
35 
36 #endif // LLVM_ADT_IDENTITY_H
llvm::identity::operator()
const Ty & operator()(const Ty &self) const
Definition: identity.h:29
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::identity::operator()
Ty & operator()(Ty &self) const
Definition: identity.h:26
llvm::identity< unsigned >::argument_type
unsigned argument_type
Definition: identity.h:24
llvm::identity< unsigned >::is_transparent
void is_transparent
Definition: identity.h:23
llvm::identity
Definition: identity.h:22