首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >assert和NDEBUG最近被大量使用了吗?

assert和NDEBUG最近被大量使用了吗?
EN

Stack Overflow用户
提问于 2022-11-22 00:54:32
回答 1查看 44关注 0票数 0

我想知道assert和NDEBUG部件是否在现代c++中使用。

还有线程和内存检查程序,如val差制和消毒剂。在单元测试中,gtest是很有名的。而且,即使我使用这些,我也不知道为什么调试部分被单独从预处理中删除。我认为发现bug的代码应该始终保留下来。

EN

回答 1

Stack Overflow用户

发布于 2022-11-24 15:27:00

让我们首先定义您的问题中没有定义的要求:

是断言,现在NDEBUG正在大量使用,,

我想“很多”的意思不止一个。

我想“这些天”意味着今年。

我想知道assert和NDEBUG部件是否在现代c++中使用。

我不知道什么是“现代c++”。我假设“现代c++”是由boost/asio库使用的,用于回答这个问题,因为boost是一个用C++编写的大型、伟大、高级的库。异步是一个很难的话题,所以我假设库的作者讲的是“现代c++”。

让我们下载boost/asio源代码,看看assertNDEBUG是否有任何用途

代码语言:javascript
复制
$ git clone https://github.com/boostorg/asio.git
$ git log --pretty=format:"%h" --since 2022-01-01 | xargs -n1 git show | grep assert
+    assert(completion);
     assert(impl_);
     assert(impl_);
+  static_assert(
+  static_assert(
-    static_assert(std::is_nothrow_move_constructible_v<allocator_type>);
-    static_assert(std::is_nothrow_move_constructible_v<allocator_type>);
-    assert(cancel);
       assert(ch && !ch.done());
-    void unhandled_exception() { assert(false); }
-      assert(executor);
-      assert(h);
-      assert(self_);
 #include <boost/asio/detail/assert.hpp>
+* Removed faulty assertions from `experimental::coro` implementation.
    Remove faulty assertions from experimental::coro implementation.
       assert(ch && !ch.done());
-      assert(coro->awaited_from == detail::noop_coroutine());
       assert(ch && !ch.done());
-      assert(coro->awaited_from == detail::noop_coroutine());
-        assert(coro->awaited_from == detail::noop_coroutine());
-        assert(coro->awaited_from == detail::noop_coroutine());
+  static_assert(asio::is_async_operation<decltype(d)>::value);
+  static_assert(
     assert(impl_);
      static_assert(asio::is_async_operation<decltype(d)>::value);
      static_assert(
+  static_assert(
-  static_assert(
+  assert(!ok);
-  [[expression] [return type] [assertion/note[br]pre/post-conditions]]
+#include <cassert>
+          assert(length < data_.size());
diff --git a/include/boost/asio/detail/assert.hpp b/include/boost/asio/detail/assert.hpp
--- a/include/boost/asio/detail/assert.hpp
+++ b/include/boost/asio/detail/assert.hpp
 // detail/assert.hpp
$ git log --pretty=format:"%h" --since 2022-01-01 | xargs -n1 git show | grep NDEBUG

这行+ assert(completion);显示,assert在“现代c++”中使用了“很多”。

然而,NDEBUG并没有在这个“现代c++”项目中使用“很多”。它很可能被其他项目所使用。这个答案的目的是为您提供工具,使您能够检查是否使用了某些东西,这取决于您想要限制搜索的约束条件。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74526387

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档