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
9
namespace
wpi
{
10
11
template
<
typename
F>
12
class
scope_exit
{
13
public
:
14
explicit
scope_exit
(F&& f) noexcept : m_f{std::forward<F>(f)} {}
15
16
~scope_exit
() {
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
wpi::scope_exit
Definition
scope:12
wpi::scope_exit::scope_exit
scope_exit(const scope_exit &)=delete
wpi::scope_exit::~scope_exit
~scope_exit()
Definition
scope:16
wpi::scope_exit::scope_exit
scope_exit(scope_exit &&rhs) noexcept
Definition
scope:22
wpi::scope_exit::operator=
scope_exit & operator=(const scope_exit &)=delete
wpi::scope_exit::release
void release() noexcept
Definition
scope:30
wpi::scope_exit::scope_exit
scope_exit(F &&f) noexcept
Definition
scope:14
wpi
Foonathan namespace.
Definition
ntcore_cpp.h:26
wpi
scope
Generated on Thu Jan 2 2025 00:19:44 for WPILibC++ by
1.12.0