小编deW*_*eW1的帖子

如何将unique_ptr捕获到lambda表达式中?

我尝试过以下方法:

std::function<void ()> getAction(std::unique_ptr<MyClass> &&psomething){
    //The caller given ownership of psomething
    return [psomething](){ 
        psomething->do_some_thing();
        //psomething is expected to be released after this point
    };
}
Run Code Online (Sandbox Code Playgroud)

但它没有编译.有任何想法吗?

更新:

AS建议,需要一些新的语法来明确指定我们需要将所有权转移到lambda,我现在考虑以下语法:

std::function<void ()> getAction(std::unique_ptr<MyClass> psomething){
    //The caller given ownership of psomething
    return [auto psomething=move(psomething)](){ 
        psomething->do_some_thing();
        //psomething is expected to be released after this point
    };
}
Run Code Online (Sandbox Code Playgroud)

它会是一个好的候选人吗?

更新1:

我将展示我的实施movecopy如下:

template<typename T>
T copy(const T &t) {
    return t;
}

//process lvalue references
template<typename T>
T move(T &t) {
    return …
Run Code Online (Sandbox Code Playgroud)

c++ lambda unique-ptr c++11

38
推荐指数
4
解决办法
3万
查看次数

C++ Qt在哪里是std :: unique_ptr Qt版本?

因此,当在Qt中编程时,我希望尽可能地使用Qt实现.据我所见,没有Qt版本std::unique_ptr或者有没有?

如果它不存在,那么在Qt中产生"相同"结果的替代方案是什么?

c++ qt qt5

21
推荐指数
1
解决办法
1万
查看次数

Android如何获取当前的系统设置值?

我知道我可以通过以下方式更改设置:

Settings.System.putInt( getContentResolver() , 
         Settings.System.SCREEN_OFF_TIMEOUT , DELAY );
Run Code Online (Sandbox Code Playgroud)

但老实说,我找不到如何读取该/任何设置的当前值的解决方案。

java android system-setting android-studio android-settings

7
推荐指数
1
解决办法
8527
查看次数

如何从字符串/字节数组或任何其他容器加载私钥/公钥

是否有可能存储在一个源例如RSA公钥/私钥byte[]string或任何其他container与使用该密钥用于加密/解密?

文件中的解码函数如下所示:

void Decode(const string& filename, BufferedTransformation& bt)
{
    // http://www.cryptopp.com/docs/ref/class_file_source.html
    FileSource file(filename.c_str(), true /*pumpAll*/);

    file.TransferTo(bt);
    bt.MessageEnd();
}
Run Code Online (Sandbox Code Playgroud)

从文件加载密钥不是我想要的.

我知道它必须是可能的,因为我可以创建密钥AutoSeededRandomPool.

我只是不知道如何使用现有的.

也许我在文档中忽略了这一部分.

c++ cryptography rsa public-key-encryption crypto++

7
推荐指数
1
解决办法
9492
查看次数

我如何在客户端支持多个版本的TLS?

嗨我想在客户端使用SSLV23方法支持多个版本的TLS.但是我无法连接获取错误:

SSL23_GET_SERVER_HELLO:sslv3警报握手失败

任何人都可以告诉我如何使用openssl支持多个版本的TLS?

SSLV23的代码片段(不工作)

cctx = SSL_CTX_new(SSLv23_client_method());
  if(cctx) {
  SSL_CTX_set_options(cctx, SSL_OP_NO_SSLv3);
  }
Run Code Online (Sandbox Code Playgroud)

仅适用于TLS V1(工作)

cctx = SSL_CTX_new(TLSv1_client_method());
Run Code Online (Sandbox Code Playgroud)

c++ ssl openssl ssl-certificate poodle-attack

6
推荐指数
1
解决办法
4041
查看次数

C++的含义[]

这是来自提升asio的一个例子.这是什么意思?为什么 []?

acceptor_.async_accept(socket_,
    [this](boost::system::error_code ec)
Run Code Online (Sandbox Code Playgroud)

c++ boost boost-asio

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

如何找出模板<typename type>的类型?

假设我有这个代码,例如:

#include <iostream>

template< typename typeOne , typename typeTwo >
void doWhatever( typeOne a , typeTwo b )
{
    if( typeOne == std::string )
    {
        std::cout << "Hey I found a string" << std::endl;
    }
    else if( typeOne == int )
    {
        std::cout << "Oh shoot! Now it's an integer!" << std::endl;
    }
    else
    {
        std::cout << "Are you mad?! What is that?" << std::endl;
    }
    // if a is string for example cast it to int
}

int main() …
Run Code Online (Sandbox Code Playgroud)

c++ templates

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