gpt4 book ai didi

c++ - C++中的Docker线程池端口问题

转载 作者:行者123 更新时间:2023-12-02 10:11:52 24 4
gpt4 key购买 nike

我有一个 c++ 中的线程池程序,可以在 Visual Studio 的 Windows 机器上运行。我对 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 声明为一个类型名,但它仍然存在问题。我唯一能想到的另一件事是我没有引入正确的库。我的 dockerfile 看起来像这样......
# 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"]
任何帮助,将不胜感激。如有必要,我可以发布更多代码!

最佳答案

如果您正在使用
How to check if an arbitrary type is an iterator?
对于您的 is_iterator 方法,您会注意到这些方法检查类型是否是迭代器,而 end 是函数参数。所以编译它你可以去:

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");
请注意,这是多余的,因为 begin 和 end 共享相同的类型。

关于c++ - C++中的Docker线程池端口问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63197675/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com