ICode9

精准搜索请尝试: 精确搜索
  • c-如果条件导致错误,则在constexpr中比较constexpr函数参数2019-10-14 02:15:56

    我正在尝试比较constexpr-if语句中的函数参数. 这是一个简单的示例: constexpr bool test_int(const int i) { if constexpr(i == 5) { return true; } else { return false; } } 但是,当我使用带有以下标志的GCC 7进行编译时: g -7 -std = c 1z test.cpp -o test我收到以下错误

  • C 11 static_assert(及其中使用的功能)2019-10-13 01:06:12

    static_assert与模板一起似乎是一个非常不错的功能. 但是,我很难在标准库中找到在编译时进行各种测试的功能. 例如,我正在寻找一种函数来检查一个类型是否是另一个类型的子类型. boost :: is_base_of可以完成这项工作,但是它是std中的一个可比较函数,因此我不需要依赖boost. 基本上

  • c – 是否允许编译器评估静态断言中的重言式2019-10-06 15:06:30

    参见英文答案 > static_assert dependent on non-type template parameter (different behavior on gcc and clang)                                    2个 在模板中提供static_assert通常很有帮助.在模板不应该以某种方式实例化的情况下,我

  • c – 在static_assert()中在编译时显示整数2019-10-06 13:10:14

    这是我正在尝试做的简化版本 enum First { a, b, c, nbElementFirstEnum, }; enum Second { a, b, c, nbElementSecondEnum, }; static_assert( First::nbElementFirstEnum == Second::nbElementSecondEnum, "Not the same number of el

  • c – 静态断言和SFINAE2019-10-05 00:15:07

    考虑一下: template <typename T> struct hash { static_assert(false,"Not implemented."); }; struct unhashable {}; template <typename T> auto test(const T &t) -> decltype((*(hash<T> const *)nullptr)(t),int); void test(

  • c – 如何用宏做static_assert?2019-09-26 10:04:33

    我曾尝试使用this suggestion来执行静态断言,但如果我在模板的方法中使用它,则不会出现编译错误. 示例如下: #include <iostream> #define STATIC_ASSERT(expr, msg) \ { \ char STATIC_ASSERTION__##msg[(expr)?

  • c – 在编译时比较静态字段指针2019-09-01 04:16:41

    我有一个派生自A类的B类.A声明一个静态字段f,B可能声明一个相同名称的类似字段.以下不起作用: struct A { static int f; }; struct B : A { static int f; }; // A::f is different from B::f struct C : A {}; // A::f is the same as C::f BOOST_STATIC_ASSERT((&A::f != &B::f)

  • c – 结合静态断言和断言?2019-08-30 00:05:43

    我有一个看起来像这样的函数: int div_round_up(int x, int y) { /** * This function only works for positive divisor and non-negative dividend!! */ assert(y > 0 && x >= 0); if (x == 0) return 0; return (x - 1) / y + 1; }

  • C编译并链接指向未定义函数的指针2019-08-23 19:08:34

    这段代码: void undefined_fcn(); void defined_fcn() {} struct api_t { void (*first)(); void (*second)(); }; api_t api = {undefined_fcn, defined_fcn}; 定义一个全局变量api,其中包含指向不存在函数的指针.然而,它编译,令我惊讶的是,与GCC绝对没有任何投诉的链接

  • c – 在hana的教程中使用nonconstexpr对象的static_assert2019-08-23 19:07:59

    阅读hana’s tutorial,我想知道static_assert如何按预期工作: template <typename Any> auto switch_(Any& a) { return [&a](auto ...cases_) { auto cases = hana::make_tuple(cases_...); auto default_ = hana::find_if(cases, [](auto const& c) {

  • c – /boost/lockfree/queue.hpp:错误:静态断言失败:(boost :: has_trivial_destructor :: value)2019-07-29 03:04:25

    我试图在此文件https://github.com/zaphoyd/websocketpp/blob/experimental/examples/broadcast_server/broadcast_server.cpp中替换boost :: lockfree :: queue for std :: queue 我添加了#include< boost / lockfree / queue.hpp&gt ;;更改了第130行,std :: queue< action> m_act

  • c – 如何将模板参数限制为指针或随机访问迭代器?2019-07-28 14:05:27

    有没有办法将模板函数的参数类型限制为仅指针或随机访问迭代器? 假设我正在开发一个仅适用于随机可访问容器的排序功能.我正在寻找一种方法来抛出编译时错误,如果用户通过非随机访问迭代器. #include <type_traits> #include <iterator> template <class Iterator> void mySort(It

  • c – 为什么这个静态断言不起作用?2019-07-27 12:07:11

    我试图使用pre-C 11静态断言.我发现了this和this的问题,但不知怎的,我无法让它运行: #define STATIC_ASSERT(x) \ do { \ const static char dummy[(x)?1:-1] = {0};\ } while(0) struct bar { int value; template<typename T> void setValue(T x); }; t

  • c – 用消息提升static_assert?2019-07-26 18:06:06

    在1.43提升似乎BOOST_STATIC_ASSERT只允许放置一个布尔值,是否有一些替代方案允许我在编译错误上显示消息?解决方法:MPL有BOOST_MPL_ASSERT_MSG.例如使用GCC 4.2.有了这个: BOOST_MPL_ASSERT_MSG(false, THIS_DOESNT_WORK, (void)); … 结果是: /path/to/file.cpp:42: error: no ma

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有