diff --git a/src/common/backport14.h b/src/common/backport14.h index 5d5c9ffcbed..1d059d8e794 100644 --- a/src/common/backport14.h +++ b/src/common/backport14.h @@ -21,18 +21,119 @@ // Library code from C++14 that can be implemented in C++11. namespace ceph { -template -using remove_extent_t = typename std::remove_extent::type; -template -using remove_reference_t = typename std::remove_reference::type; -template -using result_of_t = typename std::result_of::type; +// Template variable aliases from C++17 +// primary type categories +template constexpr bool is_void_v = std::is_void::value; +template constexpr bool is_null_pointer_v = + std::is_null_pointer::value; +template constexpr bool is_integral_v = std::is_integral::value; +template constexpr bool is_floating_point_v = + std::is_floating_point::value; +template constexpr bool is_array_v = std::is_array::value; +template constexpr bool is_pointer_v = std::is_pointer::value; +template constexpr bool is_lvalue_reference_v = + std::is_lvalue_reference::value; +template constexpr bool is_rvalue_reference_v = + std::is_rvalue_reference::value; +template constexpr bool is_member_object_pointer_v = + std::is_member_object_pointer::value; +template constexpr bool is_member_function_pointer_v = + std::is_member_function_pointer::value; +template constexpr bool is_enum_v = std::is_enum::value; +template constexpr bool is_union_v = std::is_union::value; +template constexpr bool is_class_v = std::is_class::value; +template constexpr bool is_function_v = std::is_function::value; -template -using decay_t = typename std::decay::type; +// composite type categories +template constexpr bool is_reference_v = std::is_reference::value; +template constexpr bool is_arithmetic_v = std::is_arithmetic::value; +template constexpr bool is_fundamental_v = + std::is_fundamental::value; +template constexpr bool is_object_v = std::is_object::value; +template constexpr bool is_scalar_v = std::is_scalar::value; +template constexpr bool is_compound_v = std::is_compound::value; +template constexpr bool is_member_pointer_v = + std::is_member_pointer::value; -template -using enable_if_t = typename std::enable_if::type; +// type properties +template constexpr bool is_const_v = std::is_const::value; +template constexpr bool is_volatile_v = std::is_volatile::value; +template constexpr bool is_trivial_v = std::is_trivial::value; +template constexpr bool is_trivially_copyable_v = + std::is_trivially_copyable::value; +template constexpr bool is_standard_layout_v = + std::is_standard_layout::value; +template constexpr bool is_pod_v = std::is_pod::value; +template constexpr bool is_empty_v = std::is_empty::value; +template constexpr bool is_polymorphic_v = + std::is_polymorphic::value; +template constexpr bool is_abstract_v = std::is_abstract::value; +template constexpr bool is_final_v = std::is_final::value; +template constexpr bool is_signed_v = std::is_signed::value; +template constexpr bool is_unsigned_v = std::is_unsigned::value; +template constexpr bool is_constructible_v = + std::is_constructible::value; +template constexpr bool is_default_constructible_v = + std::is_default_constructible::value; +template constexpr bool is_copy_constructible_v = + std::is_copy_constructible::value; +template constexpr bool is_move_constructible_v = + std::is_move_constructible::value; +template constexpr bool is_assignable_v = + std::is_assignable::value; +template constexpr bool is_copy_assignable_v = + std::is_copy_assignable::value; +template constexpr bool is_move_assignable_v = + std::is_move_assignable::value; +template constexpr bool is_destructible_v = + std::is_destructible::value; +template constexpr bool is_trivially_constructible_v = + std::is_trivially_constructible::value; +template constexpr bool is_trivially_default_constructible_v = + std::is_trivially_default_constructible::value; +template constexpr bool is_trivially_copy_constructible_v = + std::is_trivially_copy_constructible::value; +template constexpr bool is_trivially_move_constructible_v = + std::is_trivially_move_constructible::value; +template constexpr bool is_trivially_assignable_v = + std::is_trivially_assignable::value; +template constexpr bool is_trivially_copy_assignable_v = + std::is_trivially_copy_assignable::value; +template constexpr bool is_trivially_move_assignable_v = + std::is_trivially_move_assignable::value; +template constexpr bool is_trivially_destructible_v = + std::is_trivially_destructible::value; +template constexpr bool is_nothrow_constructible_v = + std::is_nothrow_constructible::value; +template constexpr bool is_nothrow_default_constructible_v = + std::is_nothrow_default_constructible::value; +template constexpr bool is_nothrow_copy_constructible_v = + std::is_nothrow_copy_constructible::value; +template constexpr bool is_nothrow_move_constructible_v = + std::is_nothrow_move_constructible::value; +template constexpr bool is_nothrow_assignable_v = + std::is_nothrow_assignable::value; +template constexpr bool is_nothrow_copy_assignable_v = + std::is_nothrow_copy_assignable::value; +template constexpr bool is_nothrow_move_assignable_v = + std::is_nothrow_move_assignable::value; +template constexpr bool is_nothrow_destructible_v = + std::is_nothrow_destructible::value; +template constexpr bool has_virtual_destructor_v = + std::has_virtual_destructor::value; + +// type property queries +template constexpr size_t alignment_of_v = std::alignment_of::value; +template constexpr size_t rank_v = std::rank::value; +template constexpr size_t extent_v = + std::extent::value; + +// type relations +template constexpr bool is_same_v = std::is_same::value; +template constexpr bool is_base_of_v = + std::is_base_of::value; +template constexpr bool is_convertible_v = + std::is_convertible::value; namespace _backport14 { template @@ -57,7 +158,7 @@ inline typename uniquity::datum make_unique(Args&&... args) { template inline typename uniquity::array make_unique(std::size_t n) { - return std::unique_ptr(new remove_extent_t[n]()); + return std::unique_ptr(new std::remove_extent_t[n]()); } template @@ -87,7 +188,7 @@ constexpr std::size_t size(const T (&array)[N]) noexcept { // invoke_result_t, and so may not behave correctly when SFINAE is required template class not_fn_result { - using DecayF = decay_t; + using DecayF = std::decay_t; DecayF fn; public: explicit not_fn_result(F&& f) : fn(std::forward(f)) {} @@ -96,23 +197,23 @@ class not_fn_result { template auto operator()(Args&&... args) & - -> decltype(!std::declval>()) { + -> decltype(!std::declval>()) { return !fn(std::forward(args)...); } template auto operator()(Args&&... args) const& - -> decltype(!std::declval>()) { + -> decltype(!std::declval>()) { return !fn(std::forward(args)...); } template auto operator()(Args&&... args) && - -> decltype(!std::declval>()) { + -> decltype(!std::declval>()) { return !std::move(fn)(std::forward(args)...); } template auto operator()(Args&&... args) const&& - -> decltype(!std::declval>()) { + -> decltype(!std::declval>()) { return !std::move(fn)(std::forward(args)...); } }; @@ -128,10 +229,8 @@ constexpr in_place_t in_place{}; template struct in_place_type_t {}; -#ifdef __cpp_variable_templates template constexpr in_place_type_t in_place_type{}; -#endif // __cpp_variable_templates } // namespace _backport17 namespace _backport_ts { @@ -186,11 +285,11 @@ private: }; template -ostream_joiner, CharT, Traits> +ostream_joiner, CharT, Traits> make_ostream_joiner(std::basic_ostream& os, DelimT&& delimiter) { - return ostream_joiner, - CharT, Traits>(os, std::forward(delimiter)); + return ostream_joiner, + CharT, Traits>(os, std::forward(delimiter)); } } // namespace _backport_ts @@ -202,9 +301,7 @@ using _backport17::not_fn; using _backport17::in_place_t; using _backport17::in_place; using _backport17::in_place_type_t; -#ifdef __cpp_variable_templates using _backport17::in_place_type; -#endif // __cpp_variable_templates using _backport_ts::ostream_joiner; using _backport_ts::make_ostream_joiner; } // namespace ceph diff --git a/src/common/config.h b/src/common/config.h index 25305d46186..a3a2c4f576a 100644 --- a/src/common/config.h +++ b/src/common/config.h @@ -168,7 +168,7 @@ public: template const T get_val(const std::string &key) const; template auto with_val(const string& key, Callback&& cb, Args&&... args) const -> - ceph::result_of_t { + std::result_of_t { return std::forward(cb)( boost::get(this->get_val_generic(key)), std::forward(args)...); diff --git a/src/common/convenience.h b/src/common/convenience.h index 1c935abc526..442cad4b2b2 100644 --- a/src/common/convenience.h +++ b/src/common/convenience.h @@ -46,38 +46,38 @@ namespace ceph { // are some lock factories. template inline auto uniquely_lock(Mutex&& m, Args&& ...args) - -> std::unique_lock > { - return std::unique_lock >( + -> std::unique_lock > { + return std::unique_lock >( std::forward(m), std::forward(args)... ); } template inline auto sharingly_lock(Mutex&& m, Args&& ...args) - -> boost::shared_lock > { + -> boost::shared_lock > { return - boost::shared_lock >( + boost::shared_lock >( std::forward(m), std::forward(args)...); } template inline auto shuniquely_lock(std::unique_lock&& m, Args&& ...args) - -> shunique_lock > { - return shunique_lock >( + -> shunique_lock > { + return shunique_lock >( std::forward >(m), std::forward(args)...); } template inline auto shuniquely_lock(boost::shared_lock&& m, Args&& ...args) - -> shunique_lock > { - return shunique_lock >( + -> shunique_lock > { + return shunique_lock >( std::forward >(m), std::forward(args)...); } template inline auto shuniquely_lock(Mutex&& m, Args&& ...args) - -> shunique_lock > { - return shunique_lock >( + -> shunique_lock > { + return shunique_lock >( std::forward(m), std::forward(args)...); } @@ -104,7 +104,7 @@ inline auto shuniquely_lock(Mutex&& m, Args&& ...args) template inline auto guardedly_lock(Mutex&& m) - -> std::lock_guard > { + -> std::lock_guard > { m.lock(); // So the way this works is that Copy List Initialization creates // one and only one Temporary. There is no implicit copy that is @@ -126,7 +126,7 @@ inline auto guardedly_lock(Mutex&& m) template inline auto guardedly_lock(Mutex&& m, std::adopt_lock_t) - -> std::lock_guard > { + -> std::lock_guard > { return { std::forward(m), std::adopt_lock }; } @@ -156,11 +156,11 @@ inline auto with_shared_lock(Mutex&& mutex, Fun&& fun, Args&&... args) // returns a lock class. // #define UNIQUE_LOCK_T(m) \ - ::std::unique_lock> + ::std::unique_lock> #define SHARED_LOCK_T(m) \ - ::std::shared_lock> + ::std::shared_lock> #define SHUNIQUE_LOCK_T(m) \ - ::ceph::shunique_lock> + ::ceph::shunique_lock> // boost::optional is wonderful! Unfortunately it lacks a function for // the thing you would most obviously want to do with it: apply a @@ -176,7 +176,7 @@ inline auto with_shared_lock(Mutex&& mutex, Fun&& fun, Args&&... args) // template auto maybe_do(const boost::optional& t, F&& f) -> - boost::optional)>> + boost::optional)>> { if (t) return { std::forward(f)(*t) }; @@ -190,9 +190,9 @@ auto maybe_do(const boost::optional& t, F&& f) -> // template auto maybe_do_or(const boost::optional& t, F&& f, U&& u) -> - ceph::result_of_t)> + std::result_of_t)> { - static_assert(std::is_convertible>::value, + static_assert(ceph::is_convertible_v>, "Alternate value must be convertible to function return type."); if (t) return std::forward(f)(*t); diff --git a/src/common/static_ptr.h b/src/common/static_ptr.h index 9e4ea101aa9..43dca56b025 100644 --- a/src/common/static_ptr.h +++ b/src/common/static_ptr.h @@ -85,12 +85,12 @@ class static_ptr { // template constexpr static int create_ward() noexcept { - static_assert(std::is_void{} || - std::is_base_of>{}, + static_assert(ceph::is_void_v || + ceph::is_base_of_v>, "Value to store must be a derivative of the base."); static_assert(S <= Size, "Value too large."); - static_assert(std::is_void{} || !std::is_const{} || - std::is_const{}, + static_assert(ceph::is_void_v || !std::is_const{} || + ceph::is_const_v, "Cannot assign const pointer to non-const pointer."); return 0; } @@ -134,13 +134,13 @@ public: // // Since the templated versions don't count for overriding the defaults static_ptr(const static_ptr& rhs) - noexcept(std::is_nothrow_copy_constructible{}) : operate(rhs.operate) { + noexcept(ceph::is_nothrow_copy_constructible_v) : operate(rhs.operate) { if (operate) { operate(_mem::op::copy, &rhs.buf, &buf); } } static_ptr(static_ptr&& rhs) - noexcept(std::is_nothrow_move_constructible{}) : operate(rhs.operate) { + noexcept(ceph::is_nothrow_move_constructible_v) : operate(rhs.operate) { if (operate) { operate(_mem::op::move, &rhs.buf, &buf); } @@ -148,7 +148,7 @@ public: template static_ptr(const static_ptr& rhs) - noexcept(std::is_nothrow_copy_constructible{}) : operate(rhs.operate) { + noexcept(ceph::is_nothrow_copy_constructible_v) : operate(rhs.operate) { create_ward(); if (operate) { operate(_mem::op::copy, &rhs.buf, &buf); @@ -156,7 +156,7 @@ public: } template static_ptr(static_ptr&& rhs) - noexcept(std::is_nothrow_move_constructible{}) : operate(rhs.operate) { + noexcept(ceph::is_nothrow_move_constructible_v) : operate(rhs.operate) { create_ward(); if (operate) { operate(_mem::op::move, &rhs.buf, &buf); @@ -164,7 +164,7 @@ public: } static_ptr& operator =(const static_ptr& rhs) - noexcept(std::is_nothrow_copy_constructible{}) { + noexcept(ceph::is_nothrow_copy_constructible_v) { reset(); if (rhs) { operate = rhs.operate; @@ -174,7 +174,7 @@ public: return *this; } static_ptr& operator =(static_ptr&& rhs) - noexcept(std::is_nothrow_move_constructible{}) { + noexcept(ceph::is_nothrow_move_constructible_v) { reset(); if (rhs) { operate = rhs.operate; @@ -185,7 +185,7 @@ public: template static_ptr& operator =(const static_ptr& rhs) - noexcept(std::is_nothrow_copy_constructible{}) { + noexcept(ceph::is_nothrow_copy_constructible_v) { create_ward(); reset(); if (rhs) { @@ -197,7 +197,7 @@ public: } template static_ptr& operator =(static_ptr&& rhs) - noexcept(std::is_nothrow_move_constructible{}) { + noexcept(ceph::is_nothrow_move_constructible_v) { create_ward(); reset(); if (rhs) { @@ -215,12 +215,12 @@ public: // template static_ptr(in_place_type_t, Args&& ...args) - noexcept(std::is_nothrow_constructible{}) + noexcept(ceph::is_nothrow_constructible_v) : operate(&_mem::op_fun){ - static_assert((!std::is_nothrow_copy_constructible{} || - std::is_nothrow_copy_constructible{}) && - (!std::is_nothrow_move_constructible{} || - std::is_nothrow_move_constructible{}), + static_assert((!ceph::is_nothrow_copy_constructible_v || + ceph::is_nothrow_copy_constructible_v) && + (!ceph::is_nothrow_move_constructible_v || + ceph::is_nothrow_move_constructible_v), "If declared type of static_ptr is nothrow " "move/copy constructible, then any " "type assigned to it must be as well. " @@ -238,7 +238,7 @@ public: // template void emplace(Args&& ...args) - noexcept(std::is_nothrow_constructible{}) { + noexcept(ceph::is_nothrow_constructible_v) { create_ward(); reset(); operate = &_mem::op_fun; @@ -250,11 +250,11 @@ public: return operate ? reinterpret_cast(&buf) : nullptr; } template - enable_if_t{}, Base*> operator->() const noexcept { + std::enable_if_t, Base*> operator->() const noexcept { return get(); } template - enable_if_t{}, Base&> operator *() const noexcept { + std::enable_if_t, Base&> operator *() const noexcept { return *get(); } operator bool() const noexcept { @@ -401,7 +401,7 @@ static_ptr reinterpret_pointer_cast(static_ptr&& p) { // returns a null value rather than throwing. template static_ptr resize_pointer_cast(const static_ptr& p) { - static_assert(std::is_same{}, + static_assert(ceph::is_same_v, "resize_pointer_cast only changes size, not type."); static_ptr r; if (Z >= p.operate(_mem::op::size, &p.buf, nullptr)) { @@ -412,7 +412,7 @@ static_ptr resize_pointer_cast(const static_ptr& p) { } template static_ptr resize_pointer_cast(static_ptr&& p) { - static_assert(std::is_same{}, + static_assert(ceph::is_same_v, "resize_pointer_cast only changes size, not type."); static_ptr r; if (Z >= p.operate(_mem::op::size, &p.buf, nullptr)) { @@ -437,6 +437,6 @@ bool operator ==(std::nullptr_t, static_ptr s) { template static_ptr make_static(Args&& ...args) { - return { in_place_type_t{}, std::forward(args)... }; + return { ceph::in_place_type, std::forward(args)... }; } } diff --git a/src/include/random.h b/src/include/random.h index 45f0b33fa2c..b985606bdba 100644 --- a/src/include/random.h +++ b/src/include/random.h @@ -17,11 +17,10 @@ #include #include +#include #include "boost/optional.hpp" -#include "common/backport14.h" - // Basic random number facility, adapted from N3551: namespace ceph { namespace util { @@ -145,7 +144,7 @@ IntegerT generate_random_number() template IntegerT generate_random_number(const IntegerT min, const IntegerT max, - ceph::enable_if_t::value>* = nullptr) + std::enable_if_t::value>* = nullptr) { return detail::generate_random_number, @@ -158,7 +157,7 @@ namespace detail { template int generate_random_number(const IntegerT min, const IntegerT max, MutexT& m, EngineT& e, - ceph::enable_if_t::value>* = nullptr) + std::enable_if_t::value>* = nullptr) { return detail::generate_random_number, @@ -169,7 +168,7 @@ int generate_random_number(const IntegerT min, const IntegerT max, template int generate_random_number(const IntegerT max, MutexT& m, EngineT& e, - ceph::enable_if_t::value>* = nullptr) + std::enable_if_t::value>* = nullptr) { constexpr IntegerT zero = 0; return generate_random_number(zero, max, m, e); @@ -179,7 +178,7 @@ int generate_random_number(const IntegerT max, template int generate_random_number(const IntegerT max, - ceph::enable_if_t::value>* = nullptr) + std::enable_if_t::value>* = nullptr) { constexpr IntegerT zero = 0; return generate_random_number(zero, max); @@ -187,7 +186,7 @@ int generate_random_number(const IntegerT max, template RealT generate_random_number(const RealT min, const RealT max, - ceph::enable_if_t::value>* = nullptr) + std::enable_if_t::value>* = nullptr) { return detail::generate_random_number, @@ -199,7 +198,7 @@ namespace detail { template RealT generate_random_number(const RealT max, MutexT& m, - ceph::enable_if_t::value>* = nullptr) + std::enable_if_t::value>* = nullptr) { constexpr RealT zero = 0.0; return generate_random_number(zero, max, m); @@ -207,7 +206,7 @@ RealT generate_random_number(const RealT max, MutexT& m, template RealT generate_random_number(const RealT min, const RealT max, MutexT& m, EngineT& e, - ceph::enable_if_t::value>* = nullptr) + std::enable_if_t::value>* = nullptr) { return detail::generate_random_number, @@ -218,7 +217,7 @@ RealT generate_random_number(const RealT min, const RealT max, MutexT& m, Engine template RealT generate_random_number(const RealT max, MutexT& m, EngineT& e, - ceph::enable_if_t::value>* = nullptr) + std::enable_if_t::value>* = nullptr) { constexpr RealT zero = 0.0; return generate_random_number(zero, max, m, e); @@ -228,7 +227,7 @@ RealT generate_random_number(const RealT max, MutexT& m, EngineT& e, template RealT generate_random_number(const RealT max, - ceph::enable_if_t::value>* = nullptr) + std::enable_if_t::value>* = nullptr) { constexpr RealT zero = 0.0; return generate_random_number(zero, max);