From bd813b74768b2c6f36a73c5186668e2596a3486a Mon Sep 17 00:00:00 2001 From: ICHINOSE Shogo Date: Thu, 23 Nov 2023 00:42:54 +0900 Subject: [PATCH] use std::function instead of std::binary_function (#102) * use std::function instead of std::binary_function * Add pair_1st_cmp struct for C++11 compatibility * Fix pair_1st_cmp struct inheritance * fix builds on Visual Studio 2022 * Add header * Fix compatibility issue with Visual Studio 2022 --- mecab/src/dictionary.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/mecab/src/dictionary.cpp b/mecab/src/dictionary.cpp index 5c4e945..6f2d76d 100644 --- a/mecab/src/dictionary.cpp +++ b/mecab/src/dictionary.cpp @@ -5,6 +5,7 @@ // Copyright(C) 2004-2006 Nippon Telegraph and Telephone Corporation #include #include +#include #include "connector.h" #include "context_id.h" #include "char_property.h" @@ -64,6 +65,21 @@ int progress_bar_darts(size_t current, size_t total) { return progress_bar("emitting double-array", current, total); } +#if defined(__cplusplus) && __cplusplus >= 201103L +# define HAS_STD_FUNCTION 1 +#else +# define HAS_STD_FUNCTION 0 +#endif + +#if HAS_STD_FUNCTION +template +struct pair_1st_cmp: public std::function { + bool operator()(const std::pair &x1, + const std::pair &x2) { + return x1.first < x2.first; + } +}; +#else template struct pair_1st_cmp: public std::binary_function { bool operator()(const std::pair &x1, @@ -71,6 +87,7 @@ struct pair_1st_cmp: public std::binary_function { return x1.first < x2.first; } }; +#endif } // namespace bool Dictionary::open(const char *file, const char *mode) {