forked from boostorg/unordered
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 =
|
using iter_to_alloc_t =
|
||||||
typename std::pair<iter_key_t<T> const, iter_val_t<T> >;
|
typename std::pair<iter_key_t<T> const, iter_val_t<T> >;
|
||||||
#endif
|
#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 detail
|
||||||
} // namespace unordered
|
} // namespace unordered
|
||||||
} // namespace boost
|
} // namespace boost
|
||||||
|
@ -198,7 +198,7 @@ namespace boost {
|
|||||||
template <class... Args> std::pair<iterator, bool> emplace(Args&&... args)
|
template <class... Args> std::pair<iterator, bool> emplace(Args&&... args)
|
||||||
{
|
{
|
||||||
return table_.emplace_unique(
|
return table_.emplace_unique(
|
||||||
table::extractor::extract(std::forward<Args>(args)...),
|
table::extractor::extract(detail::as_const(args)...),
|
||||||
std::forward<Args>(args)...);
|
std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,7 +206,7 @@ namespace boost {
|
|||||||
iterator emplace_hint(const_iterator hint, Args&&... args)
|
iterator emplace_hint(const_iterator hint, Args&&... args)
|
||||||
{
|
{
|
||||||
return table_.emplace_hint_unique(hint,
|
return table_.emplace_hint_unique(hint,
|
||||||
table::extractor::extract(std::forward<Args>(args)...),
|
table::extractor::extract(detail::as_const(args)...),
|
||||||
std::forward<Args>(args)...);
|
std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,7 +194,7 @@ namespace boost {
|
|||||||
template <class... Args> std::pair<iterator, bool> emplace(Args&&... args)
|
template <class... Args> std::pair<iterator, bool> emplace(Args&&... args)
|
||||||
{
|
{
|
||||||
return table_.emplace_unique(
|
return table_.emplace_unique(
|
||||||
table::extractor::extract(std::forward<Args>(args)...),
|
table::extractor::extract(detail::as_const(args)...),
|
||||||
std::forward<Args>(args)...);
|
std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,7 +202,7 @@ namespace boost {
|
|||||||
iterator emplace_hint(const_iterator hint, Args&&... args)
|
iterator emplace_hint(const_iterator hint, Args&&... args)
|
||||||
{
|
{
|
||||||
return table_.emplace_hint_unique(hint,
|
return table_.emplace_hint_unique(hint,
|
||||||
table::extractor::extract(std::forward<Args>(args)...),
|
table::extractor::extract(detail::as_const(args)...),
|
||||||
std::forward<Args>(args)...);
|
std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user