[glom] C++11: Encoding: Use a lambda instead of a predicate object with std::find_if.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] C++11: Encoding: Use a lambda instead of a predicate object with std::find_if.
- Date: Mon, 20 Jul 2015 21:07:54 +0000 (UTC)
commit 259356473c68f2b1a2c266bfcef62f50c139396d
Author: Murray Cumming <murrayc murrayc com>
Date: Mon Jul 20 14:06:18 2015 +0200
C++11: Encoding: Use a lambda instead of a predicate object with std::find_if.
glom/import_csv/file_encodings.cc | 32 +++++---------------------------
1 files changed, 5 insertions(+), 27 deletions(-)
---
diff --git a/glom/import_csv/file_encodings.cc b/glom/import_csv/file_encodings.cc
index 52ca85d..d079f93 100644
--- a/glom/import_csv/file_encodings.cc
+++ b/glom/import_csv/file_encodings.cc
@@ -51,31 +51,6 @@ Glib::ustring Encoding::get_name() const
return Glib::ustring();
}
-/** A predicate for use with std::find_if() to find an Encoding with the charset.
- */
-template<class T_Element>
-class predicate_EncodingHasCharset
-{
-public:
- predicate_EncodingHasCharset(const Glib::ustring& charset)
- {
- m_charset = charset;
- }
-
- virtual ~predicate_EncodingHasCharset()
- {
- }
-
- bool operator() (const T_Element& element)
- {
- return (element.get_charset() == m_charset);
- }
-
-private:
- Glib::ustring m_charset;
-};
-
-
static type_list_encodings list_encodings;
static void add_encoding(const gchar* name, const gchar* encoding)
@@ -134,8 +109,11 @@ Glib::ustring get_name_of_charset(const Glib::ustring& charset)
get_list_of_encodings();
type_list_encodings::const_iterator iter =
- std::find_if(list_encodings.begin(), list_encodings.end(),
- predicate_EncodingHasCharset<Encoding>(charset));
+ std::find_if(list_encodings.begin(), list_encodings.end(),
+ [charset](const Encoding& encoding) {
+ return encoding.get_charset() == charset;
+ }
+ );
if(iter != list_encodings.end())
return iter->get_name();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]