- #define FOLLY_FBVECTOR_INSERT_PRE(cpos, n) \
- if (n == 0) return (iterator)cpos; \
- bool at_end = cpos == cend(); \
- bool fresh = insert_use_fresh(at_end, n); \
- if (!at_end) { \
- if (!fresh) {
-
- // check for internal data (technically not required by the standard)
-
- #define FOLLY_FBVECTOR_INSERT_START(cpos, n) \
- } \
- assert(isValid(cpos)); \
- } \
- T* position = const_cast<T*>(cpos); \
- size_type idx = std::distance(impl_.b_, position); \
- T* b; \
- size_type newCap; /* intentionally uninitialized */ \
- \
- if (fresh) { \
- newCap = computeInsertCapacity(n); \
- b = M_allocate(newCap); \
- } else { \
- if (!at_end) { \
- make_window(position, n); \
- } else { \
- impl_.e_ += n; \
- } \
- b = impl_.b_; \
- } \
- \
- T* start = b + idx; \
- \
- try { \
-
- // construct the inserted elements
-
- #define FOLLY_FBVECTOR_INSERT_TRY(cpos, n) \
- } catch (...) { \
- if (fresh) { \
- M_deallocate(b, newCap); \
- } else { \
- if (!at_end) { \
- undo_window(position, n); \
- } else { \
- impl_.e_ -= n; \
- } \
- } \
- throw; \
- } \
- \
- if (fresh) { \
- try { \
- wrap_frame(b, idx, n); \
- } catch (...) { \
-
-
- // delete the inserted elements (exception has been thrown)
-
- #define FOLLY_FBVECTOR_INSERT_END(cpos, n) \
- M_deallocate(b, newCap); \
- throw; \
- } \
- if (impl_.b_) M_deallocate(impl_.b_, capacity()); \
- impl_.set(b, size() + n, newCap); \
- return impl_.b_ + idx; \
- } else { \
- return position; \
- } \
+ template <
+ typename IsInternalFunc,
+ typename InsertInternalFunc,
+ typename ConstructFunc,
+ typename DestroyFunc>
+ iterator do_real_insert(
+ const_iterator cpos,
+ size_type n,
+ IsInternalFunc&& isInternalFunc,
+ InsertInternalFunc&& insertInternalFunc,
+ ConstructFunc&& constructFunc,
+ DestroyFunc&& destroyFunc) {
+ if (n == 0) {
+ return iterator(cpos);
+ }
+ bool at_end = cpos == cend();
+ bool fresh = insert_use_fresh(at_end, n);
+ if (!at_end) {
+ if (!fresh && isInternalFunc()) {
+ // check for internal data (technically not required by the standard)
+ return insertInternalFunc();
+ }
+ assert(isValid(cpos));
+ }
+ T* position = const_cast<T*>(cpos);
+ size_type idx = size_type(std::distance(impl_.b_, position));
+ T* b;
+ size_type newCap; /* intentionally uninitialized */