[glom/no_raw_loops2: 3/4] Add and use Utils::copy_if().
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom/no_raw_loops2: 3/4] Add and use Utils::copy_if().
- Date: Wed, 10 Feb 2016 14:22:26 +0000 (UTC)
commit bcd487aeec94e65a69a5632d5bfadd87e3a87641
Author: Murray Cumming <murrayc murrayc com>
Date: Wed Feb 10 15:04:36 2016 +0100
Add and use Utils::copy_if().
glom/libglom/algorithms_utils.h | 10 ++++++++++
glom/libglom/privs.cc | 15 ++++++---------
2 files changed, 16 insertions(+), 9 deletions(-)
---
diff --git a/glom/libglom/algorithms_utils.h b/glom/libglom/algorithms_utils.h
index 0a79dbc..bcf2883 100644
--- a/glom/libglom/algorithms_utils.h
+++ b/glom/libglom/algorithms_utils.h
@@ -92,6 +92,16 @@ copy(T_container_input input, T_container_output& output)
std::back_inserter(output));
}
+template<typename T_container_input, typename T_container_output, typename T_callable>
+void
+copy_if(T_container_input input, T_container_output& output, T_callable f)
+{
+ std::copy_if(
+ std::begin(input), std::end(input),
+ std::back_inserter(output),
+ f);
+}
+
} //namespace Utils
} //namespace Glom
diff --git a/glom/libglom/privs.cc b/glom/libglom/privs.cc
index 98c771e..5d6f002 100644
--- a/glom/libglom/privs.cc
+++ b/glom/libglom/privs.cc
@@ -398,16 +398,13 @@ Privs::type_vec_strings Privs::get_groups_of_user(const Glib::ustring& user)
type_vec_strings result;
//Look at each group:
- type_vec_strings groups = get_database_groups();
- for(const auto& group : groups)
- {
- //See whether the user is in this group:
- if(get_user_is_in_group(user, group))
- {
- //Add the group to the result:
- result.emplace_back(group);
+ const auto groups = get_database_groups();
+ Utils::copy_if(groups, result,
+ [&user](const auto& group) {
+ //See whether the user is in this group:
+ return get_user_is_in_group(user, group);
}
- }
+ );
return result;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]