[glom/no_raw_loops2: 2/4] And and use Utils::copy().



commit 6612bdba99ec2604de1c5cef9b4f9723b73c0f76
Author: Murray Cumming <murrayc murrayc com>
Date:   Wed Feb 10 15:02:23 2016 +0100

    And and use Utils::copy().
    
    Doing that just to unconst the members is still awful, but at least
    this is explicit about what we are doing.

 glom/libglom/algorithms_utils.h                   |    8 ++++++++
 glom/libglom/data_structure/layout/layoutgroup.cc |    7 +------
 glom/libglom/utils.cc                             |   10 ++--------
 3 files changed, 11 insertions(+), 14 deletions(-)
---
diff --git a/glom/libglom/algorithms_utils.h b/glom/libglom/algorithms_utils.h
index 5bf9895..0a79dbc 100644
--- a/glom/libglom/algorithms_utils.h
+++ b/glom/libglom/algorithms_utils.h
@@ -83,6 +83,14 @@ add_unique(T_container& container, T_element&& element)
     container.emplace_back(std::forward<T_element>(element));
 }
 
+template<typename T_container_input, typename T_container_output>
+void
+copy(T_container_input input, T_container_output& output)
+{
+  std::copy(
+    std::begin(input), std::end(input),
+    std::back_inserter(output));
+}
 
 } //namespace Utils
 
diff --git a/glom/libglom/data_structure/layout/layoutgroup.cc 
b/glom/libglom/data_structure/layout/layoutgroup.cc
index 61170b5..2407a98 100644
--- a/glom/libglom/data_structure/layout/layoutgroup.cc
+++ b/glom/libglom/data_structure/layout/layoutgroup.cc
@@ -174,12 +174,7 @@ LayoutGroup::type_list_const_items LayoutGroup::get_items() const
   //Get a const map from the non-const map:
   //TODO_Performance: Surely we should not need to copy the structure just to constize it?
   type_list_const_items result;
-
-  for(const auto& item : m_list_items)
-  {
-    result.emplace_back(item);
-  }
-
+  Utils::copy(m_list_items, result);
   return result;
 }
 
diff --git a/glom/libglom/utils.cc b/glom/libglom/utils.cc
index 5e58f56..1bdbcb4 100644
--- a/glom/libglom/utils.cc
+++ b/glom/libglom/utils.cc
@@ -192,10 +192,7 @@ Glib::RefPtr<Gnome::Gda::SqlBuilder> Utils::build_sql_select_with_where_clause(c
 {
   //TODO_Performance:
   type_vecConstLayoutFields constFieldsToGet;
-  for(const auto& field : fieldsToGet)
-  {
-    constFieldsToGet.emplace_back(field);
-  }
+  Utils::copy(fieldsToGet, constFieldsToGet);
 
   return build_sql_select_with_where_clause(table_name, constFieldsToGet, where_clause, extra_join, 
sort_clause, limit);
 }
@@ -450,10 +447,7 @@ Glib::RefPtr<Gnome::Gda::SqlBuilder> Utils::build_sql_select_with_key(const Glib
 {
   //TODO_Performance:
   type_vecConstLayoutFields constFieldsToGet;
-  for(const auto& field : fieldsToGet)
-  {
-    constFieldsToGet.emplace_back(field);
-  }
+  Utils::copy(fieldsToGet, constFieldsToGet);
 
   return build_sql_select_with_key(table_name, constFieldsToGet, key_field, key_value, sort_clause, limit);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]