Skip to content

Commit a588881

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 b60b9dd commit a588881

File tree

9 files changed

+1298
-0
lines changed

9 files changed

+1298
-0
lines changed
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: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
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+
*/
32+
33+
#include <functional>
34+
35+
#include <mstd_memory> // addressof
36+
#include <mstd_utility> // forward
37+
#include <mstd_type_traits>
38+
39+
namespace mstd {
40+
41+
// [func.invoke]
42+
#if __cpp_lib_invoke >= 201411
43+
using std::invoke;
44+
#else
45+
template <typename F, typename... Args>
46+
invoke_result_t<F, Args...> invoke(F&& f, Args&&... args)
47+
{
48+
return impl::INVOKE(std::forward<F>(f), std::forward<Args>(args)...);
49+
}
50+
#endif // __cpp_lib_invoke
51+
52+
} // namespace mstd
53+
54+
namespace mstd {
55+
using std::reference_wrapper;
56+
using std::ref;
57+
using std::cref;
58+
using std::plus;
59+
using std::minus;
60+
using std::multiplies;
61+
using std::divides;
62+
using std::modulus;
63+
using std::negate;
64+
using std::equal_to;
65+
using std::not_equal_to;
66+
using std::greater;
67+
using std::less;
68+
using std::greater_equal;
69+
using std::less_equal;
70+
using std::logical_and;
71+
using std::logical_or;
72+
using std::logical_not;
73+
using std::bit_and;
74+
using std::bit_or;
75+
using std::bit_xor;
76+
using std::bit_not;
77+
78+
#if __cpp_lib_not_fn >= 201603
79+
using std::not_fn;
80+
#else
81+
namespace impl {
82+
// [func.not_fn]
83+
template <typename F>
84+
class not_fn_t {
85+
std::decay_t<F> fn;
86+
public:
87+
explicit not_fn_t(F&& f) : fn(std::forward<F>(f)) { }
88+
not_fn_t(const not_fn_t &other) = default;
89+
not_fn_t(not_fn_t &&other) = default;
90+
91+
template<typename... Args>
92+
auto operator()(Args&&... args) & -> decltype(!std::declval<invoke_result_t<std::decay_t<F> &, Args...>>())
93+
{
94+
return !mstd::invoke(fn, std::forward<Args>(args)...);
95+
}
96+
97+
template<typename... Args>
98+
auto operator()(Args&&... args) const & -> decltype(!std::declval<invoke_result_t<std::decay_t<F> const &, Args...>>())
99+
{
100+
return !mstd::invoke(fn, std::forward<Args>(args)...);
101+
}
102+
103+
template<typename... Args>
104+
auto operator()(Args&&... args) && -> decltype(!std::declval<invoke_result_t<std::decay_t<F>, Args...>>())
105+
{
106+
return !mstd::invoke(std::move(fn), std::forward<Args>(args)...);
107+
}
108+
109+
template<typename... Args>
110+
auto operator()(Args&&... args) const && -> decltype(!std::declval<invoke_result_t<std::decay_t<F> const, Args...>>())
111+
{
112+
return !mstd::invoke(std::move(fn), std::forward<Args>(args)...);
113+
}
114+
};
115+
}
116+
117+
template <typename F>
118+
impl::not_fn_t<F> not_fn_t(F&& f)
119+
{
120+
return impl::not_fn_t<F>(std::forward<F>(f));
121+
}
122+
#endif
123+
}
124+
125+
#endif // MSTD_FUNCTIONAL_

0 commit comments

Comments
 (0)