Fix autovector::emplace_back return type for C++17 (#10542)

Summary:
C++17 changes emplace_back API to return the new object. Needed to compile rocksdb on recent compilers.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/10542

Reviewed By: hx235

Differential Revision: D38896019

Pulled By: ajkr

fbshipit-source-id: cd7ddf34c0dcd449ecedc41e89a37b3a270a5603
main
Ryan Mack 2 years ago committed by Facebook GitHub Bot
parent 9593fd1c82
commit 06f73d2575
  1. 12
      util/autovector.h

@ -299,6 +299,16 @@ class autovector {
} }
template <class... Args> template <class... Args>
#if _LIBCPP_STD_VER > 14
reference emplace_back(Args&&... args) {
if (num_stack_items_ < kSize) {
return *(new ((void*)(&values_[num_stack_items_++]))
value_type(std::forward<Args>(args)...));
} else {
return vect_.emplace_back(std::forward<Args>(args)...);
}
}
#else
void emplace_back(Args&&... args) { void emplace_back(Args&&... args) {
if (num_stack_items_ < kSize) { if (num_stack_items_ < kSize) {
new ((void*)(&values_[num_stack_items_++])) new ((void*)(&values_[num_stack_items_++]))
@ -307,6 +317,8 @@ class autovector {
vect_.emplace_back(std::forward<Args>(args)...); vect_.emplace_back(std::forward<Args>(args)...);
} }
} }
#endif
void pop_back() { void pop_back() {
assert(!empty()); assert(!empty());

Loading…
Cancel
Save