New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add <mstd_xxx> C++ headers #11039
Add <mstd_xxx> C++ headers #11039
Changes from all commits
e5a3f97
7c849cb
6fc767d
de7e72b
0aab1a9
0bb4c05
da3cd6f
b1c35b7
f27c7ec
85cd3cd
852a626
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* 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 OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#ifndef MSTD_ALGORITHM_ | ||
#define MSTD_ALGORITHM_ | ||
|
||
/* <mstd_algorithm> | ||
* | ||
* - provides <algorithm> | ||
* - For ARM C 5, standard C++11/14 features: | ||
* - std::min, std::max for std::initializer_list | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not have <mstd_initializer_list> for initialiser list ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good general question - for consistency, it would indeed make sense to have |
||
* - std::all_of, std::any_of, std::none_of | ||
* - std::find_if_not | ||
* - std::equal (2-range forms) | ||
* - std::copy_n, std::move, std::move_backward | ||
* - mstd::min, mstd::max constexpr replacements | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How do we get constexpr replacement if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As |
||
*/ | ||
|
||
#include <algorithm> | ||
|
||
namespace mstd { | ||
using std::min; | ||
using std::max; | ||
using std::minmax; | ||
using std::initializer_list; | ||
using std::all_of; | ||
using std::any_of; | ||
using std::none_of; | ||
using std::for_each; | ||
using std::find; | ||
using std::find_if; | ||
using std::find_if_not; | ||
using std::find_end; | ||
using std::find_first_of; | ||
using std::adjacent_find; | ||
using std::count; | ||
using std::count_if; | ||
using std::mismatch; | ||
using std::equal; | ||
using std::search; | ||
using std::search_n; | ||
using std::copy; | ||
using std::copy_n; | ||
using std::copy_if; | ||
using std::move; | ||
using std::move_backward; | ||
using std::swap_ranges; | ||
using std::iter_swap; | ||
using std::transform; | ||
using std::replace; | ||
using std::replace_if; | ||
using std::replace_copy; | ||
using std::replace_copy_if; | ||
using std::fill; | ||
using std::fill_n; | ||
using std::generate; | ||
using std::generate_n; | ||
using std::remove; | ||
using std::remove_if; | ||
using std::remove_copy; | ||
using std::remove_copy_if; | ||
using std::unique; | ||
using std::unique_copy; | ||
using std::reverse; | ||
using std::reverse_copy; | ||
using std::rotate; | ||
using std::rotate_copy; | ||
using std::partition; | ||
using std::stable_partition; | ||
using std::sort; | ||
using std::stable_sort; | ||
using std::partial_sort; | ||
using std::partial_sort_copy; | ||
using std::nth_element; | ||
using std::lower_bound; | ||
using std::upper_bound; | ||
using std::equal_range; | ||
using std::binary_search; | ||
using std::merge; | ||
using std::inplace_merge; | ||
using std::includes; | ||
using std::set_union; | ||
using std::set_intersection; | ||
using std::set_difference; | ||
using std::set_symmetric_difference; | ||
using std::push_heap; | ||
using std::pop_heap; | ||
using std::make_heap; | ||
using std::sort_heap; | ||
using std::min_element; | ||
using std::max_element; | ||
using std::lexicographical_compare; | ||
using std::next_permutation; | ||
using std::prev_permutation; | ||
} | ||
|
||
#endif // MSTD_ALGORITHM_ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright (c) 2017 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 OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef MSTD_ATOMIC_ | ||
#define MSTD_ATOMIC_ | ||
|
||
#include <atomic> | ||
|
||
namespace mstd { | ||
using std::atomic; | ||
using std::atomic_is_lock_free; | ||
using std::atomic_store; | ||
using std::atomic_store_explicit; | ||
using std::atomic_load; | ||
using std::atomic_load_explicit; | ||
using std::atomic_exchange; | ||
using std::atomic_exchange_explicit; | ||
using std::atomic_compare_exchange_weak; | ||
using std::atomic_compare_exchange_weak_explicit; | ||
using std::atomic_compare_exchange_strong; | ||
using std::atomic_compare_exchange_strong_explicit; | ||
using std::atomic_fetch_add; | ||
using std::atomic_fetch_add_explicit; | ||
using std::atomic_fetch_sub; | ||
using std::atomic_fetch_sub_explicit; | ||
using std::atomic_fetch_and; | ||
using std::atomic_fetch_and_explicit; | ||
using std::atomic_fetch_or; | ||
using std::atomic_fetch_or_explicit; | ||
using std::atomic_fetch_xor; | ||
using std::atomic_fetch_xor_explicit; | ||
using std::atomic_flag; | ||
using std::atomic_flag_test_and_set; | ||
using std::atomic_flag_test_and_set_explicit; | ||
using std::atomic_flag_clear; | ||
using std::atomic_flag_clear_explicit; | ||
using std::atomic_init; | ||
using std::memory_order; | ||
using std::kill_dependency; | ||
using std::atomic_thread_fence; | ||
using std::atomic_signal_fence; | ||
} | ||
|
||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* 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 OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#ifndef MSTD_CSTDDEF_ | ||
#define MSTD_CSTDDEF_ | ||
|
||
/* <mstd_cstddef> | ||
* | ||
* - provides <cstddef> | ||
* - For ARM C 5, standard C++11/14 features: | ||
* - - adds macro replacements for alignof and alignas keywords | ||
* - - adds missing std::nullptr_t | ||
* - For all toolchains: | ||
* - - MSTD_CONSTEXPR_XX_14 macros that can be used to mark | ||
* things that are valid as constexpr only for C++14 or later, | ||
* permitting constexpr use where ARM C 5 would reject it. | ||
*/ | ||
|
||
#include <cstddef> | ||
|
||
/* Macros that can be used to mark functions and objects that are | ||
* constexpr in C++14 or later, but not in earlier versions. | ||
*/ | ||
#if __cplusplus >= 201402 | ||
#define MSTD_CONSTEXPR_FN_14 constexpr | ||
#define MSTD_CONSTEXPR_OBJ_14 constexpr | ||
#else | ||
#define MSTD_CONSTEXPR_FN_14 inline | ||
#define MSTD_CONSTEXPR_OBJ_14 const | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure to agree with that definition; in C++14 a constexpr object can invoke non const member function in a constexpr context. In C++11; constexpr equals const. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Flipping from constexpr in C++14 to inline in C++11 seems right to me - either member or non-member. Or were you misunderstanding
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking of the following case: struct Foo {
constexpr Foo() { }
// not a const member function!
MSTD_CONSTEXPR_FN_14 int get_something() { /* ... */ }
};
static MSTD_CONSTEXPR_OBJ_14 Foo foo;
void foo() {
// error call of a non const function on a const object
auto v = foo.get_something();
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems fine to me? In C++14, the function is In C++11, the function is |
||
#endif | ||
|
||
namespace mstd | ||
{ | ||
using std::size_t; | ||
using std::ptrdiff_t; | ||
using std::nullptr_t; | ||
using std::max_align_t; | ||
|
||
} | ||
|
||
#endif // MSTD_CSTDDEF_ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mbed.h
is included above, so there'susing namespace std
andusing mstd:atomic
that both bringsatomic
in the global namespace.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is actually pulling it into this unnamed namespace.
I previously claimed that a global-scope
using mstd::atomic
would override a more generalusing namespace std
foratomic
, and I'm sure I'd tested this, but seemed not to work here.But putting it into an inner namespace like this does work - it searches innermost namespace first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I somehow missed the anonymous namespace declaration. Good to know.