src/macros.h

changeset 709
47a2f9d10ebe
parent 706
d79083b9f74d
child 754
c37564d59ce1
equal deleted inserted replaced
708:3155f2c05f89 709:47a2f9d10ebe
15 * You should have received a copy of the GNU General Public License 15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */ 17 */
18 18
19 #pragma once 19 #pragma once
20 #include <type_traits>
20 21
21 #ifndef __GNUC__ 22 #ifndef __GNUC__
22 # define __attribute__(X) 23 # define __attribute__(X)
23 #endif 24 #endif
24 25
25 #define countof(A) ((int) (sizeof A / sizeof *A)) 26 // =============================================================================
27 //
28 #define countof(A) (safeCountOf<std::is_array<decltype(A)>::value, (sizeof A / sizeof *A)>())
29
30 template<bool isArray, size_t elems>
31 inline constexpr int safeCountOf() __attribute__ ((always_inline));
32
33 template<bool isArray, size_t elems>
34 inline constexpr int safeCountOf()
35 {
36 static_assert (isArray, "parameter to countof must be an array");
37 return elems;
38 }
26 39
27 // ============================================================================= 40 // =============================================================================
28 // 41 //
29 #define PROPERTY(ACCESS, TYPE, READ, WRITE, WRITETYPE) \ 42 #define PROPERTY(ACCESS, TYPE, READ, WRITE, WRITETYPE) \
30 private: \ 43 private: \

mercurial