back_emplace_iterator and related classes and utility functions
authorPhilipp Unterbrunner <philippu@fb.com>
Tue, 9 May 2017 01:37:28 +0000 (18:37 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Tue, 9 May 2017 01:51:37 +0000 (18:51 -0700)
commitd5986bf055513d4ca02b27234afff6a841f9ba00
tree9dd6a9a543ac589e0447f7e8ee9bcfe4b5296dec
parentf34acf2cbdfd496b88611f725852f774290ef234
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
folly/Iterator.h [new file with mode: 0644]
folly/Makefile.am
folly/test/IteratorTest.cpp [new file with mode: 0644]
folly/test/Makefile.am