From 3a9ec5fc9e50c19a3d25511137b675f763d08dfb Mon Sep 17 00:00:00 2001 From: "Adam C. Emerson" Date: Fri, 22 Dec 2017 17:30:08 -0500 Subject: [PATCH] common: Remove backported C++17 functions Signed-off-by: Adam C. Emerson --- src/common/backport_std.h | 49 --------------- src/rgw/rgw_iam_policy.cc | 10 +-- src/test/common/CMakeLists.txt | 3 - src/test/common/test_backport_std.cc | 94 ---------------------------- 4 files changed, 5 insertions(+), 151 deletions(-) delete mode 100644 src/test/common/test_backport_std.cc diff --git a/src/common/backport_std.h b/src/common/backport_std.h index e6b0c700c8d..f7487750119 100644 --- a/src/common/backport_std.h +++ b/src/common/backport_std.h @@ -23,53 +23,6 @@ namespace ceph { -namespace _backport17 { -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)); -} -} // namespace _backport17 - namespace _backport_ts { template & os, } // namespace _backport_ts -using _backport17::size; -using _backport17::not_fn; using _backport_ts::ostream_joiner; using _backport_ts::make_ostream_joiner; } // namespace ceph diff --git a/src/rgw/rgw_iam_policy.cc b/src/rgw/rgw_iam_policy.cc index 11078d494c0..91bbabf5959 100644 --- a/src/rgw/rgw_iam_policy.cc +++ b/src/rgw/rgw_iam_policy.cc @@ -943,27 +943,27 @@ bool Condition::eval(const Environment& env) const { return orrible(std::equal_to(), s, vals); case TokenID::StringNotEquals: - return orrible(ceph::not_fn(std::equal_to()), + return orrible(std::not_fn(std::equal_to()), s, vals); case TokenID::StringEqualsIgnoreCase: return orrible(ci_equal_to(), s, vals); case TokenID::StringNotEqualsIgnoreCase: - return orrible(ceph::not_fn(ci_equal_to()), s, vals); + return orrible(std::not_fn(ci_equal_to()), s, vals); case TokenID::StringLike: return orrible(string_like(), s, vals); case TokenID::StringNotLike: - return orrible(ceph::not_fn(string_like()), s, vals); + return orrible(std::not_fn(string_like()), s, vals); // Numeric case TokenID::NumericEquals: return shortible(std::equal_to(), as_number, s, vals); case TokenID::NumericNotEquals: - return shortible(ceph::not_fn(std::equal_to()), + return shortible(std::not_fn(std::equal_to()), as_number, s, vals); @@ -985,7 +985,7 @@ bool Condition::eval(const Environment& env) const { return shortible(std::equal_to(), as_date, s, vals); case TokenID::DateNotEquals: - return shortible(ceph::not_fn(std::equal_to()), + return shortible(std::not_fn(std::equal_to()), as_date, s, vals); case TokenID::DateLessThan: diff --git a/src/test/common/CMakeLists.txt b/src/test/common/CMakeLists.txt index b0c3245eeb8..b934cfd9c2a 100644 --- a/src/test/common/CMakeLists.txt +++ b/src/test/common/CMakeLists.txt @@ -265,9 +265,6 @@ add_executable(unittest_iso_8601 target_link_libraries(unittest_iso_8601 ceph-common) add_ceph_unittest(unittest_iso_8601) -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) add_ceph_unittest(unittest_convenience) diff --git a/src/test/common/test_backport_std.cc b/src/test/common/test_backport_std.cc deleted file mode 100644 index cbfa4ef6b88..00000000000 --- a/src/test/common/test_backport_std.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/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()); -} -- 2.39.5