CARLA
 
载入中...
搜索中...
未找到
ScopedStack.h
浏览该文件的文档.
1// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
2// de Barcelona (UAB).
3//
4// This work is licensed under the terms of the MIT license.
5// For a copy, see <https://opensource.org/licenses/MIT>.
6
7#pragma once
8
9#include <deque>
10#include <memory>
11
12/// A stack to keep track of nested scopes.
13template <typename T>
14class FScopedStack : private std::deque<T> {
15 using Super = std::deque<T>;
16public:
17
18 /// Push this scope into the stack. Automatically pops @a Value when the
19 /// returned object goes out of the scope.
20 template <typename V>
21 auto PushScope(V &&Value)
22 {
23 Super::emplace_back(std::forward<V>(Value));
24 T *Pointer = &Super::back();
25 auto Deleter = [this](const T *) { Super::pop_back(); };
26 return std::unique_ptr<T, decltype(Deleter)>(Pointer, Deleter);
27 }
28
29 using Super::empty;
30 using Super::size;
31 using Super::begin;
32 using Super::end;
33};
A stack to keep track of nested scopes.
Definition ScopedStack.h:14
auto PushScope(V &&Value)
Push this scope into the stack.
Definition ScopedStack.h:21
std::deque< T > Super
Definition ScopedStack.h:15