Commit d5986bf0 authored by Philipp Unterbrunner's avatar Philipp Unterbrunner Committed by Facebook Github Bot

back_emplace_iterator and related classes and utility functions

Summary:
C++ up to and including C++17 lacks an alternative to std::back_inserter() that uses emplace_back() instead of push_back(). This causes unnecessary temporary objects in some cases, when using std::back_inserter() together with STL functions such as std::copy() or std::transform(). The same holds for std::front_inserter() and std::inserter().
This diff introduces folly::back_emplacer(), folly::front_emplacer(), folly::emplacer(), and related iterator classes, which call emplace_back(), emplace_front(), and emplace() respectively, with perfect forwarding of any arguments to the output iterator's operator=.
Includes support for variadic emplacement / multi-argument constructors through a utility function folly::make_emplace_args() which packs its arguments into a special tuple for use with operator=.

Reviewed By: ericniebler

Differential Revision: D4897174

fbshipit-source-id: c85c30c457e0c946938051819baa662d1a0b8ca1
parent f34acf2c
This diff is collapsed.
......@@ -272,6 +272,7 @@ nobase_follyinclude_HEADERS = \
io/async/test/TimeUtil.h \
io/async/test/UndelayedDestruction.h \
io/async/test/Util.h \
Iterator.h \
json.h \
Lazy.h \
LifoSem.h \
......
This diff is collapsed.
......@@ -332,4 +332,8 @@ utility_test_SOURCES = UtilityTest.cpp
utility_test_LDADD = libfollytestmain.la
TESTS += utility_test
iterator_test_SOURCES = IteratorTest.cpp
iterator_test_LDADD = libfollytestmain.la
TESTS += iterator_test
check_PROGRAMS += $(TESTS)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment