mirror of https://gitee.com/bigwinds/arangodb
remove backports
This commit is contained in:
parent
36bde0dfad
commit
c6aef7194b
|
@ -32,7 +32,6 @@
|
|||
#include "Futures/Promise.h"
|
||||
#include "Futures/SharedState.h"
|
||||
#include "Futures/Unit.h"
|
||||
#include "Futures/backports.h"
|
||||
|
||||
namespace arangodb {
|
||||
namespace futures {
|
||||
|
@ -102,7 +101,7 @@ struct valueCallableResult {
|
|||
template <class F, typename R = typename std::result_of<F()>::type>
|
||||
typename std::enable_if<!std::is_same<R, void>::value, Try<R>>::type makeTryWith(F&& func) noexcept {
|
||||
try {
|
||||
return Try<R>(in_place, func());
|
||||
return Try<R>(std::in_place, func());
|
||||
} catch (...) {
|
||||
return Try<R>(std::current_exception());
|
||||
}
|
||||
|
@ -211,8 +210,8 @@ class Future {
|
|||
|
||||
// Construct a Future from a `T` constructed from `args`
|
||||
template <class... Args, typename std::enable_if<std::is_constructible<T, Args&&...>::value, int>::type = 0>
|
||||
explicit Future(in_place_t, Args&&... args)
|
||||
: _state(detail::SharedState<T>::make(in_place, std::forward<Args>(args)...)) {}
|
||||
explicit Future(std::in_place_t, Args&&... args)
|
||||
: _state(detail::SharedState<T>::make(std::in_place, std::forward<Args>(args)...)) {}
|
||||
|
||||
Future(Future const& o) = delete;
|
||||
Future(Future<T>&& o) noexcept : _state(std::move(o._state)) {
|
||||
|
@ -354,7 +353,7 @@ class Future {
|
|||
pr.setException(std::move(t).exception());
|
||||
} else {
|
||||
pr.setTry(detail::makeTryWith([&fn, &t] {
|
||||
return futures::invoke(std::forward<DF>(fn), std::move(t).get());
|
||||
return std::invoke(std::forward<DF>(fn), std::move(t).get());
|
||||
}));
|
||||
}
|
||||
});
|
||||
|
@ -370,7 +369,7 @@ class Future {
|
|||
using DF = detail::decay_t<F>;
|
||||
|
||||
static_assert(!isFuture<B>::value, "");
|
||||
static_assert(is_invocable_r<Future<B>, F, T>::value,
|
||||
static_assert(std::is_invocable_r<Future<B>, F, T>::value,
|
||||
"Function must be invocable with T");
|
||||
|
||||
Promise<B> promise;
|
||||
|
@ -381,7 +380,7 @@ class Future {
|
|||
pr.setException(std::move(t).exception());
|
||||
} else {
|
||||
try {
|
||||
auto f = futures::invoke(std::forward<DF>(fn), std::move(t).get());
|
||||
auto f = std::invoke(std::forward<DF>(fn), std::move(t).get());
|
||||
std::move(f).then([pr = std::move(pr)](Try<B>&& t) mutable {
|
||||
pr.setTry(std::move(t));
|
||||
});
|
||||
|
@ -409,7 +408,7 @@ class Future {
|
|||
getState().setCallback([fn = std::forward<DF>(func),
|
||||
pr = std::move(promise)](Try<T>&& t) mutable {
|
||||
pr.setTry(detail::makeTryWith([&fn, &t] {
|
||||
return futures::invoke(std::forward<DF>(fn), std::move(t));
|
||||
return std::invoke(std::forward<DF>(fn), std::move(t));
|
||||
}));
|
||||
});
|
||||
return future;
|
||||
|
@ -428,7 +427,7 @@ class Future {
|
|||
getState().setCallback([fn = std::forward<F>(func),
|
||||
pr = std::move(promise)](Try<T>&& t) mutable {
|
||||
try {
|
||||
auto f = futures::invoke(std::forward<F>(fn), std::move(t));
|
||||
auto f = std::invoke(std::forward<F>(fn), std::move(t));
|
||||
std::move(f).then([pr = std::move(pr)](Try<B>&& t) mutable {
|
||||
pr.setTry(std::move(t));
|
||||
});
|
||||
|
@ -465,7 +464,7 @@ class Future {
|
|||
std::rethrow_exception(std::move(t).exception());
|
||||
} catch (ET& e) {
|
||||
pr.setTry(detail::makeTryWith([&fn, &e]() mutable {
|
||||
return futures::invoke(std::forward<DF>(fn), e);
|
||||
return std::invoke(std::forward<DF>(fn), e);
|
||||
}));
|
||||
} catch (...) {
|
||||
pr.setException(std::current_exception());
|
||||
|
@ -494,7 +493,7 @@ class Future {
|
|||
std::rethrow_exception(std::move(t).exception());
|
||||
} catch (ET& e) {
|
||||
try {
|
||||
auto f = futures::invoke(std::forward<DF>(fn), e);
|
||||
auto f = std::invoke(std::forward<DF>(fn), e);
|
||||
std::move(f).then([pr = std::move(pr)](Try<B>&& t) mutable {
|
||||
pr.setTry(std::move(t));
|
||||
});
|
||||
|
|
|
@ -86,8 +86,8 @@ class SharedState {
|
|||
/// State will be OnlyResult
|
||||
/// Result held will be the `T` constructed from forwarded `args`
|
||||
template <typename... Args>
|
||||
static SharedState<T>* make(in_place_t, Args&&... args) {
|
||||
return new SharedState<T>(in_place, std::forward<Args>(args)...);
|
||||
static SharedState<T>* make(std::in_place_t, Args&&... args) {
|
||||
return new SharedState<T>(std::in_place, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
// not copyable
|
||||
|
@ -233,9 +233,9 @@ class SharedState {
|
|||
|
||||
/// use to construct a ready future
|
||||
template <typename... Args>
|
||||
explicit SharedState(in_place_t,
|
||||
explicit SharedState(std::in_place_t,
|
||||
Args&&... args) noexcept(std::is_nothrow_constructible<T, Args&&...>::value)
|
||||
: _result(in_place, std::forward<Args>(args)...),
|
||||
: _result(std::in_place, std::forward<Args>(args)...),
|
||||
_state(State::OnlyResult),
|
||||
_attached(1) {}
|
||||
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
#include "Basics/Common.h"
|
||||
#include "Basics/debugging.h"
|
||||
#include "Basics/system-compiler.h"
|
||||
#include "Futures/backports.h"
|
||||
|
||||
#include <exception>
|
||||
#include <type_traits>
|
||||
|
@ -63,7 +62,7 @@ class Try {
|
|||
: _value(std::move(v)), _content(Content::Value) {}
|
||||
|
||||
template <typename... Args>
|
||||
explicit Try(in_place_t,
|
||||
explicit Try(std::in_place_t,
|
||||
Args&&... args) noexcept(std::is_nothrow_constructible<T, Args&&...>::value)
|
||||
: _value(static_cast<Args&&>(args)...), _content(Content::Value) {}
|
||||
|
||||
|
@ -395,7 +394,7 @@ class Try<void> {
|
|||
template <class F, typename R = typename std::result_of<F()>::type>
|
||||
typename std::enable_if<!std::is_same<R, void>::value, Try<R>>::type makeTryWith(F&& func) noexcept {
|
||||
try {
|
||||
return Try<R>(in_place, func());
|
||||
return Try<R>(std::in_place, func());
|
||||
} catch (...) {
|
||||
return Try<R>(std::current_exception());
|
||||
}
|
||||
|
|
|
@ -1,87 +0,0 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// DISCLAIMER
|
||||
///
|
||||
/// Copyright 2018 ArangoDB GmbH, Cologne, Germany
|
||||
///
|
||||
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
/// you may not use this file except in compliance with the License.
|
||||
/// You may obtain a copy of the License at
|
||||
///
|
||||
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||
///
|
||||
/// Unless required by applicable law or agreed to in writing, software
|
||||
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
/// See the License for the specific language governing permissions and
|
||||
/// limitations under the License.
|
||||
///
|
||||
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
|
||||
///
|
||||
/// @author Simon Grätzer
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef ARANGOD_FUTURES_BACKPORTS_H
|
||||
#define ARANGOD_FUTURES_BACKPORTS_H 1
|
||||
|
||||
#if __cplusplus >= 201703L
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
#endif
|
||||
|
||||
#include <functional>
|
||||
|
||||
namespace arangodb {
|
||||
namespace futures {
|
||||
|
||||
/// Backports from C++17 of:
|
||||
/// std::in_place_t
|
||||
/// std::in_place
|
||||
/// std::is_invocable
|
||||
/// std::is_invocable_r
|
||||
/// std::invoke
|
||||
|
||||
#if __cplusplus < 201703L
|
||||
struct in_place_tag {};
|
||||
using in_place_t = in_place_tag (&)(in_place_tag);
|
||||
inline in_place_tag in_place(in_place_tag = {}) { return {}; }
|
||||
|
||||
template <typename F, typename... Args>
|
||||
struct is_invocable
|
||||
: std::is_constructible<std::function<void(Args...)>,
|
||||
std::reference_wrapper<typename std::remove_reference<F>::type>> {
|
||||
};
|
||||
|
||||
template <typename R, typename F, typename... Args>
|
||||
struct is_invocable_r
|
||||
: std::is_constructible<std::function<R(Args...)>, std::reference_wrapper<typename std::remove_reference<F>::type>> {
|
||||
};
|
||||
|
||||
// mimic: std::invoke, C++17
|
||||
template <typename F, typename... Args>
|
||||
constexpr auto invoke(F&& f, Args&&... args) noexcept(
|
||||
noexcept(static_cast<F&&>(f)(static_cast<Args&&>(args)...)))
|
||||
-> decltype(static_cast<F&&>(f)(static_cast<Args&&>(args)...)) {
|
||||
return static_cast<F&&>(f)(static_cast<Args&&>(args)...);
|
||||
}
|
||||
template <typename M, typename C, typename... Args>
|
||||
constexpr auto invoke(M(C::*d), Args&&... args)
|
||||
-> decltype(std::mem_fn(d)(static_cast<Args&&>(args)...)) {
|
||||
return std::mem_fn(d)(static_cast<Args&&>(args)...);
|
||||
}
|
||||
|
||||
#else
|
||||
using std::invoke;
|
||||
using in_place_t = std::in_place_t;
|
||||
inline constexpr in_place_t in_place{};
|
||||
|
||||
template <class R, class FN, class... ArgTypes>
|
||||
using is_invocable_r = std::is_invocable_r<R, FN, ArgTypes...>;
|
||||
|
||||
template <class FN, class... ArgTypes>
|
||||
using is_invocable = std::is_invocable<FN, ArgTypes...>;
|
||||
#endif
|
||||
|
||||
} // namespace futures
|
||||
} // namespace arangodb
|
||||
|
||||
#endif
|
|
@ -788,7 +788,7 @@ TEST(FutureTest, ImplicitConstructor) {
|
|||
}
|
||||
|
||||
TEST(FutureTest, InPlaceConstructor) {
|
||||
auto f = Future<std::pair<int, double>>(in_place, 5, 3.2);
|
||||
auto f = Future<std::pair<int, double>>(std::in_place, 5, 3.2);
|
||||
ASSERT_TRUE(5 == f.get().first);
|
||||
}
|
||||
|
||||
|
|
|
@ -92,13 +92,13 @@ TEST(FuturesTryTest, Basic) {
|
|||
}
|
||||
|
||||
TEST(FuturesTryTest, in_place) {
|
||||
Try<A> t_a(in_place, 5);
|
||||
Try<A> t_a(std::in_place, 5);
|
||||
|
||||
ASSERT_TRUE(5 == t_a.get().x());
|
||||
}
|
||||
|
||||
TEST(FuturesTryTest, in_place_nested) {
|
||||
Try<Try<A>> t_t_a(in_place, in_place, 5);
|
||||
Try<Try<A>> t_t_a(std::in_place, std::in_place, 5);
|
||||
|
||||
ASSERT_TRUE(5 == t_t_a.get().get().x());
|
||||
}
|
||||
|
@ -124,8 +124,8 @@ TEST(FuturesTryTest, assignment_with_throwing_ctor) {
|
|||
int counter = 0;
|
||||
|
||||
{
|
||||
Try<ThrowingCopyConstructor> t1{in_place, counter};
|
||||
Try<ThrowingCopyConstructor> t2{in_place, counter};
|
||||
Try<ThrowingCopyConstructor> t1{std::in_place, counter};
|
||||
Try<ThrowingCopyConstructor> t2{std::in_place, counter};
|
||||
ASSERT_TRUE(2 == counter);
|
||||
EXPECT_ANY_THROW(t2 = t1);
|
||||
EXPECT_ANY_THROW(t2 = t1);
|
||||
|
@ -135,7 +135,7 @@ TEST(FuturesTryTest, assignment_with_throwing_ctor) {
|
|||
}
|
||||
ASSERT_TRUE(0 == counter);
|
||||
{
|
||||
Try<ThrowingCopyConstructor> t1{in_place, counter};
|
||||
Try<ThrowingCopyConstructor> t1{std::in_place, counter};
|
||||
Try<ThrowingCopyConstructor> t2;
|
||||
ASSERT_TRUE(1 == counter);
|
||||
EXPECT_ANY_THROW(t2 = t1);
|
||||
|
@ -173,12 +173,12 @@ TEST(FuturesTryTest, MoveConstRvalue) {
|
|||
// where for example MutableContainer has a mutable member that is move only
|
||||
// and you want to fetch the value from the Try and move it into a member
|
||||
{
|
||||
const Try<MutableContainer> t{in_place};
|
||||
const Try<MutableContainer> t{std::in_place};
|
||||
auto val = MoveConstructOnly(std::move(t).get().val);
|
||||
static_cast<void>(val);
|
||||
}
|
||||
{
|
||||
const Try<MutableContainer> t{in_place};
|
||||
const Try<MutableContainer> t{std::in_place};
|
||||
auto val = (*(std::move(t))).val;
|
||||
static_cast<void>(val);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue