From cc0729a6784b7f3cd1d5e730e11a69e57b5f0c9b Mon Sep 17 00:00:00 2001 From: Paul Szczepanek Date: Sun, 6 Jun 2021 11:42:20 +0100 Subject: [PATCH] add missing tuple c++ replacement for unittests --- .../target_h/platform/cxxsupport/mstd_tuple | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 UNITTESTS/target_h/platform/cxxsupport/mstd_tuple diff --git a/UNITTESTS/target_h/platform/cxxsupport/mstd_tuple b/UNITTESTS/target_h/platform/cxxsupport/mstd_tuple new file mode 100644 index 0000000000..d9e926aa57 --- /dev/null +++ b/UNITTESTS/target_h/platform/cxxsupport/mstd_tuple @@ -0,0 +1,93 @@ +/* mbed Microcontroller Library + * Copyright (c) 2019 ARM Limited + * SPDX-License-Identifier: Apache-2.0 + * + * 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 LEOR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef MSTD_TUPLE_ +#define MSTD_TUPLE_ + +/* + * + * - includes toolchain's + * - For all toolchains, C++17 backports: + * - mstd::apply + * - mstd::make_from_tuple + */ + +#include + +#if __cpp_lib_apply < 201603 || __cpp_lib_make_from_tuple < 201606 +#include // integer_sequence +#endif +#if __cpp_lib_apply < 201603 +#include // invoke +#endif + +namespace mstd { +using std::tuple; +using std::ignore; +using std::make_tuple; +using std::forward_as_tuple; +using std::tie; +using std::tuple_cat; +using std::tuple_size; +using std::tuple_element; +using std::tuple_element_t; +using std::get; + +// [tuple.apply] +#if __cpp_lib_apply >= 201603 +using std::apply; +#else +namespace impl { +template +invoke_result_t...> apply(F&& f, Tuple&& t, std::index_sequence) +{ + return mstd::invoke(std::forward(f), std::get(std::forward(t))...); +} +} + +// apply - works also for tuple-like objects such as array or pair +// user-defined types can specialize std::get and std::tuple_size to make this work +template +auto apply(F&& f, Tuple&& t) -> +decltype(impl::apply(std::forward(f), std::forward(t), std::make_index_sequence>::value>{})) +{ + return impl::apply(std::forward(f), std::forward(t), + std::make_index_sequence>::value>{}); +} +#endif + +#if __cpp_lib_make_from_tuple >= 201606 +using std::make_from_tuple; +#else +namespace impl { +template +T make_from_tuple(Tuple&& t, std::index_sequence) +{ + return T(std::get(std::forward(t))...); +} +} + +template +T make_from_tuple(Tuple&& t) +{ + return impl::make_from_tuple(std::forward(t), + std::make_index_sequence>::value>{}); +} +#endif + +} // namespace mstd + +#endif // MSTD_TUPLE_