Skip to content

Commit 1bc9b70

Browse files
committed
Add mstd_xxx headers to unit tests
Stripped down headers that route through to `std` forms more - eg no local implementation of `atomic` or `mutex`.
1 parent 9c6f34b commit 1bc9b70

File tree

10 files changed

+1301
-0
lines changed

10 files changed

+1301
-0
lines changed

UNITTESTS/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ set(unittest-includes-base
9595
"${PROJECT_SOURCE_DIR}/target_h/events"
9696
"${PROJECT_SOURCE_DIR}/target_h/events/equeue"
9797
"${PROJECT_SOURCE_DIR}/target_h/platform"
98+
"${PROJECT_SOURCE_DIR}/target_h/platform/cxxsupport"
9899
"${PROJECT_SOURCE_DIR}/target_h/drivers"
99100
"${PROJECT_SOURCE_DIR}/stubs"
100101
"${PROJECT_SOURCE_DIR}/.."
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2019 ARM Limited
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
#ifndef MSTD_ALGORITHM_
18+
#define MSTD_ALGORITHM_
19+
20+
/* <mstd_algorithm>
21+
*
22+
* - provides <algorithm>
23+
* - For ARM C 5, standard C++11/14 features:
24+
* - std::min, std::max for std::initializer_list
25+
* - std::all_of, std::any_of, std::none_of
26+
* - std::find_if_not
27+
* - std::equal (2-range forms)
28+
* - std::copy_n, std::move, std::move_backward
29+
* - mstd::min, mstd::max constexpr replacements
30+
*/
31+
32+
#include <algorithm>
33+
34+
namespace mstd {
35+
using std::min;
36+
using std::max;
37+
using std::minmax;
38+
using std::initializer_list;
39+
using std::all_of;
40+
using std::any_of;
41+
using std::none_of;
42+
using std::for_each;
43+
using std::find;
44+
using std::find_if;
45+
using std::find_if_not;
46+
using std::find_end;
47+
using std::find_first_of;
48+
using std::adjacent_find;
49+
using std::count;
50+
using std::count_if;
51+
using std::mismatch;
52+
using std::equal;
53+
using std::search;
54+
using std::search_n;
55+
using std::copy;
56+
using std::copy_n;
57+
using std::copy_if;
58+
using std::move;
59+
using std::move_backward;
60+
using std::swap_ranges;
61+
using std::iter_swap;
62+
using std::transform;
63+
using std::replace;
64+
using std::replace_if;
65+
using std::replace_copy;
66+
using std::replace_copy_if;
67+
using std::fill;
68+
using std::fill_n;
69+
using std::generate;
70+
using std::generate_n;
71+
using std::remove;
72+
using std::remove_if;
73+
using std::remove_copy;
74+
using std::remove_copy_if;
75+
using std::unique;
76+
using std::unique_copy;
77+
using std::reverse;
78+
using std::reverse_copy;
79+
using std::rotate;
80+
using std::rotate_copy;
81+
using std::partition;
82+
using std::stable_partition;
83+
using std::sort;
84+
using std::stable_sort;
85+
using std::partial_sort;
86+
using std::partial_sort_copy;
87+
using std::nth_element;
88+
using std::lower_bound;
89+
using std::upper_bound;
90+
using std::equal_range;
91+
using std::binary_search;
92+
using std::merge;
93+
using std::inplace_merge;
94+
using std::includes;
95+
using std::set_union;
96+
using std::set_intersection;
97+
using std::set_difference;
98+
using std::set_symmetric_difference;
99+
using std::push_heap;
100+
using std::pop_heap;
101+
using std::make_heap;
102+
using std::sort_heap;
103+
using std::min_element;
104+
using std::max_element;
105+
using std::lexicographical_compare;
106+
using std::next_permutation;
107+
using std::prev_permutation;
108+
}
109+
110+
#endif // MSTD_ALGORITHM_
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright (c) 2017 ARM Limited
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#ifndef MSTD_ATOMIC_
19+
#define MSTD_ATOMIC_
20+
21+
#include <atomic>
22+
23+
namespace mstd {
24+
using std::atomic;
25+
using std::atomic_is_lock_free;
26+
using std::atomic_store;
27+
using std::atomic_store_explicit;
28+
using std::atomic_load;
29+
using std::atomic_load_explicit;
30+
using std::atomic_exchange;
31+
using std::atomic_exchange_explicit;
32+
using std::atomic_compare_exchange_weak;
33+
using std::atomic_compare_exchange_weak_explicit;
34+
using std::atomic_compare_exchange_strong;
35+
using std::atomic_compare_exchange_strong_explicit;
36+
using std::atomic_fetch_add;
37+
using std::atomic_fetch_add_explicit;
38+
using std::atomic_fetch_sub;
39+
using std::atomic_fetch_sub_explicit;
40+
using std::atomic_fetch_and;
41+
using std::atomic_fetch_and_explicit;
42+
using std::atomic_fetch_or;
43+
using std::atomic_fetch_or_explicit;
44+
using std::atomic_fetch_xor;
45+
using std::atomic_fetch_xor_explicit;
46+
using std::atomic_flag;
47+
using std::atomic_flag_test_and_set;
48+
using std::atomic_flag_test_and_set_explicit;
49+
using std::atomic_flag_clear;
50+
using std::atomic_flag_clear_explicit;
51+
using std::atomic_init;
52+
using std::memory_order;
53+
using std::kill_dependency;
54+
using std::atomic_thread_fence;
55+
using std::atomic_signal_fence;
56+
}
57+
58+
#endif
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2019 ARM Limited
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
#ifndef MSTD_CSTDDEF_
18+
#define MSTD_CSTDDEF_
19+
20+
/* <mstd_cstddef>
21+
*
22+
* - provides <cstddef>
23+
* - For ARM C 5, standard C++11/14 features:
24+
* - - adds macro replacements for alignof and alignas keywords
25+
* - - adds missing std::nullptr_t
26+
* - For all toolchains:
27+
* - - MSTD_CONSTEXPR_XX_14 macros that can be used to mark
28+
* things that are valid as constexpr only for C++14 or later,
29+
* permitting constexpr use where ARM C 5 would reject it.
30+
*/
31+
32+
#include <cstddef>
33+
34+
/* Macros that can be used to mark functions and objects that are
35+
* constexpr in C++14 or later, but not in earlier versions.
36+
*/
37+
#if __cplusplus >= 201402
38+
#define MSTD_CONSTEXPR_FN_14 constexpr
39+
#define MSTD_CONSTEXPR_OBJ_14 constexpr
40+
#else
41+
#define MSTD_CONSTEXPR_FN_14 inline
42+
#define MSTD_CONSTEXPR_OBJ_14 const
43+
#endif
44+
45+
namespace mstd
46+
{
47+
using std::size_t;
48+
using std::ptrdiff_t;
49+
using std::nullptr_t;
50+
using std::max_align_t;
51+
52+
}
53+
54+
#endif // MSTD_CSTDDEF_
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2019 ARM Limited
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under tUNChe License.
16+
*/
17+
#ifndef MSTD_FUNCTIONAL_
18+
#define MSTD_FUNCTIONAL_
19+
20+
/* <mstd_functional>
21+
*
22+
* - includes toolchain's <functional>
23+
* - For ARM C 5, standard C++11/14 features:
24+
* - std::mem_fn,
25+
* - std::reference_wrapper, std::ref, std::cref
26+
* - transparent std::plus<> etc
27+
* - std::bit_and, std::bit_or, std::bit_xor, std::bit_not
28+
* - For all toolchains, C++17/20 backports:
29+
* - mbed::not_fn (C++17)
30+
* - mbed::invoke (C++17)
31+
* - mstd::unwrap_reference, mstd::unwrap_ref_decay (C++20)
32+
*/
33+
34+
#include <functional>
35+
36+
#include <mstd_memory> // addressof
37+
#include <mstd_utility> // forward
38+
#include <mstd_type_traits>
39+
40+
namespace mstd {
41+
42+
// [func.invoke]
43+
#if __cpp_lib_invoke >= 201411
44+
using std::invoke;
45+
#else
46+
template <typename F, typename... Args>
47+
invoke_result_t<F, Args...> invoke(F&& f, Args&&... args)
48+
{
49+
return impl::INVOKE(std::forward<F>(f), std::forward<Args>(args)...);
50+
}
51+
#endif // __cpp_lib_invoke
52+
53+
} // namespace mstd
54+
55+
namespace mstd {
56+
using std::reference_wrapper;
57+
using std::ref;
58+
using std::cref;
59+
using std::plus;
60+
using std::minus;
61+
using std::multiplies;
62+
using std::divides;
63+
using std::modulus;
64+
using std::negate;
65+
using std::equal_to;
66+
using std::not_equal_to;
67+
using std::greater;
68+
using std::less;
69+
using std::greater_equal;
70+
using std::less_equal;
71+
using std::logical_and;
72+
using std::logical_or;
73+
using std::logical_not;
74+
using std::bit_and;
75+
using std::bit_or;
76+
using std::bit_xor;
77+
using std::bit_not;
78+
79+
#if __cpp_lib_not_fn >= 201603
80+
using std::not_fn;
81+
#else
82+
namespace impl {
83+
// [func.not_fn]
84+
template <typename F>
85+
class not_fn_t {
86+
std::decay_t<F> fn;
87+
public:
88+
explicit not_fn_t(F&& f) : fn(std::forward<F>(f)) { }
89+
not_fn_t(const not_fn_t &other) = default;
90+
not_fn_t(not_fn_t &&other) = default;
91+
92+
template<typename... Args>
93+
auto operator()(Args&&... args) & -> decltype(!std::declval<invoke_result_t<std::decay_t<F> &, Args...>>())
94+
{
95+
return !mstd::invoke(fn, std::forward<Args>(args)...);
96+
}
97+
98+
template<typename... Args>
99+
auto operator()(Args&&... args) const & -> decltype(!std::declval<invoke_result_t<std::decay_t<F> const &, Args...>>())
100+
{
101+
return !mstd::invoke(fn, std::forward<Args>(args)...);
102+
}
103+
104+
template<typename... Args>
105+
auto operator()(Args&&... args) && -> decltype(!std::declval<invoke_result_t<std::decay_t<F>, Args...>>())
106+
{
107+
return !mstd::invoke(std::move(fn), std::forward<Args>(args)...);
108+
}
109+
110+
template<typename... Args>
111+
auto operator()(Args&&... args) const && -> decltype(!std::declval<invoke_result_t<std::decay_t<F> const, Args...>>())
112+
{
113+
return !mstd::invoke(std::move(fn), std::forward<Args>(args)...);
114+
}
115+
};
116+
}
117+
118+
template <typename F>
119+
impl::not_fn_t<F> not_fn_t(F&& f)
120+
{
121+
return impl::not_fn_t<F>(std::forward<F>(f));
122+
}
123+
#endif
124+
125+
/* C++20 unwrap_reference */
126+
template <typename T>
127+
struct unwrap_reference : type_identity<T> { };
128+
template <typename T>
129+
struct unwrap_reference<std::reference_wrapper<T>> : type_identity<T &> { };
130+
template <typename T>
131+
using unwrap_reference_t = typename unwrap_reference<T>::type;
132+
133+
/* C++20 unwrap_ref_decay */
134+
template <typename T>
135+
struct unwrap_ref_decay : unwrap_reference<std::decay_t<T>> { };
136+
template <typename T>
137+
using unwrap_ref_decay_t = typename unwrap_ref_decay<T>::type;
138+
139+
}
140+
141+
#endif // MSTD_FUNCTIONAL_

0 commit comments

Comments
 (0)