Skip to content

Commit

Permalink
Fix autovector::emplace_back return type for C++17 (facebook#10542)
Browse files Browse the repository at this point in the history
Summary:
C++17 changes emplace_back API to return the new object. Needed to compile rocksdb on recent compilers.

Pull Request resolved: facebook#10542

Reviewed By: hx235

Differential Revision: D38896019

Pulled By: ajkr

fbshipit-source-id: cd7ddf34c0dcd449ecedc41e89a37b3a270a5603
  • Loading branch information
uptycs-rmack authored and facebook-github-bot committed Aug 23, 2022
1 parent 9593fd1 commit 06f73d2
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions util/autovector.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,16 @@ class autovector {
}

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) {
if (num_stack_items_ < kSize) {
new ((void*)(&values_[num_stack_items_++]))
Expand All @@ -307,6 +317,8 @@ class autovector {
vect_.emplace_back(std::forward<Args>(args)...);
}
}
#endif


void pop_back() {
assert(!empty());
Expand Down

0 comments on commit 06f73d2

Please sign in to comment.