diff --git a/common/utility.h b/common/utility.h index afeb6fb0..33601371 100644 --- a/common/utility.h +++ b/common/utility.h @@ -74,12 +74,15 @@ ptr_array_t ptr_array(T* pbegin, size_t n) return {pbegin, pbegin + n}; } +#define __INLINE__ __attribute__((always_inline)) +#define __FORCE_INLINE__ __INLINE__ inline + template class Defer { public: - Defer(T fn) : m_func(fn) {} - ~Defer() { m_func(); } + Defer(T fn) __INLINE__ : m_func(fn) {} + ~Defer() __INLINE__ { m_func(); } void operator=(const Defer&) = delete; operator bool () { return true; } // if (DEFER(...)) { ... } @@ -87,12 +90,9 @@ class Defer T m_func; }; -template +template __INLINE__ Defer make_defer(T func) { return Defer(func); } -#define __INLINE__ __attribute__((always_inline)) -#define __FORCE_INLINE__ __INLINE__ inline - #define _CONCAT_(a, b) a##b #define _CONCAT(a, b) _CONCAT_(a, b)