From: Adam C. Emerson Date: Sat, 9 Dec 2017 23:57:20 +0000 (-0500) Subject: common: Get rid of artifact filename X-Git-Tag: v13.0.2~759^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=2d45f808ef20a38891dff4395f31acb5d6d5c78d;p=ceph.git common: Get rid of artifact filename Since we're on C++14, we're just backporting from future standards generally. Signed-off-by: Adam C. Emerson --- diff --git a/src/common/backport14.h b/src/common/backport14.h deleted file mode 100644 index 6e96711ba44e..000000000000 --- a/src/common/backport14.h +++ /dev/null @@ -1,269 +0,0 @@ -// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- -// vim: ts=8 sw=2 smarttab -/* - * Ceph - scalable distributed file system - * - * Copyright (C) 2004-2006 Sage Weil - * - * This is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License version 2.1, as published by the Free Software - * Foundation. See file COPYING. - * - */ - -#include -#include - -#ifndef CEPH_COMMON_BACKPORT14_H -#define CEPH_COMMON_BACKPORT14_H - -// Library code from C++14 that can be implemented in C++11. - -namespace ceph { -// 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; - -// 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; - -// 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 _backport17 { -template -constexpr auto size(const C& c) -> decltype(c.size()) { - return c.size(); -} - -template -constexpr std::size_t size(const T (&array)[N]) noexcept { - return N; -} - -/// http://en.cppreference.com/w/cpp/utility/functional/not_fn -// this implementation uses c++14's result_of_t (above) instead of the c++17 -// invoke_result_t, and so may not behave correctly when SFINAE is required -template -class not_fn_result { - using DecayF = std::decay_t; - DecayF fn; - public: - explicit not_fn_result(F&& f) : fn(std::forward(f)) {} - not_fn_result(not_fn_result&& f) = default; - not_fn_result(const not_fn_result& f) = default; - - template - auto operator()(Args&&... args) & - -> decltype(!std::declval>()) { - return !fn(std::forward(args)...); - } - template - auto operator()(Args&&... args) const& - -> decltype(!std::declval>()) { - return !fn(std::forward(args)...); - } - - template - auto operator()(Args&&... args) && - -> decltype(!std::declval>()) { - return !std::move(fn)(std::forward(args)...); - } - template - auto operator()(Args&&... args) const&& - -> decltype(!std::declval>()) { - return !std::move(fn)(std::forward(args)...); - } -}; - -template -not_fn_result not_fn(F&& fn) { - return not_fn_result(std::forward(fn)); -} - -struct in_place_t {}; -constexpr in_place_t in_place{}; - -template -struct in_place_type_t {}; - -template -constexpr in_place_type_t in_place_type{}; -} // namespace _backport17 - -namespace _backport_ts { -template > -class ostream_joiner { -public: - using char_type = CharT; - using traits_type = Traits; - using ostream_type = std::basic_ostream; - using iterator_category = std::output_iterator_tag; - using value_type = void; - using difference_type = void; - using pointer = void; - using reference = void; - - ostream_joiner(ostream_type& s, const DelimT& delimiter) - : out_stream(std::addressof(out_stream)), - delim(delimiter), - first_element(true) - {} - ostream_joiner(ostream_type& s, DelimT&& delimiter) - : out_stream(std::addressof(s)), - delim(std::move(delimiter)), - first_element(true) - {} - - template - ostream_joiner& operator=(const T& value) { - if (!first_element) - *out_stream << delim; - first_element = false; - *out_stream << value; - return *this; - } - - ostream_joiner& operator*() noexcept { - return *this; - } - ostream_joiner& operator++() noexcept { - return *this; - } - ostream_joiner& operator++(int) noexcept { - return this; - } - -private: - ostream_type* out_stream; - DelimT delim; - bool first_element; -}; - -template -ostream_joiner, CharT, Traits> -make_ostream_joiner(std::basic_ostream& os, - DelimT&& delimiter) { - return ostream_joiner, - CharT, Traits>(os, std::forward(delimiter)); -} - -} // namespace _backport_ts - -using _backport17::size; -using _backport17::not_fn; -using _backport17::in_place_t; -using _backport17::in_place; -using _backport17::in_place_type_t; -using _backport17::in_place_type; -using _backport_ts::ostream_joiner; -using _backport_ts::make_ostream_joiner; -} // namespace ceph - -#endif // CEPH_COMMON_BACKPORT14_H diff --git a/src/common/backport_std.h b/src/common/backport_std.h new file mode 100644 index 000000000000..880b103deb8c --- /dev/null +++ b/src/common/backport_std.h @@ -0,0 +1,270 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2004-2006 Sage Weil + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + * + */ + +#include +#include + +#ifndef CEPH_COMMON_BACKPORT14_H +#define CEPH_COMMON_BACKPORT14_H + +// Library code from later C++ standards and technical specifications +// backported to C++14. + +namespace ceph { +// 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; + +// 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; + +// 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 _backport17 { +template +constexpr auto size(const C& c) -> decltype(c.size()) { + return c.size(); +} + +template +constexpr std::size_t size(const T (&array)[N]) noexcept { + return N; +} + +/// http://en.cppreference.com/w/cpp/utility/functional/not_fn +// this implementation uses c++14's result_of_t (above) instead of the c++17 +// invoke_result_t, and so may not behave correctly when SFINAE is required +template +class not_fn_result { + using DecayF = std::decay_t; + DecayF fn; + public: + explicit not_fn_result(F&& f) : fn(std::forward(f)) {} + not_fn_result(not_fn_result&& f) = default; + not_fn_result(const not_fn_result& f) = default; + + template + auto operator()(Args&&... args) & + -> decltype(!std::declval>()) { + return !fn(std::forward(args)...); + } + template + auto operator()(Args&&... args) const& + -> decltype(!std::declval>()) { + return !fn(std::forward(args)...); + } + + template + auto operator()(Args&&... args) && + -> decltype(!std::declval>()) { + return !std::move(fn)(std::forward(args)...); + } + template + auto operator()(Args&&... args) const&& + -> decltype(!std::declval>()) { + return !std::move(fn)(std::forward(args)...); + } +}; + +template +not_fn_result not_fn(F&& fn) { + return not_fn_result(std::forward(fn)); +} + +struct in_place_t {}; +constexpr in_place_t in_place{}; + +template +struct in_place_type_t {}; + +template +constexpr in_place_type_t in_place_type{}; +} // namespace _backport17 + +namespace _backport_ts { +template > +class ostream_joiner { +public: + using char_type = CharT; + using traits_type = Traits; + using ostream_type = std::basic_ostream; + using iterator_category = std::output_iterator_tag; + using value_type = void; + using difference_type = void; + using pointer = void; + using reference = void; + + ostream_joiner(ostream_type& s, const DelimT& delimiter) + : out_stream(std::addressof(out_stream)), + delim(delimiter), + first_element(true) + {} + ostream_joiner(ostream_type& s, DelimT&& delimiter) + : out_stream(std::addressof(s)), + delim(std::move(delimiter)), + first_element(true) + {} + + template + ostream_joiner& operator=(const T& value) { + if (!first_element) + *out_stream << delim; + first_element = false; + *out_stream << value; + return *this; + } + + ostream_joiner& operator*() noexcept { + return *this; + } + ostream_joiner& operator++() noexcept { + return *this; + } + ostream_joiner& operator++(int) noexcept { + return this; + } + +private: + ostream_type* out_stream; + DelimT delim; + bool first_element; +}; + +template +ostream_joiner, CharT, Traits> +make_ostream_joiner(std::basic_ostream& os, + DelimT&& delimiter) { + return ostream_joiner, + CharT, Traits>(os, std::forward(delimiter)); +} + +} // namespace _backport_ts + +using _backport17::size; +using _backport17::not_fn; +using _backport17::in_place_t; +using _backport17::in_place; +using _backport17::in_place_type_t; +using _backport17::in_place_type; +using _backport_ts::ostream_joiner; +using _backport_ts::make_ostream_joiner; +} // namespace ceph + +#endif // CEPH_COMMON_BACKPORT14_H diff --git a/src/common/config.h b/src/common/config.h index a3a2c4f576a9..0e049920eeaf 100644 --- a/src/common/config.h +++ b/src/common/config.h @@ -15,7 +15,7 @@ #ifndef CEPH_CONFIG_H #define CEPH_CONFIG_H -#include "common/backport14.h" +#include "common/backport_std.h" #include "common/ConfUtils.h" #include "common/entity_name.h" #include "common/code_environment.h" diff --git a/src/common/convenience.h b/src/common/convenience.h index 442cad4b2b2e..65fc30d54be3 100644 --- a/src/common/convenience.h +++ b/src/common/convenience.h @@ -20,7 +20,7 @@ #include #include -#include "common/backport14.h" +#include "common/backport_std.h" #include "common/shunique_lock.h" #include "include/assert.h" // I despise you. Not you the reader, I'm talking diff --git a/src/common/static_ptr.h b/src/common/static_ptr.h index 43dca56b0259..fd8b0e07f07d 100644 --- a/src/common/static_ptr.h +++ b/src/common/static_ptr.h @@ -12,7 +12,8 @@ * */ -#include "common/backport14.h" +#include +#include "common/backport_std.h" namespace ceph { // `static_ptr` diff --git a/src/include/scope_guard.h b/src/include/scope_guard.h index b60667f792e7..2c11d89f82d5 100644 --- a/src/include/scope_guard.h +++ b/src/include/scope_guard.h @@ -17,7 +17,7 @@ #include -#include "common/backport14.h" +#include "common/backport_std.h" template struct scope_guard { diff --git a/src/mds/MDSDaemon.cc b/src/mds/MDSDaemon.cc index d184d68cceb6..f24c6c5efab3 100644 --- a/src/mds/MDSDaemon.cc +++ b/src/mds/MDSDaemon.cc @@ -21,7 +21,7 @@ #include "common/Clock.h" #include "common/HeartbeatMap.h" #include "common/Timer.h" -#include "common/backport14.h" +#include "common/backport_std.h" #include "common/ceph_argparse.h" #include "common/config.h" #include "common/entity_name.h" diff --git a/src/msg/QueueStrategy.cc b/src/msg/QueueStrategy.cc index 21cdb725b877..d72350d217f5 100644 --- a/src/msg/QueueStrategy.cc +++ b/src/msg/QueueStrategy.cc @@ -15,7 +15,7 @@ #include "QueueStrategy.h" #define dout_subsys ceph_subsys_ms #include "common/debug.h" -#include "common/backport14.h" +#include "common/backport_std.h" QueueStrategy::QueueStrategy(int _n_threads) : lock("QueueStrategy::lock"), diff --git a/src/osd/OSD.h b/src/osd/OSD.h index ce20ec2ef825..089a70ab625f 100644 --- a/src/osd/OSD.h +++ b/src/osd/OSD.h @@ -19,7 +19,7 @@ #include "msg/Dispatcher.h" -#include "common/backport14.h" +#include "common/backport_std.h" #include "common/Mutex.h" #include "common/RWLock.h" #include "common/Timer.h" diff --git a/src/rgw/rgw_bucket.cc b/src/rgw/rgw_bucket.cc index 61fb6c9f0807..93344bfa9393 100644 --- a/src/rgw/rgw_bucket.cc +++ b/src/rgw/rgw_bucket.cc @@ -12,7 +12,7 @@ #include "common/errno.h" #include "common/ceph_json.h" -#include "common/backport14.h" +#include "common/backport_std.h" #include "rgw_rados.h" #include "rgw_acl.h" #include "rgw_acl_s3.h" diff --git a/src/rgw/rgw_iam_policy.cc b/src/rgw/rgw_iam_policy.cc index c6666cb652cd..62ba3163cb2e 100644 --- a/src/rgw/rgw_iam_policy.cc +++ b/src/rgw/rgw_iam_policy.cc @@ -11,7 +11,7 @@ #include #include "rapidjson/reader.h" -#include "common/backport14.h" +#include "common/backport_std.h" #include "rgw_auth.h" #include #include "rgw_iam_policy.h" diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index 5431b0630cd0..a0baf1df8716 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -16,7 +16,7 @@ #include "common/Clock.h" #include "common/armor.h" -#include "common/backport14.h" +#include "common/backport_std.h" #include "common/errno.h" #include "common/mime.h" #include "common/utf8.h" diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index ccc3cabedf9e..852d6b00feb0 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -10,7 +10,7 @@ #include "common/utf8.h" #include "common/ceph_json.h" #include "common/safe_io.h" -#include "common/backport14.h" +#include "common/backport_std.h" #include #include #include diff --git a/src/rgw/rgw_rest_s3.h b/src/rgw/rgw_rest_s3.h index dea68a93d108..df626717d32d 100644 --- a/src/rgw/rgw_rest_s3.h +++ b/src/rgw/rgw_rest_s3.h @@ -11,7 +11,7 @@ #include #include -#include "common/backport14.h" +#include "common/backport_std.h" #include "common/sstring.hh" #include "rgw_op.h" #include "rgw_rest.h" diff --git a/src/rgw/rgw_user.cc b/src/rgw/rgw_user.cc index ce998d138005..210b01c8faa1 100644 --- a/src/rgw/rgw_user.cc +++ b/src/rgw/rgw_user.cc @@ -11,7 +11,7 @@ #include "common/Formatter.h" #include "common/ceph_json.h" #include "common/RWLock.h" -#include "common/backport14.h" +#include "common/backport_std.h" #include "rgw_rados.h" #include "rgw_acl.h" diff --git a/src/test/common/CMakeLists.txt b/src/test/common/CMakeLists.txt index bb5d892da876..b0c3245eeb86 100644 --- a/src/test/common/CMakeLists.txt +++ b/src/test/common/CMakeLists.txt @@ -265,8 +265,8 @@ add_executable(unittest_iso_8601 target_link_libraries(unittest_iso_8601 ceph-common) add_ceph_unittest(unittest_iso_8601) -add_executable(unittest_backport14 test_backport14.cc) -add_ceph_unittest(unittest_backport14) +add_executable(unittest_backport_std test_backport_std.cc) +add_ceph_unittest(unittest_backport_std) add_executable(unittest_convenience test_convenience.cc) target_link_libraries(unittest_convenience ceph-common) diff --git a/src/test/common/Throttle.cc b/src/test/common/Throttle.cc index fdb1e06e0756..ad4a81605946 100644 --- a/src/test/common/Throttle.cc +++ b/src/test/common/Throttle.cc @@ -29,12 +29,11 @@ #include #include "gtest/gtest.h" -#include "common/backport14.h" #include "common/Mutex.h" #include "common/Thread.h" #include "common/Throttle.h" #include "common/ceph_argparse.h" -#include "common/backport14.h" +#include "common/backport_std.h" class ThrottleTest : public ::testing::Test { protected: diff --git a/src/test/common/test_backport14.cc b/src/test/common/test_backport14.cc deleted file mode 100644 index 63ef5d0e7b3d..000000000000 --- a/src/test/common/test_backport14.cc +++ /dev/null @@ -1,94 +0,0 @@ -// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- -// vim: ts=8 sw=2 smarttab -/* - * Ceph - scalable distributed file system - * - * Copyright (C) 2017 Red Hat, Inc. - * - * Author: Casey Bodley - * - * This is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License version 2.1, as published by the Free Software - * Foundation. See file COPYING. - * - */ - -#include "common/backport14.h" // include first: tests that header is standalone -#include - -int int_func() { return 1; } -bool bool_func0() { return true; } -bool bool_func1(int a) { return true; } -bool bool_func2(const std::string& a, int b) { return true; } - -// given a callable and argument list, test that the result of ceph::not_fn -// evaluates to false as both an lvalue and rvalue -template -void test_not(F&& fn, Args&&... args) -{ - auto res = ceph::not_fn(std::forward(fn)); - // test res as lvalue - EXPECT_FALSE(res(std::forward(args)...)); - // test res as rvalue - // note: this forwards args twice, but it's okay if none are rvalues - EXPECT_FALSE(std::move(res)(std::forward(args)...)); -} - -TEST(Backport14, not_fn) -{ - // function pointers - test_not(int_func); - test_not(&int_func); - test_not(bool_func0); - test_not(&bool_func0); - test_not(bool_func1, 5); - test_not(bool_func2, "foo", 5); - - // lambdas - auto int_lambda = [] { return 1; }; - auto bool_lambda0 = [] { return true; }; - auto bool_lambda1 = [] (int a) { return true; }; - auto bool_lambda2 = [] (const std::string& a, int b) { return true; }; - - test_not(int_lambda); - test_not(bool_lambda0); - test_not(bool_lambda1, 5); - test_not(bool_lambda2, "foo", 5); - - // functors - struct int_functor { - int operator()() { return 1; } - }; - test_not(int_functor{}); - - struct bool_functor { - bool operator()() { return true; } - bool operator()(int a) { return true; } - bool operator()(const std::string& a, int b) { return true; } - }; - - test_not(bool_functor{}); - test_not(bool_functor{}, 5); - test_not(bool_functor{}, "foo", 5); - - // lvalue-only overload - struct lvalue_only_functor { - bool operator()() & { return true; } // no overload for rvalue - }; - auto lvalue_result = ceph::not_fn(lvalue_only_functor{}); - EXPECT_FALSE(lvalue_result()); - // should not compile: - // EXPECT_FALSE(std::move(lvalue_result)()); - - // rvalue-only overload - struct rvalue_only_functor { - bool operator()() && { return true; } // no overload for lvalue - }; - EXPECT_FALSE(ceph::not_fn(rvalue_only_functor{})()); - auto lvalue_functor = rvalue_only_functor{}; - EXPECT_FALSE(ceph::not_fn(lvalue_functor)()); // lvalue functor, rvalue result - // should not compile: - // auto lvalue_result2 = ceph::not_fn(rvalue_only_functor{}); - // EXPECT_FALSE(lvalue_result2()); -} diff --git a/src/test/common/test_backport_std.cc b/src/test/common/test_backport_std.cc new file mode 100644 index 000000000000..cbfa4ef6b88f --- /dev/null +++ b/src/test/common/test_backport_std.cc @@ -0,0 +1,94 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2017 Red Hat, Inc. + * + * Author: Casey Bodley + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + * + */ + +#include "common/backport_std.h" // include first: tests that header is standalone +#include + +int int_func() { return 1; } +bool bool_func0() { return true; } +bool bool_func1(int a) { return true; } +bool bool_func2(const std::string& a, int b) { return true; } + +// given a callable and argument list, test that the result of ceph::not_fn +// evaluates to false as both an lvalue and rvalue +template +void test_not(F&& fn, Args&&... args) +{ + auto res = ceph::not_fn(std::forward(fn)); + // test res as lvalue + EXPECT_FALSE(res(std::forward(args)...)); + // test res as rvalue + // note: this forwards args twice, but it's okay if none are rvalues + EXPECT_FALSE(std::move(res)(std::forward(args)...)); +} + +TEST(Backport14, not_fn) +{ + // function pointers + test_not(int_func); + test_not(&int_func); + test_not(bool_func0); + test_not(&bool_func0); + test_not(bool_func1, 5); + test_not(bool_func2, "foo", 5); + + // lambdas + auto int_lambda = [] { return 1; }; + auto bool_lambda0 = [] { return true; }; + auto bool_lambda1 = [] (int a) { return true; }; + auto bool_lambda2 = [] (const std::string& a, int b) { return true; }; + + test_not(int_lambda); + test_not(bool_lambda0); + test_not(bool_lambda1, 5); + test_not(bool_lambda2, "foo", 5); + + // functors + struct int_functor { + int operator()() { return 1; } + }; + test_not(int_functor{}); + + struct bool_functor { + bool operator()() { return true; } + bool operator()(int a) { return true; } + bool operator()(const std::string& a, int b) { return true; } + }; + + test_not(bool_functor{}); + test_not(bool_functor{}, 5); + test_not(bool_functor{}, "foo", 5); + + // lvalue-only overload + struct lvalue_only_functor { + bool operator()() & { return true; } // no overload for rvalue + }; + auto lvalue_result = ceph::not_fn(lvalue_only_functor{}); + EXPECT_FALSE(lvalue_result()); + // should not compile: + // EXPECT_FALSE(std::move(lvalue_result)()); + + // rvalue-only overload + struct rvalue_only_functor { + bool operator()() && { return true; } // no overload for lvalue + }; + EXPECT_FALSE(ceph::not_fn(rvalue_only_functor{})()); + auto lvalue_functor = rvalue_only_functor{}; + EXPECT_FALSE(ceph::not_fn(lvalue_functor)()); // lvalue functor, rvalue result + // should not compile: + // auto lvalue_result2 = ceph::not_fn(rvalue_only_functor{}); + // EXPECT_FALSE(lvalue_result2()); +} diff --git a/src/test/libradosstriper/striping.cc b/src/test/libradosstriper/striping.cc index 6bb58df614e9..f31667e86890 100644 --- a/src/test/libradosstriper/striping.cc +++ b/src/test/libradosstriper/striping.cc @@ -8,7 +8,7 @@ #include "include/radosstriper/libradosstriper.h" #include "include/radosstriper/libradosstriper.hpp" #include "include/ceph_fs.h" -#include "common/backport14.h" +#include "common/backport_std.h" #include "test/librados/test.h" #include "test/libradosstriper/TestCase.h" diff --git a/src/test/librgw_file_marker.cc b/src/test/librgw_file_marker.cc index 97db99bb86fb..3aaf76d2bd01 100644 --- a/src/test/librgw_file_marker.cc +++ b/src/test/librgw_file_marker.cc @@ -24,7 +24,7 @@ #include "rgw/rgw_lib_frontend.h" // direct requests #include "gtest/gtest.h" -#include "common/backport14.h" +#include "common/backport_std.h" #include "common/ceph_argparse.h" #include "common/debug.h" #include "global/global_init.h" diff --git a/src/test/librgw_file_nfsns.cc b/src/test/librgw_file_nfsns.cc index a09c21c3d96a..59dbc2a087ba 100644 --- a/src/test/librgw_file_nfsns.cc +++ b/src/test/librgw_file_nfsns.cc @@ -24,7 +24,7 @@ #include "rgw/rgw_lib_frontend.h" // direct requests #include "gtest/gtest.h" -#include "common/backport14.h" +#include "common/backport_std.h" #include "common/ceph_argparse.h" #include "common/debug.h" #include "global/global_init.h"