2 * Copyright 2016 Facebook, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <folly/Traits.h>
23 FOLLY_CREATE_HAS_MEMBER_FN_TRAITS(container_emplace_back_traits, emplace_back);
25 template <class Container, typename... Args>
27 typename std::enable_if<
28 container_emplace_back_traits<Container, void(Args...)>::value>::type
29 container_emplace_back_or_push_back(Container& container, Args&&... args) {
30 container.emplace_back(std::forward<Args>(args)...);
33 template <class Container, typename... Args>
35 typename std::enable_if<
36 !container_emplace_back_traits<Container, void(Args...)>::value>::type
37 container_emplace_back_or_push_back(Container& container, Args&&... args) {
38 using v = typename Container::value_type;
39 container.push_back(v(std::forward<Args>(args)...));