#include <algorithm>
#include <initializer_list>
#include <iterator>
+#include <stdexcept>
+#include <type_traits>
#include <utility>
#include <vector>
+
#include <boost/operators.hpp>
-#include <boost/bind.hpp>
-#include <boost/type_traits/is_same.hpp>
namespace folly {
template<class Iterator>
int distance_if_multipass(Iterator first, Iterator last) {
typedef typename std::iterator_traits<Iterator>::iterator_category categ;
- if (boost::is_same<categ,std::input_iterator_tag>::value)
+ if (std::is_same<categ,std::input_iterator_tag>::value)
return -1;
return std::distance(first, last);
}
typedef std::pair<key_type,mapped_type> value_type;
typedef Compare key_compare;
- struct value_compare
- : std::binary_function<value_type,value_type,bool>
- , private Compare
- {
+ struct value_compare : private Compare {
bool operator()(const value_type& a, const value_type& b) const {
return Compare::operator()(a.first, b.first);
}
}
iterator lower_bound(const key_type& key) {
- return std::lower_bound(begin(), end(), key,
- boost::bind(key_comp(), boost::bind(&value_type::first, _1), _2));
+ auto c = key_comp();
+ auto f = [&](const value_type& a, const key_type& b) {
+ return c(a.first, b);
+ };
+ return std::lower_bound(begin(), end(), key, f);
}
const_iterator lower_bound(const key_type& key) const {
- return std::lower_bound(begin(), end(), key,
- boost::bind(key_comp(), boost::bind(&value_type::first, _1), _2));
+ auto c = key_comp();
+ auto f = [&](const value_type& a, const key_type& b) {
+ return c(a.first, b);
+ };
+ return std::lower_bound(begin(), end(), key, f);
}
iterator upper_bound(const key_type& key) {
- return std::upper_bound(begin(), end(), key,
- boost::bind(key_comp(), _1, boost::bind(&value_type::first, _2)));
+ auto c = key_comp();
+ auto f = [&](const key_type& a, const value_type& b) {
+ return c(a, b.first);
+ };
+ return std::upper_bound(begin(), end(), key, f);
}
const_iterator upper_bound(const key_type& key) const {
- return std::upper_bound(begin(), end(), key,
- boost::bind(key_comp(), _1, boost::bind(&value_type::first, _2)));
+ auto c = key_comp();
+ auto f = [&](const key_type& a, const value_type& b) {
+ return c(a, b.first);
+ };
+ return std::upper_bound(begin(), end(), key, f);
}
std::pair<iterator,iterator> equal_range(const key_type& key) {
// argument types different from the iterator value_type, so we
// have to do this.
iterator low = lower_bound(key);
- iterator high = std::upper_bound(low, end(), key,
- boost::bind(key_comp(), _1, boost::bind(&value_type::first, _2)));
+ auto c = key_comp();
+ auto f = [&](const key_type& a, const value_type& b) {
+ return c(a, b.first);
+ };
+ iterator high = std::upper_bound(low, end(), key, f);
return std::make_pair(low, high);
}