25 #ifndef TVM_SUPPORT_WITH_H_
26 #define TVM_SUPPORT_WITH_H_
58 template <
typename ContextType>
65 template <
typename... Args>
66 explicit With(Args&&... args) : ctx_(std::forward<Args>(args)...) {
67 ctx_.EnterWithScope();
70 ~With() noexcept(false) { ctx_.ExitWithScope(); }
81 ContextType*
get() {
return &ctx_; }
82 const ContextType*
get()
const {
return &ctx_; }
113 template <
typename ContextType>
126 template <
typename... Args>
128 entries_.push_back(std::make_unique<
With<ContextType>>(std::forward<Args>(args)...));
132 size_t size()
const {
return entries_.size(); }
145 bool unwinding = std::uncaught_exceptions() > 0;
146 std::exception_ptr first_exc;
147 while (!entries_.empty()) {
150 auto entry = std::move(entries_.back());
155 if (!unwinding && !first_exc) {
156 first_exc = std::current_exception();
160 if (first_exc) std::rethrow_exception(first_exc);
164 std::vector<std::unique_ptr<With<ContextType>>> entries_;
A group of RAII contexts managed together.
Definition: with.h:114
~WithGroup() noexcept(false)
Destructor — exits all contexts in reverse order.
Definition: with.h:144
WithGroup(const WithGroup &)=delete
void Emplace(Args &&... args)
Construct a context and enter its scope.
Definition: with.h:127
WithGroup & operator=(WithGroup &&)=default
WithGroup(WithGroup &&)=default
WithGroup & operator=(const WithGroup &)=delete
size_t size() const
Number of active contexts in this group.
Definition: with.h:132
RAII wrapper function to enter and exit a context object similar to python's with syntax.
Definition: with.h:59
With & operator=(With &&other)=delete
With(Args &&... args)
constructor. Enter the scope of the context.
Definition: with.h:66
const ContextType * operator*() const
Definition: with.h:87
With(With &&other)=delete
const ContextType * operator->() const
Definition: with.h:85
ContextType * get()
Definition: with.h:81
With & operator=(const With &other)=delete
ContextType operator()()
Definition: with.h:89
ContextType & operator*()
Definition: with.h:86
With(const With &other)=delete
~With() noexcept(false)
destructor, leaves the scope of the context.
Definition: with.h:70
const ContextType * get() const
Definition: with.h:82
ContextType * operator->()
Definition: with.h:84
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition: analyzer.h:37