Google OR-Tools: ortools/util/lazy_mutable_copy.h Source File

Go to the documentation of this file.

1

2

3

4

5

6

7

8

9

10

11

12

13

14#ifndef ORTOOLS_UTIL_LAZY_MUTABLE_COPY_H_

15#define ORTOOLS_UTIL_LAZY_MUTABLE_COPY_H_

16

17#include <memory>

18

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43template <class T>

45 public:

46

47

50

51

52

54 : copy_(std::make_unique<T>(std::move(obj))), ptr_(copy_.get()) {}

55

56

57

62

63

65 if (copy_ == nullptr && ptr_ != nullptr) {

66 copy_ = std::make_unique<T>(*ptr_);

67 ptr_ = copy_.get();

68 }

69 return copy_.get();

70 }

71

72

73

74

75

76

77

78

79

81 if (copy_ == nullptr && ptr_ != nullptr) {

82 std::unique_ptr<T> result = std::make_unique<T>(*ptr_);

83 ptr_ = nullptr;

84 return result;

85 }

86 ptr_ = nullptr;

87 return std::move(copy_);

88 }

89

90

91

93

94

95

96 const T* get() const { return ptr_; }

97 const T& operator*() const { return *ptr_; }

99

100

101

102

103

104

106 ptr_ = nullptr;

107 copy_ = nullptr;

108 }

109

110 private:

111 std::unique_ptr<T> copy_;

112 const T* ptr_ = nullptr;

113};

114

115}

116

117#endif

LazyMutableCopy(const LazyMutableCopy &)=delete

class LazyMutableCopy< T > & operator=(const LazyMutableCopy< T > &)=delete

T * get_mutable()

Definition lazy_mutable_copy.h:64

void dispose() &&

Definition lazy_mutable_copy.h:105

bool has_ownership() const

Definition lazy_mutable_copy.h:92

const T * operator->() const

Definition lazy_mutable_copy.h:98

LazyMutableCopy(LazyMutableCopy &&)=default

class LazyMutableCopy< T > & operator=(LazyMutableCopy< T > &&)=default

std::unique_ptr< T > copy_or_move_as_unique_ptr() &&

Definition lazy_mutable_copy.h:80

LazyMutableCopy(const T &obj)

Definition lazy_mutable_copy.h:48

LazyMutableCopy(T &&obj)

Definition lazy_mutable_copy.h:53

const T & operator*() const

Definition lazy_mutable_copy.h:97

const T * get() const

Definition lazy_mutable_copy.h:96