Skip to content

Commit

Permalink
use std::function instead of std::binary_function (#102)
Browse files Browse the repository at this point in the history
* 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 <functional> header

* Fix compatibility issue with Visual Studio 2022
  • Loading branch information
shogo82148 authored Nov 22, 2023
1 parent 9c9f57f commit bd813b7
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions mecab/src/dictionary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Copyright(C) 2004-2006 Nippon Telegraph and Telephone Corporation
#include <fstream>
#include <climits>
#include <functional>
#include "connector.h"
#include "context_id.h"
#include "char_property.h"
Expand Down Expand Up @@ -64,13 +65,29 @@ 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 <typename T1, typename T2>
struct pair_1st_cmp: public std::function<bool(T1, T2)> {
bool operator()(const std::pair<T1, T2> &x1,
const std::pair<T1, T2> &x2) {
return x1.first < x2.first;
}
};
#else
template <typename T1, typename T2>
struct pair_1st_cmp: public std::binary_function<bool, T1, T2> {
bool operator()(const std::pair<T1, T2> &x1,
const std::pair<T1, T2> &x2) {
return x1.first < x2.first;
}
};
#endif
} // namespace

bool Dictionary::open(const char *file, const char *mode) {
Expand Down

0 comments on commit bd813b7

Please sign in to comment.