Docker c++ 中的线程池端口问题
Docker threading pool port issue in c++
我在 visual studio 的 windows 机器上有一个 C++ 线程池程序。我是 c++ 的新手,从未在基于 linux 的系统上开发过它。我正在尝试使用 ubuntu 和 g++ 在 docker 容器中构建相同的程序。但是,我不断收到以下错误...
threadpool.h: In member function 'void ThreadPool::map(Func&&, Iterator, Iterator)':
threadpool.h:73:33: error: type/value mismatch at argument 1 in template parameter list for 'template<class T, class> struct ThreadPool::is_iterator'
73 | static_assert(!is_iterator<end>::value, "End argument needs to be an iterator");
| ^
threadpool.h:73:33: note: expected a type, got 'end'
如果我没看错,它说 end 需要是一个类型,这个错误是由下面的代码产生的....
template <typename Func, typename Iterator>
inline void map(Func&& f, Iterator begin, Iterator end)
{
static_assert(!is_iterator<Iterator>::value, "Begin argument needs to be an iterator");
static_assert(!is_iterator<end>::value, "End argument needs to be an iterator");
for (auto i = begin; i != end; ++i)
{
push(f, *i);
}
}
我想我将 Iterator 声明为一个类型名,但它仍然有问题。我唯一能想到的另一件事是我没有引入正确的库。我的 docker 文件看起来像这样...
# Get the base Ubuntu image from Docker Hub
FROM ubuntu:latest
# Update apps on the base image
RUN apt-get -y update && apt-get install -y
# Install the Clang compiler
RUN apt-get -y install clang
# Install the G++ Compiler
RUN apt-get install -y g++
# Install Ruby
RUN apt-get install -y ruby
# Install Python
RUN apt-get install -y python
# Copy the current folder which contains C++ source code to the Docker image under /usr/src
COPY . /usr/src/threading
# Specify the working directory
WORKDIR /usr/src/threading
# Use G++ to compile the Test.cpp source file
RUN g++ -o threading threading.cpp -lpthread -std=c++17
# Run the output program from the previous step
CMD ["./threading"]
如有任何帮助,我们将不胜感激。如有必要,我可以 post 更多代码!
如果您正在使用
How to check if an arbitrary type is an iterator?
对于您的 is_iterator 方法,您会注意到这些方法检查类型是否为迭代器,而结束是否为函数参数。所以要编译它你可以去:
static_assert(is_iterator<Iterator>::value, "Begin argument needs to be an iterator");
static_assert(is_iterator<decltype(end)>::value, "End argument needs to be an iterator");
请注意这是多余的,因为开始和结束共享相同的类型。
我在 visual studio 的 windows 机器上有一个 C++ 线程池程序。我是 c++ 的新手,从未在基于 linux 的系统上开发过它。我正在尝试使用 ubuntu 和 g++ 在 docker 容器中构建相同的程序。但是,我不断收到以下错误...
threadpool.h: In member function 'void ThreadPool::map(Func&&, Iterator, Iterator)':
threadpool.h:73:33: error: type/value mismatch at argument 1 in template parameter list for 'template<class T, class> struct ThreadPool::is_iterator'
73 | static_assert(!is_iterator<end>::value, "End argument needs to be an iterator");
| ^
threadpool.h:73:33: note: expected a type, got 'end'
如果我没看错,它说 end 需要是一个类型,这个错误是由下面的代码产生的....
template <typename Func, typename Iterator>
inline void map(Func&& f, Iterator begin, Iterator end)
{
static_assert(!is_iterator<Iterator>::value, "Begin argument needs to be an iterator");
static_assert(!is_iterator<end>::value, "End argument needs to be an iterator");
for (auto i = begin; i != end; ++i)
{
push(f, *i);
}
}
我想我将 Iterator 声明为一个类型名,但它仍然有问题。我唯一能想到的另一件事是我没有引入正确的库。我的 docker 文件看起来像这样...
# Get the base Ubuntu image from Docker Hub
FROM ubuntu:latest
# Update apps on the base image
RUN apt-get -y update && apt-get install -y
# Install the Clang compiler
RUN apt-get -y install clang
# Install the G++ Compiler
RUN apt-get install -y g++
# Install Ruby
RUN apt-get install -y ruby
# Install Python
RUN apt-get install -y python
# Copy the current folder which contains C++ source code to the Docker image under /usr/src
COPY . /usr/src/threading
# Specify the working directory
WORKDIR /usr/src/threading
# Use G++ to compile the Test.cpp source file
RUN g++ -o threading threading.cpp -lpthread -std=c++17
# Run the output program from the previous step
CMD ["./threading"]
如有任何帮助,我们将不胜感激。如有必要,我可以 post 更多代码!
如果您正在使用
How to check if an arbitrary type is an iterator?
对于您的 is_iterator 方法,您会注意到这些方法检查类型是否为迭代器,而结束是否为函数参数。所以要编译它你可以去:
static_assert(is_iterator<Iterator>::value, "Begin argument needs to be an iterator");
static_assert(is_iterator<decltype(end)>::value, "End argument needs to be an iterator");
请注意这是多余的,因为开始和结束共享相同的类型。