我想知道assert和NDEBUG部件是否在现代c++中使用。
还有线程和内存检查程序,如val差制和消毒剂。在单元测试中,gtest是很有名的。而且,即使我使用这些,我也不知道为什么调试部分被单独从预处理中删除。我认为发现bug的代码应该始终保留下来。
发布于 2022-11-24 15:27:00
让我们首先定义您的问题中没有定义的要求:
是断言,现在NDEBUG正在大量使用,,?
我想“很多”的意思不止一个。
我想“这些天”意味着今年。
我想知道assert和NDEBUG部件是否在现代c++中使用。
我不知道什么是“现代c++”。我假设“现代c++”是由boost/asio库使用的,用于回答这个问题,因为boost是一个用C++编写的大型、伟大、高级的库。异步是一个很难的话题,所以我假设库的作者讲的是“现代c++”。
让我们下载boost/asio源代码,看看assert和NDEBUG是否有任何用途
$ 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++”项目中使用“很多”。它很可能被其他项目所使用。这个答案的目的是为您提供工具,使您能够检查是否使用了某些东西,这取决于您想要限制搜索的约束条件。
https://stackoverflow.com/questions/74526387
复制相似问题