3 #ifndef __CDS_DETAILS_IS_ALIGNED_H
4 #define __CDS_DETAILS_IS_ALIGNED_H
6 #include <cds/details/defs.h>
8 namespace cds { namespace details {
10 /// Checks if the pointer \p p has \p ALIGN byte alignment
12 \p ALIGN must be power of 2.
14 The function is mostly intended for run-time assertion
16 template <int ALIGN, typename T>
17 static inline bool is_aligned(T const * p)
19 return (((uintptr_t)p) & uintptr_t(ALIGN - 1)) == 0;
22 /// Checks if the pointer \p p has \p nAlign byte alignment
24 \p nAlign must be power of 2.
26 The function is mostly intended for run-time assertion
29 static inline bool is_aligned(T const * p, size_t nAlign)
31 return (((uintptr_t)p) & uintptr_t(nAlign - 1)) == 0;
34 }} // namespace cds::details
36 #endif // #ifndef __CDS_DETAILS_IS_ALIGNED_H