小编And*_* La的帖子

在[:index]上使用动态索引列出切片

我需要使用负动态索引([: - index])对列表进行切片.这很容易,直到我意识到如果我的动态索引的值为0,则没有返回任何项目,而是返回整个列表.我怎样才能以索引为0的方式实现它,它返回整个字符串?我的代码很长很复杂,但基本上这个例子显示了问题:

    arr='test text'
    index=2
    print arr[:-index]
    >>'test te'    #Entire string minus 2 from the right
    index=1
    print arr[:-index]
    >>'test tex'    #Entire string minus 1 from the right
    index=0
    print arr[:-index]
    >>''           #I would like entire string minus 0 from the right
Run Code Online (Sandbox Code Playgroud)

注意:我使用的是Python 2.7.

python list slice

7
推荐指数
3
解决办法
2557
查看次数

"没有匹配函数来调用'async(std :: launch,<unresolved overloaded function type>,std :: string&)'"

我正在尝试创建一个线程使用std::async,但我不断收到错误"没有匹配函数来调用' async(std::launch, <unresolved overloaded function type>, std::string&)''就行了

ConnectFuture = std::async(std::launch::async, Connect_T,ip);
Run Code Online (Sandbox Code Playgroud)

以下是产生此行为的代码:

#include <future>

class libWrapper
{
public:

    void Connect(std::string ip);
    void Connect_T(std::string ip);

private:

    std::future<void> ConnectFuture;
};



void libWrapper::Connect(std::string ip){

    auto status = ConnectFuture.wait_for(std::chrono::seconds(0));
    if (status != std::future_status::timeout)
    {
        ConnectFuture = std::async(std::launch::async, Connect_T,ip);

    }
}

void libWrapper::Connect_T(std::string ip)
{


}

int main(int argc, char** argv) {
    libWrapper lW;
    lW.Connect("192.168.3.1");
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ c++11 stdasync

4
推荐指数
1
解决办法
5809
查看次数

标签 统计

c++ ×1

c++11 ×1

list ×1

python ×1

slice ×1

stdasync ×1