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.
17 #ifndef FOLLY_BASE_CONTAINER_TRAITS_H_
18 #define FOLLY_BASE_CONTAINER_TRAITS_H_
20 #include <folly/Traits.h>
24 FOLLY_CREATE_HAS_MEMBER_FN_TRAITS(container_emplace_back_traits, emplace_back);
26 template <class Container, typename... Args>
28 typename std::enable_if<
29 container_emplace_back_traits<Container, void(Args...)>::value>::type
30 container_emplace_back_or_push_back(Container& container, Args&&... args) {
31 container.emplace_back(std::forward<Args>(args)...);
34 template <class Container, typename... Args>
36 typename std::enable_if<
37 !container_emplace_back_traits<Container, void(Args...)>::value>::type
38 container_emplace_back_or_push_back(Container& container, Args&&... args) {
39 using v = typename Container::value_type;
40 container.push_back(v(std::forward<Args>(args)...));