Skip to content
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

Remove _For_each_tuple_element in scoped_lock #760

Merged
merged 5 commits into from
Apr 30, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion stl/inc/mutex
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ public:
}

~scoped_lock() noexcept {
_For_each_tuple_element(_MyMutexes, [](auto& _Mutex) noexcept { _Mutex.unlock(); });
_STD apply([](_Mutexes&... _Mtxes) { (..., (void) _Mtxes.unlock()); }, _MyMutexes);
}

scoped_lock(const scoped_lock&) = delete;
Expand Down
15 changes: 0 additions & 15 deletions stl/inc/tuple
Original file line number Diff line number Diff line change
Expand Up @@ -976,21 +976,6 @@ _NODISCARD constexpr _Ty make_from_tuple(_Tuple&& _Tpl) { // construct _Ty from
}
#endif // _HAS_CXX17

// FUNCTION TEMPLATE _For_each_tuple_element
template <class _Tpl, class _Fx, size_t... _Indices>
void _For_each_tuple_element_impl(
_Tpl&& _Tuple, _Fx _Func, index_sequence<_Indices...>) { // call _Func() on the _Indices elements of _Tuple
int _Ignored[] = {(static_cast<void>(_Func(_STD get<_Indices>(_STD forward<_Tpl>(_Tuple)))), 0)...};
(void) _Ignored;
}

template <class _Tpl, class _Fx>
void _For_each_tuple_element(_Tpl&& _Tuple, _Fx _Func) { // call _Func() on each element in _Tuple
_For_each_tuple_element_impl(
_STD forward<_Tpl>(_Tuple), _Func, make_index_sequence<tuple_size_v<remove_reference_t<_Tpl>>>());
}


#pragma warning(push)
#pragma warning(disable : 4100) // TRANSITION, VSO-181496, unreferenced formal parameter
// TEMPLATE CONSTRUCTOR pair::pair(tuple, tuple, sequence, sequence)
Expand Down
19 changes: 16 additions & 3 deletions tests/std/tests/VSO_0000000_instantiate_containers/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ using namespace std;

int main() {} // COMPILE-ONLY

template <typename Tpl, typename Fx, size_t... Indices>
void for_each_tuple_element_impl(Tpl&& Tuple, Fx Func, index_sequence<Indices...>) {
// call Func() on the Indices elements of Tuple
int ignored[] = {(static_cast<void>(Func(get<Indices>(forward<Tpl>(Tuple)))), 0)...};
(void) ignored;
}

template <typename Tpl, typename Fx>
void for_each_tuple_element(Tpl&& Tuple, Fx Func) { // call Func() on each element in Tuple
for_each_tuple_element_impl(
forward<Tpl>(Tuple), Func, make_index_sequence<tuple_size_v<remove_reference_t<Tpl>>>{});
}

// Use this type to ensure function templates are used instead
// of regular member functions.
template <typename T>
Expand Down Expand Up @@ -121,7 +134,7 @@ template <typename T>
void construct_from_iterators_test(T value) {
auto containers = get_all_iterator_types_for(value);

_For_each_tuple_element(containers, [](auto c) {
for_each_tuple_element(containers, [](auto c) {
T another(begin(c), end(c));
T another2(begin(c), end(c));
});
Expand All @@ -131,7 +144,7 @@ template <typename T>
void construct_tree_containers_from_iterators_test(T value) {
auto containers = get_all_iterator_types_for(value);

_For_each_tuple_element(containers, [&](auto c) {
for_each_tuple_element(containers, [&](auto c) {
T another(begin(c), end(c));
T another2(begin(c), end(c), value.key_comp());
T another3(begin(c), end(c), value.key_comp(), value.get_allocator());
Expand All @@ -142,7 +155,7 @@ template <typename T>
void construct_hash_containers_from_iterators_test(T value) {
auto containers = get_all_iterator_types_for(value);

_For_each_tuple_element(containers, [&](auto c) {
for_each_tuple_element(containers, [&](auto c) {
T another(begin(c), end(c));
T another2(begin(c), end(c), value.bucket_count());
T another3(begin(c), end(c), value.bucket_count(), value.hash_function());
Expand Down