mirror of
https://github.com/boostorg/unordered.git
synced 2025-07-29 19:07:15 +02:00
Use as_const to remove any possibility of use-after-move (#272)
This commit is contained in:
@ -219,6 +219,17 @@ namespace boost {
|
||||
using iter_to_alloc_t =
|
||||
typename std::pair<iter_key_t<T> const, iter_val_t<T> >;
|
||||
#endif
|
||||
|
||||
#if BOOST_CXX_VERSION < 201703L
|
||||
template <class T>
|
||||
constexpr typename std::add_const<T>::type& as_const(T& t) noexcept
|
||||
{
|
||||
return t;
|
||||
}
|
||||
template <class T> void as_const(const T&&) = delete;
|
||||
#else
|
||||
using std::as_const;
|
||||
#endif
|
||||
} // namespace detail
|
||||
} // namespace unordered
|
||||
} // namespace boost
|
||||
|
@ -198,7 +198,7 @@ namespace boost {
|
||||
template <class... Args> std::pair<iterator, bool> emplace(Args&&... args)
|
||||
{
|
||||
return table_.emplace_unique(
|
||||
table::extractor::extract(std::forward<Args>(args)...),
|
||||
table::extractor::extract(detail::as_const(args)...),
|
||||
std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
@ -206,7 +206,7 @@ namespace boost {
|
||||
iterator emplace_hint(const_iterator hint, Args&&... args)
|
||||
{
|
||||
return table_.emplace_hint_unique(hint,
|
||||
table::extractor::extract(std::forward<Args>(args)...),
|
||||
table::extractor::extract(detail::as_const(args)...),
|
||||
std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
|
@ -194,7 +194,7 @@ namespace boost {
|
||||
template <class... Args> std::pair<iterator, bool> emplace(Args&&... args)
|
||||
{
|
||||
return table_.emplace_unique(
|
||||
table::extractor::extract(std::forward<Args>(args)...),
|
||||
table::extractor::extract(detail::as_const(args)...),
|
||||
std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
@ -202,7 +202,7 @@ namespace boost {
|
||||
iterator emplace_hint(const_iterator hint, Args&&... args)
|
||||
{
|
||||
return table_.emplace_hint_unique(hint,
|
||||
table::extractor::extract(std::forward<Args>(args)...),
|
||||
table::extractor::extract(detail::as_const(args)...),
|
||||
std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user