/*
 * Copyright (c) 2015 PLUMgrid, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include <memory>
#include <string>
#include <unistd.h>
#include <vector>

namespace ebpf {

template <class T, class... Args>
typename std::enable_if<!std::is_array<T>::value, std::unique_ptr<T>>::type
make_unique(Args &&... args) {
  return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}

std::vector<int> get_online_cpus();

std::vector<int> get_possible_cpus();

std::string get_pid_exe(pid_t pid);

}  // namespace ebpf

/*
 * Copyright (c) 2015 PLUMgrid, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include <memory>
#include <string>
#include <unistd.h>
#include <vector>

namespace ebpf {

#ifdef __cpp_lib_make_unique
using std::make_unique;
#else
template <class T, class... Args>
typename std::enable_if<!std::is_array<T>::value, std::unique_ptr<T>>::type
make_unique(Args &&... args) {
  return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}
#endif

std::vector<int> get_online_cpus();

std::vector<int> get_possible_cpus();

std::string get_pid_exe(pid_t pid);

}  // namespace ebpf

Use the STL's make_unique if available
Use the STL's make_unique if available

Fixes build errors with GCC7.3.1 + LLVM5.0.1 under Centos.

/bcc/src/cc/frontends/b/loader.cc: In member function 'int ebpf::BLoader::parse(llvm::Module*, const string&, const string&, ebpf::TableStorage&, const string&, const string&)':
/bcc/src/cc/frontends/b/loader.cc:39:63: error: call of overloaded 'make_unique<ebpf::cc::Parser>(const string&)' is ambiguous
   proto_parser_ = make_unique<ebpf::cc::Parser>(proto_filename);
                                                               ^
In file included from /bcc/src/cc/frontends/b/node.h:26:0,
                 from /bcc/src/cc/frontends/b/parser.h:20,
                 from /bcc/src/cc/frontends/b/loader.cc:17:
/bcc/src/cc/common.h:28:1: note: candidate: typename std::enable_if<(! std::is_array< <template-parameter-1-1> >::value), std::unique_ptr<_Tp> >::type e/*
bpf::make_unique(Args&& ...) [with T = ebpf::cc::Parser; Args = {const std::basic_string<char, std::char_traits<char>, std::allocator<char> >&}; typename std::enable_if<(! std::is_array< <template-parameter-1-1> >::value), std::unique_ptr<_Tp> >::type = std::unique_ptr<ebpf::cc::Parser>]
 make_unique(Args &&... args) {
 ^~~~~~~~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/memory:80:0,
                 from /bcc/src/cc/frontends/b/node.h:22,
                 from /bcc/src/cc/frontends/b/parser.h:20,
                 from /bcc/src/cc/frontends/b/loader.cc:17:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/unique_ptr.h:824:5: note: candidate: typename std::_MakeUniq<_Tp>::__single_object std::make_unique(_Args&& ...) [with _Tp = ebpf::cc::Parser; _Args = {const std::basic_string<char, std::char_traits<char>, std::allocator<char> >&}; typename std::_MakeUniq<_Tp>::__single_object = std::unique_ptr<ebpf::cc::Parser>]
     make_unique(_Args&&... __args)
     ^~~~~~~~~~~

Signed-off-by: Kyle Zhang <3c25b01657254677d3e1a8fd1f0742c5d489bd39@smartx.com>
