小编did*_*dil的帖子

如何将可变参数参数传递给 std::thread?

我想通过包装 C++11 中的 std::thread 类来使用我自己的 Thread 实现,这样我就可以像我想要的那样处理异常。

这是我的包装类:

#include <Types.hpp>
#include <thread>
#include <exception>
#include <functional>

class Thread
{
    private:

        std::exception_ptr exceptionPtr;
        std::thread thread;

    public:

        using Id = std::thread::id;

        using NativeHandleType = std::thread::native_handle_type;

        Thread() noexcept = default;
        Thread(Thread &&t) noexcept :
            exceptionPtr(std::move(t.exceptionPtr)),
            thread(std::move(t.thread))
        {
        }

        Thread &operator =(Thread &&t) noexcept
        {
            exceptionPtr = std::move(t.exceptionPtr);
            thread = std::move(t.thread);
            return *this;
        }

        template<typename Callable, typename... Args>
        Thread(Callable &&f, Args &&... args) :
            exceptionPtr(nullptr),
            thread([&](Callable &&f, Args &&... args)
            {
                try
                {
                    std::once_flag …
Run Code Online (Sandbox Code Playgroud)

c++ multithreading templates c++11 stdthread

5
推荐指数
1
解决办法
1642
查看次数

如何在console.log 中打印最后一个数组项?

我使用 console.log() 将用于调试目的的数组打印到我的 Electron 应用程序中的文件中,但它只显示第一项。是否可以选择打印最后一个项目?

例子:

console.log(data)

代替:

{
  threshold: 60,
  currents: [
      15,  157,  145,   20,   18,   18,  120,  122,   58,   67,
      67,   67,  415,  334,  564, 8603, 9492, 9521, 9403, 8992,
    9369, 8991, 9395, 9415, 9327, 9499, 9320, 8876, 8850, 8846,
    ... 81 more items
  ]
}
Run Code Online (Sandbox Code Playgroud)

有:

{
  threshold: 60,
  currents: [
    ... 81 previous items
    8913, 9409, 9446, 8935, 8869, 9448, 9542, 8875, 9454, 9540,
    8926, 9988, 9390, 9532, 8864, 9503, 9422, 8880, 9428, 9465,
    8896, …
Run Code Online (Sandbox Code Playgroud)

javascript node.js electron

2
推荐指数
1
解决办法
107
查看次数