小编Hol*_*olt的帖子

在字符文字中转义撇号

你能告诉我怎么能逃脱撇号.

我需要它通过文件操作处理非撇号字符,所以当我遇到撇号(')时,我不能只给出ch!='''.它不起作用.你能告诉我正确的格式吗?谢谢..:)

c++ escaping

14
推荐指数
2
解决办法
3万
查看次数

Qt本地安全Web套接字

我正在开发一个Qt应用程序,它通过WebSocket与我的网络浏览器(目前是谷歌浏览器)进行通信.

一切都工作正常,直到我尝试使用安全的websockets ...

我设法解决了我在OpenSSL中遇到的问题,所以现在我应该有一个有效的Qt应用程序,但我没有.

我正在使用VS2013和Qt 5.3.我有以下代码来启动我的服务器:

MyClass::MyClass (quint16 port, QObject *parent) : 
    QWebSocketServer("Press And Listen Server", QWebSocketServer::SecureMode, parent) {

    QSslConfiguration sslConfiguration;
    QFile certFile (QStringLiteral ("localhost.crt"));
    QFile keyFile (QStringLiteral ("localhost.key"));
    certFile.open (QIODevice::ReadOnly);
    keyFile.open (QIODevice::ReadOnly);
    QSslCertificate certificate (&certFile, QSsl::Pem);
    QSslKey sslKey (&keyFile, QSsl::Rsa, QSsl::Pem);
    certFile.close ();
    keyFile.close ();
    sslConfiguration.setPeerVerifyMode (QSslSocket::VerifyNone);
    sslConfiguration.setLocalCertificate (certificate);
    sslConfiguration.setPrivateKey (sslKey);
    sslConfiguration.setProtocol (QSsl::TlsV1SslV3);
    this->setSslConfiguration (sslConfiguration);

    if (!this->listen (QHostAddress::Any, port)) {
        throw ServerNotStartedException () ;
    }
    qDebug () << "Server listenning on: " << port ;
    connect (this, &QWebSocketServer::newConnection, this, …
Run Code Online (Sandbox Code Playgroud)

c++ ssl qt websocket qtwebsockets

14
推荐指数
1
解决办法
3217
查看次数

从.tar.gz安装模块到Anaconda

当我想将模块安装到Anaconda时,我跑了conda install.但是,现在我有一个.tar.gz文件,想要安装它.怎么做?

python-3.x anaconda

14
推荐指数
2
解决办法
3万
查看次数

为什么当T不可移动构造时,std :: optional的move-constructor不会被删除?

根据标准,复制构造函数std::optional<T>:

......除非is_copy_constructible_v<T>是,否则应被定义为删除true.

但是移动构造函数std::optional<T>:

......除非is_move_constructible_v<T>是,否则不得参与超载决议true.

据我了解删除的构造函数,不删除move-constructor的目的std::optional<T>是允许这样的代码:

std::optional<X> o1;
std::optional<X> o2(std::move(o1));
Run Code Online (Sandbox Code Playgroud)

......依靠一些转换序列工作 - o2将由一个A使用a构造的类型的对象构造std::optional<X>&&(如果我错了,请纠正我).

但是对于可能的构造函数std::optional,我很难找到一个可以匹配这个用例的...

为什么移动构造函数std::optional<T>根本不被删除,如果T不是可移动构造的?

c++ optional move-constructor

12
推荐指数
2
解决办法
695
查看次数

为什么排列函数的时间复杂度为O(n!)

考虑以下代码.

public class Permutations {
    static int count=0;
    static void permutations(String str, String prefix){
        if(str.length()==0){
            System.out.println(prefix);
        }
        else{
            for(int i=0;i<str.length();i++){
                count++;
                String rem = str.substring(0,i) + str.substring(i+1);
                permutations(rem, prefix+str.charAt(i));
            }
        }

    }
    public static void main(String[] args) {
        permutations("abc", "");
        System.out.println(count);
    }

}
Run Code Online (Sandbox Code Playgroud)

这里我认为遵循的逻辑是 - 它将字符串的每个字符视为可能的前缀,并置换剩余的n-1个字符.
所以通过这种逻辑,复发关系就出现了

T(n) = n( c1 + T(n-1) )          // ignoring the print time
Run Code Online (Sandbox Code Playgroud)

这显然是O(n!).但是当我使用一个计数变量看到天体确实按照n!的顺序增长时,我发现了不同的结果.
对于计数++的2长度字符串(在for循环中)运行4次,对于3长度字符串计数值为15,对于4和5长度字符串其64和325.
这意味着它比n!更糟糕.那么为什么它说这个(以及产生permuatations的类似算法)就运行时而言是O(n!).

algorithm permutation time-complexity

10
推荐指数
1
解决办法
8605
查看次数

函数模板参数推导(类与功能模板)

你能帮我理解为什么参数推导适用于类模板而不适用于函数模板?

如果我理解正确,类模板定义了一个函数,所以当我调用它时,编译器可以进行隐式转换,但是在函数模板的情况下,目前没有函数定义,所以隐式转换没有发生.

但是我不明白为什么编译器不能创建函数定义然后应用隐式转换?

#include <functional>

template<typename ...ARGS>
class Test1
{
public:
    void add(const std::function<void(ARGS...)>&) {}
};

class Test2
{
public:
    template<typename ...ARGS>
    void add(const std::function<void(ARGS...)>&) {}
};

void func(int) {}

int main()
{
    Test1<int> test1;
    test1.add(func);

    Test2 test2;
    test2.add<int>(func);
}
Run Code Online (Sandbox Code Playgroud)

错误是:

在函数'int main()'中:

   25:24:错误:没有匹配函数来调用'Test2 :: add(void(&)(int))'

   25:24:注意:候选人是:

   14:10:注意:模板void Test2 :: add(const std :: function&)

   14:10:注意:模板参数扣除/替换失败:

   25:24:注意:不匹配的类型'const std :: function'和'void(int)'

c++ templates std-function template-argument-deduction argument-deduction

10
推荐指数
1
解决办法
289
查看次数

在nginx中为相对URL使用别名时的禁止位置

我试图在相对网址上设置带有nginx的roundcube/phpldapadmin/...,例如:

example.com/roundcube
example.com/phpldapadmin
Run Code Online (Sandbox Code Playgroud)

首先,Apache 2.4一切正常.我有以下文件夹:

# roundcube
/var/www/roundcube
# phpldapadmin
/usr/share/phpldapadmin
Run Code Online (Sandbox Code Playgroud)

我有以下location为roundcube:

location /roundcube/ {
    root /var/www;
    index index.php;

    location ~ \.php$ {
        try_files $uri =404;
        include /etc/nginx/fastcgi_params;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}
Run Code Online (Sandbox Code Playgroud)

哪个工作正常,但以下内容phpldapadmin不起作用:

location /phpldapadmin/ {
    alias  /usr/share/phpldapadmin/htdocs;
    index  index.php index.html index.htm;

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include /etc/nginx/fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}
Run Code Online (Sandbox Code Playgroud)

我得到一个403 forbidden,有以下日志:

2016/02/07 21:43:33 [error] 23047#0: *1 …
Run Code Online (Sandbox Code Playgroud)

nginx relative-path phpldapadmin

9
推荐指数
1
解决办法
6584
查看次数

为什么不能用"非const"复制构造函数实例化对,而可以实例化一个没有?

假设您有以下课程:

struct A {
    A () {}
    A (A &) = delete;
};

int main() {
    std::pair<A, int> p1;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

以下代码将无法编译(使用-std=c++11with g++),并出现以下错误:

/usr/include/c++/5/bits/stl_pair.h:在'struct std :: pair'的实例化中:

test.cpp:13:23:从这里要求

/usr/include/c++/5/bits/stl_pair.h:127:17:错误:'constexpr std :: pair <_T1,_T2> :: pair(const std :: pair <_T1,_T2>&)[与_T1 = A; _T2 = int]'声明采用const引用,但隐式声明将采用非const

constexpr pair(const pair&) = default;
Run Code Online (Sandbox Code Playgroud)

根据错误消息,我认为这是因为由于参数const上的限定符,无法实现默认的复制构造std::pair函数.

我可以理解为什么没有这个就不能编译= delete,因为不可能实现带std::pair const&参数的复制构造函数.

但是= delete,我希望编译器不会实例化这样的构造函数,因为它不能(据我所知).实际上,这个拷贝构造函数被删除,如下面这段代码所示:

std::pair<A, int> p1;
decltype(p1) p2(p1);
Run Code Online (Sandbox Code Playgroud)

失败了:

test.cpp:11:23:错误:使用已删除的函数'constexpr std :: pair <_T1,_T2> …

c++ constructor c++11

9
推荐指数
2
解决办法
4355
查看次数

无法从地图中获取 key_type

我写了这段代码是为了检查 a 是否std::map包含特定的键:

template<typename T, typename... Args >
inline bool contains(const std::map<Args...>& map, const T& value) noexcept
{
  static_assert(std::is_constructible_v< decltype(map)::key_type , T >);

  return map.find(value) != std::end(map);
}
Run Code Online (Sandbox Code Playgroud)

我有以下错误:

错误:key_type不是成员const std::map<std::__cxx11::basic_string<char>, Query>&

有什么问题decltype(map)::key_type?

c++ c++11

9
推荐指数
1
解决办法
243
查看次数

具有可变参数的部分特化的gcc vs clang行为加上相同类型的额外参数

以下代码:

#include <cstddef>

template <size_t N,
          typename T,
          T first,
          T... rest>
struct A {
};

template<typename T,
         T... args>
struct A<0, T, args...> {
};

int main () {
    A<0, int, 1> a0;
    A<2, int, 1, 2> a2;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

... 由于以下原因而无法编译g++(版本5.1.0和5.3.0):

错误:部分特化并不比主模板更专业,因为它用包扩展替换了多个参数

...但是要编译clang.

是否允许宣布这种部分专业化?

旁注:实际上,专业化是危险的,因为A<0, int>无法使用两个编译器进行编译(模板参数数量错误).

c++ template-specialization variadic-templates c++11

8
推荐指数
1
解决办法
298
查看次数