static-assert

    7热度

    1回答

    这就是我想要实现的:创建从var/www/html到家中(~)文件夹中的目录的符号链接。我试图符号链接到家里的目录(~)是一个git仓库,如果这有什么不同。我在这个目录中有一个index.html文件。 我已经使用此命令在Amazon EC2实例上创建了var/www/html的符号链接:ln -s ~/dirIWant/ html,但是当我尝试访问我的网页时,导致出现以下错误:403 Forbi

    0热度

    1回答

    你好我试图串连表单字段名称和裁判这样并返回JSX <select className="lp-country" id="lp-country" name = 'country'{i} ref = 'country'{i} > 其中i是循环的索引。我收到意外的令牌错误。 代码截图:https://www.screencast.com/t/8QILiZaBGMM 错误截图:https://www.

    4热度

    2回答

    有没有一种方法可以在编译时已知的索引上静态声明并且在运行时断言?例如: template <class T, int Dim> class Foo { T _data[Dim]; public: const T &operator[](int idx) const { static_assert(idx < Dim, "out of r

    1热度

    2回答

    我想阻止某些函数被调用。让我们忽略通过函数指针或其他东西来调用函数的情况,只关注直接函数调用的情况。我可以用= delete来做到这一点。但是,发布的诊断信息不够丰富。我考虑使用static_assert,您可以使用它提供自定义诊断消息。我在函数体中放置了一个static_assert(false, ...)语句,希望在函数被调用时触发它。但是,事实证明,即使该函数未被调用,static_asse

    8热度

    1回答

    读cppreference.com: 静态断言声明可以在块范围出现(作为块 声明)和类体内(作为成员声明) 好了,现在我有以下代码: struct foo_t { static constexpr std::size_t maxAlignment() { // This is just a sample; I removed real code from this

    7热度

    1回答

    以下工作正常: struct X { }; // OK static_assert(std::is_default_constructible<X>::value, "Error"); 继断言失败编译: struct X { static_assert(std::is_default_constructible<X>::value, "Error"); }; // Fails 为什么在类

    1热度

    2回答

    我的问题是,下面的代码是否有效: template<int i> class Class { static_assert(sizeof(i) == 0, "Class instantiated with i != 1"); }; template<> class Class<1> {}; 这个片段与g++编译。但clang++被困在static_assert: error:

    2热度

    2回答

    我最近正在研究一个C++库,在那里我设计了一个模板类,出于效率和安全的原因,我们需要特别是非多态的。为了确保以后我没有忘记这一点,并意外地破坏了一切,我认为我会成为一个好公民,并为此添加静态断言。 我最初尝试是这样的: template <typename T> class VirtualVerboten { ... static_assert(!std::is_polymo

    6热度

    1回答

    考虑下面的代码: template<typename Derived> struct Base { static constexpr int x_base = Derived::x_derived; //static_assert(x_base > 1, "Oops"); }; struct Derived : public Base<Derived> { s

    2热度

    2回答

    我想写一个函数,如果使用编译时常量参数调用它将触发编译时错误,如果参数的值doesn与static_assert不匹配,但仍可以在运行时使用计算值进行调用。 东西有点像这样: template<int N> void f(N){ static_assert(N == 5, "N can only be 5."); do_something_with(N); } void