From: Kefu Chai Date: Tue, 24 Dec 2019 10:03:05 +0000 (+0800) Subject: include/cpp-btree: use static_assert() X-Git-Tag: v15.1.0~351^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=edb22d4e53d60b4072b1f0d40cdc713062e1a5ce;p=ceph.git include/cpp-btree: use static_assert() instead of using a homebrew replacement Signed-off-by: Kefu Chai --- diff --git a/src/include/cpp-btree/btree.h b/src/include/cpp-btree/btree.h index 321b30a6af3f..df103cf15178 100644 --- a/src/include/cpp-btree/btree.h +++ b/src/include/cpp-btree/btree.h @@ -149,14 +149,6 @@ struct big_ { char dummy[2]; }; -// A compile-time assertion. -template -struct CompileAssert { -}; - -#define COMPILE_ASSERT(expr, msg) \ - typedef CompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1] - // A helper type used to indicate that a key-compare-to functor has been // provided. A user can specify a key-compare-to functor by doing: // @@ -1406,20 +1398,20 @@ class btree : public Params::key_compare { // key_compare_checker() to instantiate and then figure out the size of the // return type of key_compare_checker() at compile time which we then check // against the sizeof of big_. - COMPILE_ASSERT( + static_assert( sizeof(key_compare_checker(key_compare_helper()(key_type(), key_type()))) == sizeof(big_), - key_comparison_function_must_return_bool); + "key comparison function must return bool"); // Note: We insist on kTargetValues, which is computed from // Params::kTargetNodeSize, must fit the base_fields::field_type. - COMPILE_ASSERT(kNodeValues < - (1 << (8 * sizeof(typename base_fields::field_type))), - target_node_size_too_large); + static_assert(kNodeValues < + (1 << (8 * sizeof(typename base_fields::field_type))), + "target node size too large"); // Test the assumption made in setting kNodeValueSpace. - COMPILE_ASSERT(sizeof(base_fields) >= 2 * sizeof(void*), - node_space_assumption_incorrect); + static_assert(sizeof(base_fields) >= 2 * sizeof(void*), + "node space assumption incorrect"); }; ////