From 06f73d257565d4758baadef6685586bdb94a9382 Mon Sep 17 00:00:00 2001 From: Ryan Mack Date: Tue, 23 Aug 2022 14:58:16 -0700 Subject: [PATCH] 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 --- util/autovector.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/util/autovector.h b/util/autovector.h index 22c9450d7..3242cb4bd 100644 --- a/util/autovector.h +++ b/util/autovector.h @@ -299,6 +299,16 @@ class autovector { } template +#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)...)); + } else { + return vect_.emplace_back(std::forward(args)...); + } + } +#else void emplace_back(Args&&... args) { if (num_stack_items_ < kSize) { new ((void*)(&values_[num_stack_items_++])) @@ -307,6 +317,8 @@ class autovector { vect_.emplace_back(std::forward(args)...); } } +#endif + void pop_back() { assert(!empty());