LLVM: include/llvm/ADT/STLFunctionalExtras.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15#ifndef LLVM_ADT_STLFUNCTIONALEXTRAS_H

16#define LLVM_ADT_STLFUNCTIONALEXTRAS_H

17

20

21#include

22#include <type_traits>

23#include

24

25namespace llvm {

26

27

28

29

30

31

32

33

34

35

36

38

39template <typename Ret, typename... Params>

41 Ret (*callback)(intptr_t callable, Params ...params) = nullptr;

42 intptr_t callable;

43

44 template

45 static Ret callback_fn(intptr_t callable, Params ...params) {

46 return (*reinterpret_cast<Callable*>(callable))(

47 std::forward(params)...);

48 }

49

50public:

53

54 template

57

60

61 std::enable_if_t<std::is_void::value ||

62 std::is_convertible<decltype(std::declval()(

63 std::declval()...)),

64 Ret>::value> * = nullptr)

65 : callback(callback_fn<std::remove_reference_t>),

66 callable(reinterpret_cast<intptr_t>(&callable)) {}

67

69 return callback(callable, std::forward(params)...);

70 }

71

72 explicit operator bool() const { return callback; }

73

75 return callable == Other.callable;

76 }

77};

78

79}

80

81#endif

#define LLVM_LIFETIME_BOUND

#define LLVM_GSL_POINTER

LLVM_GSL_POINTER - Apply this to non-owning classes like StringRef to enable lifetime warnings.

This file contains library features backported from future STL versions.

bool operator==(const function_ref< Ret(Params...)> &Other) const

Definition STLFunctionalExtras.h:74

function_ref(Callable &&callable LLVM_LIFETIME_BOUND, std::enable_if_t<!std::is_same< remove_cvref_t< Callable >, function_ref >::value > *=nullptr, std::enable_if_t< std::is_void< Ret >::value||std::is_convertible< decltype(std::declval< Callable >()(std::declval< Params >()...)), Ret >::value > *=nullptr)

Definition STLFunctionalExtras.h:55

function_ref(std::nullptr_t)

Definition STLFunctionalExtras.h:52

Ret operator()(Params ...params) const

Definition STLFunctionalExtras.h:68

An efficient, type-erasing, non-owning reference to a callable.

Definition STLFunctionalExtras.h:37

This is an optimization pass for GlobalISel generic memory operations.

Implement std::hash so that hash_code can be used in STL containers.