【问题标题】:Docker threading pool port issue in c++C ++中的Docker线程池端口问题
【发布时间】:2020-11-21 15:29:10
【问题描述】:

我有一个 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"]

任何帮助将不胜感激。如有需要,我可以发布更多代码!

【问题讨论】:

    标签: c++ docker ubuntu g++


    【解决方案1】:

    如果你正在使用

    How to check if an arbitrary type is an iterator?

    对于您的 is_iterator 方法,您会注意到这些方法检查 Type 是否为 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 共享相同的类型。

    【讨论】:

    • 嗯。我将不得不深入研究这一点。答案有效,但我遇到了一个问题,将“结束”作为一个参数。谢谢你的链接,我去看看!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-09-23
    • 1970-01-01
    • 2022-11-03
    • 2017-07-08
    • 2020-10-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多