mirror of
https://github.com/wiiu-env/WUMSLoader.git
synced 2024-11-24 00:39:15 +01:00
Format OnLeavingScope
This commit is contained in:
parent
846725f881
commit
99791f5edf
@ -46,8 +46,8 @@
|
|||||||
#ifndef CRASCIT_ONLEAVINGSCOPE_H
|
#ifndef CRASCIT_ONLEAVINGSCOPE_H
|
||||||
#define CRASCIT_ONLEAVINGSCOPE_H
|
#define CRASCIT_ONLEAVINGSCOPE_H
|
||||||
|
|
||||||
#include <utility>
|
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -61,33 +61,25 @@
|
|||||||
* function instead.
|
* function instead.
|
||||||
*/
|
*/
|
||||||
template<typename Func>
|
template<typename Func>
|
||||||
class OnLeavingScope
|
class OnLeavingScope {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
// Prevent copying
|
// Prevent copying
|
||||||
OnLeavingScope(const OnLeavingScope&) = delete;
|
OnLeavingScope(const OnLeavingScope &) = delete;
|
||||||
OnLeavingScope& operator=(const OnLeavingScope&) = delete;
|
OnLeavingScope &operator=(const OnLeavingScope &) = delete;
|
||||||
|
|
||||||
// Allow moving
|
// Allow moving
|
||||||
OnLeavingScope(OnLeavingScope&& other) :
|
OnLeavingScope(OnLeavingScope &&other) : m_func(std::move(other.m_func)),
|
||||||
m_func(std::move(other.m_func)),
|
m_owner(other.m_owner) {
|
||||||
m_owner(other.m_owner)
|
|
||||||
{
|
|
||||||
other.m_owner = false;
|
other.m_owner = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
OnLeavingScope(const Func& f) :
|
OnLeavingScope(const Func &f) : m_func(f),
|
||||||
m_func(f),
|
m_owner(true) {
|
||||||
m_owner(true)
|
|
||||||
{
|
|
||||||
}
|
}
|
||||||
OnLeavingScope(Func&& f) :
|
OnLeavingScope(Func &&f) : m_func(std::move(f)),
|
||||||
m_func(std::move(f)),
|
m_owner(true) {
|
||||||
m_owner(true)
|
|
||||||
{
|
|
||||||
}
|
}
|
||||||
~OnLeavingScope()
|
~OnLeavingScope() {
|
||||||
{
|
|
||||||
if (m_owner)
|
if (m_owner)
|
||||||
m_func();
|
m_func();
|
||||||
}
|
}
|
||||||
@ -114,8 +106,7 @@ private:
|
|||||||
* from the object passed as the function argument.
|
* from the object passed as the function argument.
|
||||||
*/
|
*/
|
||||||
template<typename Func>
|
template<typename Func>
|
||||||
OnLeavingScope<typename std::decay<Func>::type> onLeavingScope(Func&& f)
|
OnLeavingScope<typename std::decay<Func>::type> onLeavingScope(Func &&f) {
|
||||||
{
|
|
||||||
return OnLeavingScope<typename std::decay<Func>::type>(std::forward<Func>(f));
|
return OnLeavingScope<typename std::decay<Func>::type>(std::forward<Func>(f));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user