From: Kefu Chai Date: Tue, 24 Dec 2019 10:37:28 +0000 (+0800) Subject: include/cpp-btree: use inline variable to define btree_is_key_compare_to X-Git-Tag: v15.1.0~351^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F32415%2Fhead;p=ceph.git include/cpp-btree: use inline variable to define btree_is_key_compare_to simpler this way Signed-off-by: Kefu Chai --- diff --git a/src/include/cpp-btree/btree.h b/src/include/cpp-btree/btree.h index 21761273c4bc..8f77431edaa5 100644 --- a/src/include/cpp-btree/btree.h +++ b/src/include/cpp-btree/btree.h @@ -155,10 +155,9 @@ struct btree_key_compare_to_tag { // A helper class that indicates if the Compare parameter is derived from // btree_key_compare_to_tag. -template -struct btree_is_key_compare_to - : public std::is_convertible { -}; +template +inline constexpr bool btree_is_key_compare_to_v = + std::is_convertible_v; // A helper class to convert a boolean comparison into a three-way // "compare-to" comparison that returns a negative value to indicate @@ -241,7 +240,7 @@ template static bool btree_compare_keys( const Compare &comp, const Key &x, const Key &y) { typedef btree_key_comparer::value> key_comparer; + btree_is_key_compare_to_v> key_comparer; return key_comparer::bool_compare(comp, x, y); } @@ -252,11 +251,11 @@ struct btree_common_params { // key_compare type. Otherwise, use btree_key_compare_to_adapter<> which will // fall-back to Compare if we don't have an appropriate specialization. using key_compare = std::conditional_t< - btree_is_key_compare_to::value, + btree_is_key_compare_to_v, Compare, btree_key_compare_to_adapter >; // A type which indicates if we have a key-compare-to functor or a plain old // key-compare functor. - typedef btree_is_key_compare_to is_key_compare_to; + static constexpr bool is_key_compare_to = btree_is_key_compare_to_v; typedef Alloc allocator_type; typedef Key key_type; @@ -429,13 +428,13 @@ class btree_node { // If we have a valid key-compare-to type, use linear_search_compare_to, // otherwise use linear_search_plain_compare. using linear_search_type = std::conditional_t< - Params::is_key_compare_to::value, + Params::is_key_compare_to, linear_search_compare_to_type, linear_search_plain_compare_type>; // If we have a valid key-compare-to type, use binary_search_compare_to, // otherwise use binary_search_plain_compare. using binary_search_type = std::conditional_t< - Params::is_key_compare_to::value, + Params::is_key_compare_to, binary_search_compare_to_type, binary_search_plain_compare_type>; // If the key is an integral or floating point type, use linear search which @@ -845,12 +844,12 @@ class btree : public Params::key_compare { typedef typename node_type::leaf_fields leaf_fields; typedef typename node_type::internal_fields internal_fields; typedef typename node_type::root_fields root_fields; - typedef typename Params::is_key_compare_to is_key_compare_to; + static constexpr bool is_key_compare_to = Params::is_key_compare_to; friend class btree_internal_locate_plain_compare; friend class btree_internal_locate_compare_to; using internal_locate_type = std::conditional_t< - is_key_compare_to::value, + is_key_compare_to, btree_internal_locate_compare_to, btree_internal_locate_plain_compare>; @@ -1372,7 +1371,7 @@ class btree : public Params::key_compare { // key-compare-to functor or if R is bool and small_ otherwise. template static std::conditional_t< - (is_key_compare_to::value ? + (is_key_compare_to ? std::is_same_v : std::is_same_v), big_, small_> key_compare_checker(R);