Loading...
Searching...
No Matches
scope_exit.hpp
Go to the documentation of this file.
//
// Copyright 2019 Ettus Research, a National Instruments Brand
//
// SPDX-License-Identifier: GPL-3.0-or-later
//
#pragma once
#include <functional>
#include <memory>
#include <utility>
namespace uhd { namespace utils {
class scope_exit
{
public:
using uptr = std::unique_ptr<scope_exit>;
using exit_cb_t = std::function<void(void)>;
// \param exit_b The function object ("exit callback") that gets executed
// in the destructor
static uptr make(exit_cb_t&& exit_cb)
{
// Note: We can't use make_unique() here because it requires the
// constructor to be public.
return uptr(new scope_exit(std::forward<exit_cb_t>(exit_cb)));
}
~scope_exit()
{
_exit_cb();
}
private:
scope_exit(exit_cb_t&& exit_cb) : _exit_cb(std::forward<exit_cb_t>(exit_cb))
{
// nop
}
exit_cb_t _exit_cb;
};
}} // namespace uhd::utils
uhd::utils::scope_exit
Definition scope_exit.hpp:24
uhd::utils::scope_exit::exit_cb_t
std::function< void(void)> exit_cb_t
Definition scope_exit.hpp:27
uhd::utils::scope_exit::~scope_exit
~scope_exit()
Definition scope_exit.hpp:38
uhd::utils::scope_exit::make
static uptr make(exit_cb_t &&exit_cb)
Definition scope_exit.hpp:31
uhd::utils::scope_exit::uptr
std::unique_ptr< scope_exit > uptr
Definition scope_exit.hpp:26
std
STL namespace.
uhd::utils
Definition chdr_packet.hpp:20
uhd
Definition build_info.hpp:12