WPILibC++ 2025.1.1
Loading...
Searching...
No Matches
scope
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <utility>
8
9namespace wpi {
10
11template <typename F>
13 public:
14 explicit scope_exit(F&& f) noexcept : m_f{std::forward<F>(f)} {}
15
17 if (m_active) {
18 m_f();
19 }
20 }
21
22 scope_exit(scope_exit&& rhs) noexcept
23 : m_f{std::move(rhs.m_f)}, m_active{rhs.m_active} {
24 rhs.release();
25 }
26
27 scope_exit(const scope_exit&) = delete;
28 scope_exit& operator=(const scope_exit&) = delete;
29
30 void release() noexcept { m_active = false; }
31
32 private:
33 F m_f;
34 bool m_active = true;
35};
36
37} // namespace wpi
Definition scope:12
scope_exit(const scope_exit &)=delete
~scope_exit()
Definition scope:16
scope_exit(scope_exit &&rhs) noexcept
Definition scope:22
scope_exit & operator=(const scope_exit &)=delete
void release() noexcept
Definition scope:30
scope_exit(F &&f) noexcept
Definition scope:14
Foonathan namespace.
Definition ntcore_cpp.h:26