2017-01-11 Jonathan Wakely <jwakely@redhat.com>
+ PR libstdc++/78134
+ * include/bits/stl_map.h (map::lower_bound, map::upper_bound)
+ (map::equal_range): Fix return type of heterogeneous overloads.
+ * include/bits/stl_multimap.h (multimap::lower_bound)
+ (multimap::upper_bound, multimap::equal_range): Likewise.
+ * include/bits/stl_multiset.h (multiset::lower_bound)
+ (multiset::upper_bound, multiset::equal_range): Likewise.
+ * include/bits/stl_set.h (set::lower_bound, set::upper_bound)
+ (set::equal_range): Likewise.
+ * testsuite/23_containers/map/operations/2.cc
+ * testsuite/23_containers/multimap/operations/2.cc
+ * testsuite/23_containers/multiset/operations/2.cc
+ * testsuite/23_containers/set/operations/2.cc
+
PR libstdc++/78273
* include/bits/stl_map.h (map::count<_Kt>(const _Kt&)): Don't assume
the heterogeneous comparison can only find one match.
template<typename _Kt>
auto
lower_bound(const _Kt& __x)
- -> decltype(_M_t._M_lower_bound_tr(__x))
- { return _M_t._M_lower_bound_tr(__x); }
+ -> decltype(iterator(_M_t._M_lower_bound_tr(__x)))
+ { return iterator(_M_t._M_lower_bound_tr(__x)); }
#endif
//@}
template<typename _Kt>
auto
lower_bound(const _Kt& __x) const
- -> decltype(_M_t._M_lower_bound_tr(__x))
- { return _M_t._M_lower_bound_tr(__x); }
+ -> decltype(const_iterator(_M_t._M_lower_bound_tr(__x)))
+ { return const_iterator(_M_t._M_lower_bound_tr(__x)); }
#endif
//@}
template<typename _Kt>
auto
upper_bound(const _Kt& __x)
- -> decltype(_M_t._M_upper_bound_tr(__x))
- { return _M_t._M_upper_bound_tr(__x); }
+ -> decltype(iterator(_M_t._M_upper_bound_tr(__x)))
+ { return iterator(_M_t._M_upper_bound_tr(__x)); }
#endif
//@}
template<typename _Kt>
auto
upper_bound(const _Kt& __x) const
- -> decltype(_M_t._M_upper_bound_tr(__x))
- { return _M_t._M_upper_bound_tr(__x); }
+ -> decltype(const_iterator(_M_t._M_upper_bound_tr(__x)))
+ { return const_iterator(_M_t._M_upper_bound_tr(__x)); }
#endif
//@}
template<typename _Kt>
auto
equal_range(const _Kt& __x)
- -> decltype(_M_t._M_equal_range_tr(__x))
- { return _M_t._M_equal_range_tr(__x); }
+ -> decltype(pair<iterator, iterator>(_M_t._M_equal_range_tr(__x)))
+ { return pair<iterator, iterator>(_M_t._M_equal_range_tr(__x)); }
#endif
//@}
template<typename _Kt>
auto
equal_range(const _Kt& __x) const
- -> decltype(_M_t._M_equal_range_tr(__x))
- { return _M_t._M_equal_range_tr(__x); }
+ -> decltype(pair<const_iterator, const_iterator>(
+ _M_t._M_equal_range_tr(__x)))
+ {
+ return pair<const_iterator, const_iterator>(
+ _M_t._M_equal_range_tr(__x));
+ }
#endif
//@}
template<typename _Kt>
auto
lower_bound(const _Kt& __x)
- -> decltype(_M_t._M_lower_bound_tr(__x))
- { return _M_t._M_lower_bound_tr(__x); }
+ -> decltype(iterator(_M_t._M_lower_bound_tr(__x)))
+ { return iterator(_M_t._M_lower_bound_tr(__x)); }
#endif
//@}
template<typename _Kt>
auto
lower_bound(const _Kt& __x) const
- -> decltype(_M_t._M_lower_bound_tr(__x))
- { return _M_t._M_lower_bound_tr(__x); }
+ -> decltype(const_iterator(_M_t._M_lower_bound_tr(__x)))
+ { return const_iterator(_M_t._M_lower_bound_tr(__x)); }
#endif
//@}
template<typename _Kt>
auto
upper_bound(const _Kt& __x)
- -> decltype(_M_t._M_upper_bound_tr(__x))
- { return _M_t._M_upper_bound_tr(__x); }
+ -> decltype(iterator(_M_t._M_upper_bound_tr(__x)))
+ { return iterator(_M_t._M_upper_bound_tr(__x)); }
#endif
//@}
template<typename _Kt>
auto
upper_bound(const _Kt& __x) const
- -> decltype(_M_t._M_upper_bound_tr(__x))
- { return _M_t._M_upper_bound_tr(__x); }
+ -> decltype(const_iterator(_M_t._M_upper_bound_tr(__x)))
+ { return const_iterator(_M_t._M_upper_bound_tr(__x)); }
#endif
//@}
template<typename _Kt>
auto
equal_range(const _Kt& __x)
- -> decltype(_M_t._M_equal_range_tr(__x))
- { return _M_t._M_equal_range_tr(__x); }
+ -> decltype(pair<iterator, iterator>(_M_t._M_equal_range_tr(__x)))
+ { return pair<iterator, iterator>(_M_t._M_equal_range_tr(__x)); }
#endif
//@}
template<typename _Kt>
auto
equal_range(const _Kt& __x) const
- -> decltype(_M_t._M_equal_range_tr(__x))
- { return _M_t._M_equal_range_tr(__x); }
+ -> decltype(pair<const_iterator, const_iterator>(
+ _M_t._M_equal_range_tr(__x)))
+ {
+ return pair<const_iterator, const_iterator>(
+ _M_t._M_equal_range_tr(__x));
+ }
#endif
//@}
template<typename _Kt>
auto
lower_bound(const _Kt& __x)
- -> decltype(_M_t._M_lower_bound_tr(__x))
- { return _M_t._M_lower_bound_tr(__x); }
+ -> decltype(iterator(_M_t._M_lower_bound_tr(__x)))
+ { return iterator(_M_t._M_lower_bound_tr(__x)); }
template<typename _Kt>
auto
lower_bound(const _Kt& __x) const
- -> decltype(_M_t._M_lower_bound_tr(__x))
- { return _M_t._M_lower_bound_tr(__x); }
+ -> decltype(iterator(_M_t._M_lower_bound_tr(__x)))
+ { return iterator(_M_t._M_lower_bound_tr(__x)); }
#endif
//@}
template<typename _Kt>
auto
upper_bound(const _Kt& __x)
- -> decltype(_M_t._M_upper_bound_tr(__x))
- { return _M_t._M_upper_bound_tr(__x); }
+ -> decltype(iterator(_M_t._M_upper_bound_tr(__x)))
+ { return iterator(_M_t._M_upper_bound_tr(__x)); }
template<typename _Kt>
auto
upper_bound(const _Kt& __x) const
- -> decltype(_M_t._M_upper_bound_tr(__x))
- { return _M_t._M_upper_bound_tr(__x); }
+ -> decltype(iterator(_M_t._M_upper_bound_tr(__x)))
+ { return iterator(_M_t._M_upper_bound_tr(__x)); }
#endif
//@}
template<typename _Kt>
auto
equal_range(const _Kt& __x)
- -> decltype(_M_t._M_equal_range_tr(__x))
- { return _M_t._M_equal_range_tr(__x); }
+ -> decltype(pair<iterator, iterator>(_M_t._M_equal_range_tr(__x)))
+ { return pair<iterator, iterator>(_M_t._M_equal_range_tr(__x)); }
template<typename _Kt>
auto
equal_range(const _Kt& __x) const
- -> decltype(_M_t._M_equal_range_tr(__x))
- { return _M_t._M_equal_range_tr(__x); }
+ -> decltype(pair<iterator, iterator>(_M_t._M_equal_range_tr(__x)))
+ { return pair<iterator, iterator>(_M_t._M_equal_range_tr(__x)); }
#endif
//@}
template<typename _Kt>
auto
lower_bound(const _Kt& __x)
- -> decltype(_M_t._M_lower_bound_tr(__x))
- { return _M_t._M_lower_bound_tr(__x); }
+ -> decltype(iterator(_M_t._M_lower_bound_tr(__x)))
+ { return iterator(_M_t._M_lower_bound_tr(__x)); }
template<typename _Kt>
auto
lower_bound(const _Kt& __x) const
- -> decltype(_M_t._M_lower_bound_tr(__x))
- { return _M_t._M_lower_bound_tr(__x); }
+ -> decltype(const_iterator(_M_t._M_lower_bound_tr(__x)))
+ { return const_iterator(_M_t._M_lower_bound_tr(__x)); }
#endif
//@}
template<typename _Kt>
auto
upper_bound(const _Kt& __x)
- -> decltype(_M_t._M_upper_bound_tr(__x))
- { return _M_t._M_upper_bound_tr(__x); }
+ -> decltype(iterator(_M_t._M_upper_bound_tr(__x)))
+ { return iterator(_M_t._M_upper_bound_tr(__x)); }
template<typename _Kt>
auto
upper_bound(const _Kt& __x) const
- -> decltype(_M_t._M_upper_bound_tr(__x))
- { return _M_t._M_upper_bound_tr(__x); }
+ -> decltype(iterator(_M_t._M_upper_bound_tr(__x)))
+ { return const_iterator(_M_t._M_upper_bound_tr(__x)); }
#endif
//@}
template<typename _Kt>
auto
equal_range(const _Kt& __x)
- -> decltype(_M_t._M_equal_range_tr(__x))
- { return _M_t._M_equal_range_tr(__x); }
+ -> decltype(pair<iterator, iterator>(_M_t._M_equal_range_tr(__x)))
+ { return pair<iterator, iterator>(_M_t._M_equal_range_tr(__x)); }
template<typename _Kt>
auto
equal_range(const _Kt& __x) const
- -> decltype(_M_t._M_equal_range_tr(__x))
- { return _M_t._M_equal_range_tr(__x); }
+ -> decltype(pair<iterator, iterator>(_M_t._M_equal_range_tr(__x)))
+ { return pair<iterator, iterator>(_M_t._M_equal_range_tr(__x)); }
#endif
//@}
cit = cx.find(2L);
VERIFY( cit == cx.end() );
- VERIFY( Cmp::count == 0);
+ VERIFY( Cmp::count == 0 );
static_assert(std::is_same<decltype(it), test_type::iterator>::value,
"find returns iterator");
cn = cx.count(2L);
VERIFY( cn == 0 );
- VERIFY( Cmp::count == 0);
+ VERIFY( Cmp::count == 0 );
}
void
cit = cx.lower_bound(2L);
VERIFY( cit != cx.end() && cit->second == '4' );
- VERIFY( Cmp::count == 0);
+ VERIFY( Cmp::count == 0 );
+
+ static_assert(std::is_same<decltype(it), test_type::iterator>::value,
+ "lower_bound returns iterator");
+ static_assert(std::is_same<decltype(cit), test_type::const_iterator>::value,
+ "const lower_bound returns const_iterator");
}
void
cit = cx.upper_bound(3L);
VERIFY( cit == cx.end() );
- VERIFY( Cmp::count == 0);
+ VERIFY( Cmp::count == 0 );
+
+ static_assert(std::is_same<decltype(it), test_type::iterator>::value,
+ "upper_bound returns iterator");
+ static_assert(std::is_same<decltype(cit), test_type::const_iterator>::value,
+ "const upper_bound returns const_iterator");
}
void
cit = cx.equal_range(2L);
VERIFY( cit.first == cit.second && cit.first != cx.end() );
- VERIFY( Cmp::count == 0);
+ VERIFY( Cmp::count == 0 );
+
+ using pair = std::pair<test_type::iterator, test_type::iterator>;
+ static_assert(std::is_same<decltype(it), pair>::value,
+ "equal_range returns pair<iterator, iterator>");
+ using cpair = std::pair<test_type::const_iterator, test_type::const_iterator>;
+ static_assert(std::is_same<decltype(cit), cpair>::value,
+ "const equal_range returns pair<const_iterator, const_iterator>");
}
void
cit = cx.find(2L);
VERIFY( cit == cx.end() );
- VERIFY( Cmp::count == 0);
+ VERIFY( Cmp::count == 0 );
static_assert(std::is_same<decltype(it), test_type::iterator>::value,
"find returns iterator");
cn = cx.count(2L);
VERIFY( cn == 0 );
- VERIFY( Cmp::count == 0);
+ VERIFY( Cmp::count == 0 );
}
void
cit = cx.lower_bound(2L);
VERIFY( cit != cx.end() && cit->second == '4' );
- VERIFY( Cmp::count == 0);
+ VERIFY( Cmp::count == 0 );
+
+ static_assert(std::is_same<decltype(it), test_type::iterator>::value,
+ "lower_bound returns iterator");
+ static_assert(std::is_same<decltype(cit), test_type::const_iterator>::value,
+ "const lower_bound returns const_iterator");
}
void
cit = cx.upper_bound(3L);
VERIFY( cit == cx.end() );
- VERIFY( Cmp::count == 0);
+ VERIFY( Cmp::count == 0 );
+
+ static_assert(std::is_same<decltype(it), test_type::iterator>::value,
+ "upper_bound returns iterator");
+ static_assert(std::is_same<decltype(cit), test_type::const_iterator>::value,
+ "const upper_bound returns const_iterator");
}
void
cit = cx.equal_range(2L);
VERIFY( cit.first == cit.second && cit.first != cx.end() );
- VERIFY( Cmp::count == 0);
+ VERIFY( Cmp::count == 0 );
+
+ using pair = std::pair<test_type::iterator, test_type::iterator>;
+ static_assert(std::is_same<decltype(it), pair>::value,
+ "equal_range returns pair<iterator, iterator>");
+ using cpair = std::pair<test_type::const_iterator, test_type::const_iterator>;
+ static_assert(std::is_same<decltype(cit), cpair>::value,
+ "const equal_range returns pair<const_iterator, const_iterator>");
}
cit = cx.find(2L);
VERIFY( cit == cx.end() );
- VERIFY( Cmp::count == 0);
+ VERIFY( Cmp::count == 0 );
static_assert(std::is_same<decltype(it), test_type::iterator>::value,
"find returns iterator");
cn = cx.count(2L);
VERIFY( cn == 0 );
- VERIFY( Cmp::count == 0);
+ VERIFY( Cmp::count == 0 );
}
void
cit = cx.lower_bound(2L);
VERIFY( cit != cx.end() && *cit == 3 );
- VERIFY( Cmp::count == 0);
+ VERIFY( Cmp::count == 0 );
+
+ static_assert(std::is_same<decltype(it), test_type::iterator>::value,
+ "lower_bound returns iterator");
+ static_assert(std::is_same<decltype(cit), test_type::const_iterator>::value,
+ "const lower_bound returns const_iterator");
}
void
cit = cx.upper_bound(5L);
VERIFY( cit == cx.end() );
- VERIFY( Cmp::count == 0);
+ VERIFY( Cmp::count == 0 );
+
+ static_assert(std::is_same<decltype(it), test_type::iterator>::value,
+ "upper_bound returns iterator");
+ static_assert(std::is_same<decltype(cit), test_type::const_iterator>::value,
+ "const upper_bound returns const_iterator");
}
void
cit = cx.equal_range(2L);
VERIFY( cit.first == cit.second && cit.first != cx.end() );
- VERIFY( Cmp::count == 0);
+ VERIFY( Cmp::count == 0 );
+
+ using pair = std::pair<test_type::iterator, test_type::iterator>;
+ static_assert(std::is_same<decltype(it), pair>::value,
+ "equal_range returns pair<iterator, iterator>");
+ using cpair = std::pair<test_type::const_iterator, test_type::const_iterator>;
+ static_assert(std::is_same<decltype(cit), cpair>::value,
+ "const equal_range returns pair<const_iterator, const_iterator>");
}
cit = cx.find(2L);
VERIFY( cit == cx.end() );
- VERIFY( Cmp::count == 0);
+ VERIFY( Cmp::count == 0 );
static_assert(std::is_same<decltype(it), test_type::iterator>::value,
"find returns iterator");
cn = cx.count(2L);
VERIFY( cn == 0 );
- VERIFY( Cmp::count == 0);
+ VERIFY( Cmp::count == 0 );
}
void
cit = cx.lower_bound(2L);
VERIFY( cit != cx.end() && *cit == 3 );
- VERIFY( Cmp::count == 0);
+ VERIFY( Cmp::count == 0 );
+
+ static_assert(std::is_same<decltype(it), test_type::iterator>::value,
+ "lower_bound returns iterator");
+ static_assert(std::is_same<decltype(cit), test_type::const_iterator>::value,
+ "const lower_bound returns const_iterator");
}
void
cit = cx.upper_bound(5L);
VERIFY( cit == cx.end() );
- VERIFY( Cmp::count == 0);
+ VERIFY( Cmp::count == 0 );
+
+ static_assert(std::is_same<decltype(it), test_type::iterator>::value,
+ "upper_bound returns iterator");
+ static_assert(std::is_same<decltype(cit), test_type::const_iterator>::value,
+ "const upper_bound returns const_iterator");
}
void
cit = cx.equal_range(2L);
VERIFY( cit.first == cit.second && cit.first != cx.end() );
- VERIFY( Cmp::count == 0);
+ VERIFY( Cmp::count == 0 );
+
+ using pair = std::pair<test_type::iterator, test_type::iterator>;
+ static_assert(std::is_same<decltype(it), pair>::value,
+ "equal_range returns pair<iterator, iterator>");
+ using cpair = std::pair<test_type::const_iterator, test_type::const_iterator>;
+ static_assert(std::is_same<decltype(cit), cpair>::value,
+ "const equal_range returns pair<const_iterator, const_iterator>");
}
void