Skip to content

Commit

Permalink
make DEFER() always inline
Browse files Browse the repository at this point in the history
  • Loading branch information
lihuiba committed Dec 21, 2023
1 parent 1539380 commit 5eb9397
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions common/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,25 +74,25 @@ ptr_array_t<T> ptr_array(T* pbegin, size_t n)
return {pbegin, pbegin + n};
}

#define __INLINE__ __attribute__((always_inline))
#define __FORCE_INLINE__ __INLINE__ inline

template<typename T>
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<T>&) = delete;
operator bool () { return true; } // if (DEFER(...)) { ... }

private:
T m_func;
};

template<typename T>
template<typename T> __INLINE__
Defer<T> make_defer(T func) { return Defer<T>(func); }

#define __INLINE__ __attribute__((always_inline))
#define __FORCE_INLINE__ __INLINE__ inline

#define _CONCAT_(a, b) a##b
#define _CONCAT(a, b) _CONCAT_(a, b)

Expand Down

0 comments on commit 5eb9397

Please sign in to comment.