[glibmm] C++11: Use emplace_back() instead of push_back().
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glibmm] C++11: Use emplace_back() instead of push_back().
- Date: Fri, 5 Feb 2016 22:39:55 +0000 (UTC)
commit 1c212efc8e0983a69b29a5cbef7565b13e4ebfa3
Author: Murray Cumming <murrayc murrayc com>
Date: Fri Feb 5 23:28:12 2016 +0100
C++11: Use emplace_back() instead of push_back().
examples/network/resolver.cc | 8 ++++----
gio/src/application.ccg | 6 +++---
glib/glibmm/class.cc | 2 +-
glib/glibmm/containerhandle_shared.h | 2 +-
glib/glibmm/dispatcher.cc | 2 +-
glib/glibmm/interface.cc | 4 ++--
glib/glibmm/property.cc | 6 +++---
glib/glibmm/threadpool.cc | 2 +-
glib/glibmm/wrap.cc | 2 +-
glib/src/miscutils.ccg | 4 ++--
glib/src/optiongroup.ccg | 6 +++---
glib/src/variant.ccg | 6 +++---
glib/src/variant.hg | 2 +-
tests/glibmm_btree/main.cc | 4 ++--
14 files changed, 28 insertions(+), 28 deletions(-)
---
diff --git a/examples/network/resolver.cc b/examples/network/resolver.cc
index 5750479..a4f60bd 100644
--- a/examples/network/resolver.cc
+++ b/examples/network/resolver.cc
@@ -137,9 +137,9 @@ split_service_parts (const Glib::ustring& arg)
delim2 = arg.find ('/', delim1 + 1);
if (delim2 == std::string::npos)
return parts;
- parts.push_back (arg.substr (0, delim1));
- parts.push_back (arg.substr (delim1 + 1, delim2 - delim1 - 1));
- parts.push_back (arg.substr (delim2 + 1));
+ parts.emplace_back (arg.substr (0, delim1));
+ parts.emplace_back (arg.substr (delim1 + 1, delim2 - delim1 - 1));
+ parts.emplace_back (arg.substr (delim2 + 1));
return parts;
}
@@ -210,7 +210,7 @@ start_threaded_lookups (char **argv, int argc)
{
const Glib::ustring arg = argv[i];
const auto thread = new std::thread(&lookup_thread, arg);
- result.push_back(thread);
+ result.emplace_back(thread);
}
return result;
diff --git a/gio/src/application.ccg b/gio/src/application.ccg
index 4c98dd5..d8dd6e2 100644
--- a/gio/src/application.ccg
+++ b/gio/src/application.ccg
@@ -451,11 +451,11 @@ void Application::add_main_option_entry_private(GOptionArg arg, const Glib::ustr
Application_delete_extra_application_data);
}
- extra_application_data->option_entry_strings.push_back(lname);
+ extra_application_data->option_entry_strings.emplace_back(lname);
if (desc)
- extra_application_data->option_entry_strings.push_back(desc);
+ extra_application_data->option_entry_strings.emplace_back(desc);
if (arg_desc)
- extra_application_data->option_entry_strings.push_back(arg_desc);
+ extra_application_data->option_entry_strings.emplace_back(arg_desc);
// Fill in array[0].
array[0].arg = arg;
diff --git a/glib/glibmm/class.cc b/glib/glibmm/class.cc
index bf57f84..bbaf37f 100644
--- a/glib/glibmm/class.cc
+++ b/glib/glibmm/class.cc
@@ -218,7 +218,7 @@ void Class::custom_class_init_function(void* g_class, void* class_data)
GValue* g_value = g_new0(GValue, 1);
g_value_init(g_value, iface_props[p]->value_type);
g_param_value_set_default(iface_props[p], g_value);
- props->push_back(g_value);
+ props->emplace_back(g_value);
g_object_class_override_property(gobject_class, props->size(), prop_name);
}
diff --git a/glib/glibmm/containerhandle_shared.h b/glib/glibmm/containerhandle_shared.h
index d88182d..4d5a552 100644
--- a/glib/glibmm/containerhandle_shared.h
+++ b/glib/glibmm/containerhandle_shared.h
@@ -378,7 +378,7 @@ template <class Cont, class In>
void fill_container(Cont& container, In pbegin, In pend)
{
for(; pbegin != pend; ++pbegin)
- container.push_back(*pbegin);
+ container.emplace_back(*pbegin);
}
#endif /* GLIBMM_HAVE_TEMPLATE_SEQUENCE_CTORS */
diff --git a/glib/glibmm/dispatcher.cc b/glib/glibmm/dispatcher.cc
index 1bbab0e..f0ea19d 100644
--- a/glib/glibmm/dispatcher.cc
+++ b/glib/glibmm/dispatcher.cc
@@ -330,7 +330,7 @@ void DispatchNotifier::send_notification(Dispatcher* dispatcher)
const std::lock_guard<std::mutex> lock (mutex_);
const bool was_empty = notify_queue_.empty();
- notify_queue_.push_back(DispatchNotifyData(dispatcher, this));
+ notify_queue_.emplace_back(DispatchNotifyData(dispatcher, this));
if(was_empty)
{
diff --git a/glib/glibmm/interface.cc b/glib/glibmm/interface.cc
index be04a50..f592d1b 100644
--- a/glib/glibmm/interface.cc
+++ b/glib/glibmm/interface.cc
@@ -81,7 +81,7 @@ Interface::Interface(const Interface_Class& interface_class)
GValue* g_value = g_new0(GValue, 1);
g_value_init(g_value, iface_props[p]->value_type);
g_param_value_set_default(iface_props[p], g_value);
- props->push_back(g_value);
+ props->emplace_back(g_value);
const gchar* prop_name = g_param_spec_get_name(iface_props[p]);
GParamSpec* new_spec = g_param_spec_override(prop_name, iface_props[p]);
@@ -99,7 +99,7 @@ Interface::Interface(const Interface_Class& interface_class)
// The GObject is not instantiated yet. Add to the custom_interface_classes
// and add the interface in the Glib::Object constructor.
std::lock_guard<std::mutex> lock(extra_object_base_data_mutex);
- extra_object_base_data[this].custom_interface_classes.push_back(&interface_class);
+ extra_object_base_data[this].custom_interface_classes.emplace_back(&interface_class);
}
}
}
diff --git a/glib/glibmm/property.cc b/glib/glibmm/property.cc
index 0971e14..302d48a 100644
--- a/glib/glibmm/property.cc
+++ b/glib/glibmm/property.cc
@@ -186,7 +186,7 @@ void custom_set_property_callback(GObject* object, unsigned int property_id,
GValue* g_value = g_new0(GValue, 1);
g_value_init(g_value, G_VALUE_TYPE((*iface_props)[p]));
g_value_copy((*iface_props)[p], g_value);
- obj_iface_props->push_back(g_value);
+ obj_iface_props->emplace_back(g_value);
}
}
@@ -245,7 +245,7 @@ bool PropertyBase::lookup_property(const Glib::ustring& name)
g_assert(G_PARAM_SPEC_VALUE_TYPE(param_spec_) == G_VALUE_TYPE(value_.gobj()));
g_param_spec_ref(param_spec_);
- get_obj_custom_props(object_->gobj())->push_back(this);
+ get_obj_custom_props(object_->gobj())->emplace_back(this);
}
return (param_spec_ != nullptr);
@@ -271,7 +271,7 @@ void PropertyBase::install_property(GParamSpec* param_spec)
auto obj_custom_props = get_obj_custom_props(object_->gobj());
const unsigned int pos_in_obj_custom_props = obj_custom_props->size();
- obj_custom_props->push_back(this);
+ obj_custom_props->emplace_back(this);
// We need to offset by 1 as zero is an invalid property id.
const unsigned int property_id = pos_in_obj_custom_props + iface_props_size + 1;
diff --git a/glib/glibmm/threadpool.cc b/glib/glibmm/threadpool.cc
index f021815..163fb19 100644
--- a/glib/glibmm/threadpool.cc
+++ b/glib/glibmm/threadpool.cc
@@ -58,7 +58,7 @@ sigc::slot<void>* ThreadPool::SlotList::push(const sigc::slot<void>& slot)
{
Threads::Mutex::Lock lock (mutex_);
- list_.push_back(slot);
+ list_.emplace_back(slot);
return &list_.back();
}
diff --git a/glib/glibmm/wrap.cc b/glib/glibmm/wrap.cc
index eebe888..18725a9 100644
--- a/glib/glibmm/wrap.cc
+++ b/glib/glibmm/wrap.cc
@@ -86,7 +86,7 @@ void wrap_register(GType type, WrapNewFunction func)
return;
const guint idx = wrap_func_table->size();
- wrap_func_table->push_back(func);
+ wrap_func_table->emplace_back(func);
// Store the table index in the type's static data.
g_type_set_qdata(type, Glib::quark_, GUINT_TO_POINTER(idx));
diff --git a/glib/src/miscutils.ccg b/glib/src/miscutils.ccg
index 76b539d..c0600a6 100644
--- a/glib/src/miscutils.ccg
+++ b/glib/src/miscutils.ccg
@@ -135,7 +135,7 @@ std::vector<std::string> get_system_data_dirs()
for(const gchar* const * iter = cresult; *iter != nullptr; ++iter)
{
- result.push_back(
+ result.emplace_back(
convert_const_gchar_ptr_to_stdstring(*iter));
}
@@ -152,7 +152,7 @@ std::vector<std::string> get_system_config_dirs()
for(const gchar* const * iter = cresult; *iter != nullptr; ++iter)
{
- result.push_back(
+ result.emplace_back(
convert_const_gchar_ptr_to_stdstring(*iter));
}
diff --git a/glib/src/optiongroup.ccg b/glib/src/optiongroup.ccg
index 0dbba0d..56236e4 100644
--- a/glib/src/optiongroup.ccg
+++ b/glib/src/optiongroup.ccg
@@ -766,7 +766,7 @@ void OptionGroup::CppOptionEntry::convert_c_to_cpp()
//for(Glib::StringArrayHandle::iterator iter = array_handle.begin(); iter != array_handle.end();
++iter)
//{
- // typed_cpp_arg->push_back(*iter);
+ // typed_cpp_arg->emplace_back(*iter);
//}
//So we do this:
@@ -774,7 +774,7 @@ void OptionGroup::CppOptionEntry::convert_c_to_cpp()
char** char_array_next = *typed_arg;
while(*char_array_next)
{
- typed_cpp_arg->push_back(*char_array_next);
+ typed_cpp_arg->emplace_back(*char_array_next);
++char_array_next;
}
}
@@ -793,7 +793,7 @@ void OptionGroup::CppOptionEntry::convert_c_to_cpp()
char** char_array_next = *typed_arg;
while(*char_array_next)
{
- typed_cpp_arg->push_back(*char_array_next);
+ typed_cpp_arg->emplace_back(*char_array_next);
++char_array_next;
}
}
diff --git a/glib/src/variant.ccg b/glib/src/variant.ccg
index a99c17c..aba6902 100644
--- a/glib/src/variant.ccg
+++ b/glib/src/variant.ccg
@@ -175,7 +175,7 @@ VariantContainerBase
VariantContainerBase::create_tuple(const VariantBase& child)
{
std::vector<VariantBase> vec;
- vec.push_back(child);
+ vec.emplace_back(child);
return create_tuple(vec);
}
@@ -492,7 +492,7 @@ type_vec_ustring Variant<type_vec_ustring>::get() const
GVariant* gvariant =
g_variant_get_child_value(const_cast<GVariant*>(gobj()), i);
- result.push_back(Glib::Variant<Glib::ustring>(gvariant).get());
+ result.emplace_back(Glib::Variant<Glib::ustring>(gvariant).get());
}
return result;
@@ -597,7 +597,7 @@ type_vec_string Variant<type_vec_string>::get() const
GVariant* gvariant =
g_variant_get_child_value(const_cast<GVariant*>(gobj()), i);
- result.push_back(Glib::Variant<std::string>(gvariant).get());
+ result.emplace_back(Glib::Variant<std::string>(gvariant).get());
}
return result;
diff --git a/glib/src/variant.hg b/glib/src/variant.hg
index 5f9a440..c73fc8e 100644
--- a/glib/src/variant.hg
+++ b/glib/src/variant.hg
@@ -1137,7 +1137,7 @@ std::vector<T> Variant< std::vector<T> >::get() const
g_variant_get_child_value(const_cast<GVariant*>(gobj()), i);
variant.init(gvariant);
- result.push_back(variant.get());
+ result.emplace_back(variant.get());
}
return result;
diff --git a/tests/glibmm_btree/main.cc b/tests/glibmm_btree/main.cc
index 837b7ae..69566cc 100644
--- a/tests/glibmm_btree/main.cc
+++ b/tests/glibmm_btree/main.cc
@@ -140,9 +140,9 @@ main()
auto ptree = Glib::BalancedTree<type_p_key_value,
type_p_key_value>::create(sigc::ptr_fun(my_p_key_compare));
for (type_key_value::size_type i = 0; i < str.size(); ++i)
- pstr.push_back(new type_key_value(str.substr(i, 1)));
+ pstr.emplace_back(new type_key_value(str.substr(i, 1)));
for (type_key_value::size_type i = 0; i < str2.size(); ++i)
- pstr2.push_back(new type_key_value(str2.substr(i, 1)));
+ pstr2.emplace_back(new type_key_value(str2.substr(i, 1)));
for (type_key_value::size_type i = 0; i < str.size(); ++i)
ptree->insert(pstr[i], pstr[i]);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]