boost 相关问题

Boost是一系列旨在用于C ++的高质量库。 Boost是免费的,通常被认为是“第二标准库”。

如何在 Boost::Spirit::x3 中执行通用的可重用规则?

在我目前正在开发的解析器中,我正在编写一些规则/“子解析器”,其大小相当重要。问题是:因为这个解析器可能需要编译器付出一定的努力......

回答 1 投票 0

为什么 boost::function_output_iterator 不是 std::output_iterator?

我希望 boost::function_output_iterator 是一个 std::output_iterator,但令人惊讶的是不是: #包括 模板 我希望boost::function_output_iterator是一个std::output_iterator,但令人惊讶的是不是: #include <boost/iterator/function_output_iterator.hpp> template<std::output_iterator<int> IntOutIter> void f(IntOutIter outputIterator){} int main(int argc, char const *argv[]) { f(boost::make_function_output_iterator([](int i){})); return 0; } (注意,语法 template<std::output_iterator<int> IntOutIter> 来自 如何声明采用 T 的 output_iterator 的模板函数?) clang++ -std=c++20 function-output-iterator.cpp 错误: error: no matching function for call to 'f' note: candidate template ignored: constraints not satisfied [with IntOutIter = function_output_iterator<(lambda at function-output-iterator.cpp:11:42)>] note: because 'std::output_iterator<boost::iterators::function_output_iterator<(lambda at function-output-iterator.cpp:11:42)>, int>' evaluated to false note: because 'boost::iterators::function_output_iterator<(lambda at function-output-iterator.cpp:11:42)>' does not satisfy 'input_or_output_iterator' note: because 'boost::iterators::function_output_iterator<(lambda at function-output-iterator.cpp:11:42)>' does not satisfy 'weakly_incrementable' note: because 'iter_difference_t<function_output_iterator<(lambda at function-output-iterator.cpp:11:42)>>' (aka 'void') does not satisfy '__is_signed_integer_like' note: because 'void' does not satisfy 'signed_integral' note: because 'void' does not satisfy 'integral' note: because 'is_integral_v<void>' evaluated to false note: and 'void' does not satisfy '__is_signed_int128' note: because 'same_as<void, __int128>' evaluated to false note: because '__detail::__same_as<void, __int128>' evaluated to false note: because 'std::is_same_v<void, __int128>' evaluated to false note: and 'same_as<void, __max_diff_type>' evaluated to false note: because '__detail::__same_as<void, std::ranges::__detail::__max_diff_type>' evaluated to false note: because 'std::is_same_v<void, std::ranges::__detail::__max_diff_type>' evaluated to false 1 error generated. 疑似原因 我怀疑这是因为boost::function_output_iterator声明 typedef void difference_type; 但是标准说它需要是integral,而不是void: 成为 output_iterator 需要成为 weakly_incrementable(通过 input_or_output_iterator) this 表示 std::iter_difference_t<T> = ...::difference_type(在 Boost 代码中将 iter_difference_t 和 difference_type 联系起来) 这条评论指出标准requires is-signed-integer-like<iter_difference_t<I>>对于weakly_incrementable 常见的建议是将 difference_type 实施为 ptrdiff_t,而不是 void: 为什么 Difference_type 是 std::weakly_incrementable 概念的一部分? 当你无法测量差异时如何处理 iterator::difference_type? 解决方法和增强自己的主张 我知道这可以编译: -template<std::output_iterator<int> IntOutIter> +template<IntOutIter> void f(IntOutIter outputIterator){} 但它消除了 C++ 的好处concepts:限制泛型类型变量以获得更好的错误消息并指示它们应该支持哪些操作。 那么,function_output_iterator不应该是output_iterator吗? 此外,boost 文档声称: function_output_iterator 是 Writable 和 Incrementable 迭代器概念的模型。` 但是incrementable需要weakly_incrementable,它显然不是一个模型! 问题 那么,带来了什么? boost::function_output_iterator实施错误吗? 或者我不应该能够将它用作 output_iterator,并且 boost 文档是错误的? 这只是一个猜测——我不是那个特定 boost 库的作者(好吧,我不是任何 boost 库的作者......),或者与 boost 的联系比任何其他用户都多。 您链接的 boost 文档页面上的日期是 2006 年的,这表明它相当旧,并且早于 C++20,足以假设在创建库时,他们仍在开发 C++11。 Boost 通常在其文档中谈论很多概念,但它们(通常)不指 C++20 概念。他们使用该术语仅指类型属性表,例如 boost.org/doc/libs/1_85_0/libs/iterator/doc/...。这类似于 C++20 概念,但没有编译器支持。 Boosts 非正式概念和 STL 中的概念甚至可能具有相同的名称,但这并不意味着它们 100% 相同。也许该库的作者还没有时间将内容与 STL 保持一致。也许他们对现有代码存在兼容性问题。或者也许他们不再对该库做任何事情了。 我们都认为使事物符合 STL 是一个好主意,但实际工作不是我们:-)

回答 1 投票 0

Boost 使用 GCC 编译,但不使用 MinGW(使用 CMake)

所以我有一个 C++ 项目,用于从 JSON 文件生成一些批处理文件,我使用 CMake 构建该文件。我使用的是 Windows,但使用 WSL2 可以在 Linux 中完成所有操作。我已经开发了一切并构建了它......

回答 1 投票 0

使用 kNN 的自定义距离函数来提升 R 树

几天来,我一直在尝试弄清楚如何传递自定义距离函数来增强 R 树以进行 k 最近邻查询。 我有大量的线串和多边形。我将两者都嵌入...

回答 1 投票 0

用于单元测试的模拟 AsyncReadStream 增强

我面临着一种情况,我们在表示 HTTP 会话的类内部使用 http::async_read(...) 和 http::async_write(...) 。但是,如果我们想对这个类进行单元测试,我们会

回答 1 投票 0

在一个协程的子协程中使用 websocket 时卡在 co_await

我尝试在两个协程中使用一个 ws 对象,一个协程用于发送,另一个用于接收。然而,当我尝试在现有协程中使用子协程时,代码停留在

回答 1 投票 0

将 unique_ptr 传递给完成处理程序时,Boost ASIO“错误地址”错误

我正在尝试使用 ASIO 实现一个简单的 TCP 服务器。这里的主要区别是我使用 std::unique_ptr 来保存缓冲区而不是原始指针,并且我将它们移动到完整的内部...

回答 1 投票 0

适用于 Windows 操作系统的 strerror_r 替代 api

我看到 Visual C++ 2008 不再支持 strerror_r(...) API,可能是因为线程安全问题。我想在我的程序中使用类似的功能。 还有其他 winapi 吗...

回答 2 投票 0

如何强制 boost 以 root 身份运行时抛出 boost::filesystem::filesystem_error ?

我有一些代码可以在某些(难以重现)情况下引发 boost::filesystem::filesystem_error 异常。 我设置了异常处理程序,我想测试正确的

回答 1 投票 0

在boost中查找有向图的所有循环

有人可以告诉我如何使用boost图库找到有向图的所有循环吗?

回答 2 投票 0

如何使用与 io_context 一起使用的不同 TimerInterval 类在类中调用具有自己的采样间隔的不同方法

我正在尝试使用与本文中的问题答案相同的想法。这个目标是实现一个类,它将在 start_trigger 中调用 3 个不同的方法,并使用它们自己的时间间隔

回答 1 投票 0

从accumulator_set中删除或修改accumulators::tag

在boost中,是否可以从accumulator_set动态删除给定的boost::accumulators::tag? typedef boost::累加器::功能 < boost::accumulators::tag::count, boost::

回答 2 投票 0

C++Builder 12.1(现代)中的 Boost 库

是否可以将 Boost 库与 C++Builder 12.1 附带的新“现代”64 位 clang 编译器一起使用? 我尝试使用 Boost 1.70,它可以与“旧”clang 一起使用

回答 1 投票 0

boost 链接器错误错误工具集

有很多与此相关的问题,但到目前为止还没有一个解决方案适合我的情况。 我使用工具集 14.1 使用 VS 2017 构建了 boost 1.63 库 构建 boost 库的命令行是: 巴贾姆--

回答 2 投票 0

如果我重命名类名,Boost 序列化会中断吗?

我正在开发一个具有工作序列化逻辑的项目。我已使用 Visual Assist 重命名了类名称。这会打破现在的逻辑吗?我需要任何版本控制来处理这个问题吗? 我试过了

回答 1 投票 0

将 boost::filesystem 与 std::ifstream 一起使用?

我正在使用带有 C++ 20 和 boost 1.71.0 的 Ubuntu 20.04 LTS。 以下编译无错误并输出示例文件内容: #包括 #包括 #包括 我正在使用带有 C++ 20 和 boost 1.71.0 的 Ubuntu 20.04 LTS。 以下编译无误并输出示例文件内容: #include <iostream> #include <string> #include <boost/filesystem.hpp> #include <filesystem> int main() { boost::filesystem::path output_dir = boost::filesystem::path("/out/"); boost::filesystem::path sample_file = output_dir / "sample.txt"; std::ifstream ifs{sample_file}; std::string content((std::istreambuf_iterator<char>(ifs)), (std::istreambuf_iterator<char>())); std::cout << "Sample file content: " << std::endl << content << std::endl; return 0; } 那么这是如何运作的呢?这是 boost::filesystem::path 隐式转换为 std::string 吗? 使用安全吗? Boost Filesystem fstream的文档表明: C++ 标准库的标头使用 const char* 来传递表示文件名的参数,该用法出现了七次。 文件系统库的 fstream.hpp 标头在命名空间 boost::filesystem 中提供等效组件,但七个 const char* 参数已被 const path& 参数替换。 文件系统库的 fstream.hpp 标头仅使用标准库组件作为基类,然后重新声明构造函数和打开函数以采用 const path& 类型而不是 const char* 类型的参数。 其使用记录在2 分钟教程和示例中。 std::basic_fstream有一个构造函数,它采用模板化的FSPath类型https://en.cppreference.com/w/cpp/io/basic_ifstream/basic_ifstream 这个重载应该只接受std::filesystem::path,但看起来像libstdc++接受任何符合std::filesystem::path接口的类。这是非标准的,不能与其他标准库一起编译:https://godbolt.org/z/njr5s3har 您可以使用 boost/filesystem/fstream.hpp 标题修复此问题,但您必须将 std::ifstream 更改为 boost::filesystem::fstream。更好的解决方法是改用 std::filesystem,这主要是 boost::filesystem 的替代品。

回答 2 投票 0

QT Creator 13 中的 Boost Beast 1.84 服务器示例和 clangd 警告

当我将以下原始 boost bread 1.84.0 服务器示例加载到我的 IDE QT Creator 13.0 (C++20) 中时,我收到以下 clang-tools 17.0.1 警告。我该如何解决/解决这个问题并且......

回答 1 投票 0

如何从使用 mmap 创建的内存块构造 std::vector<boost::dynamic_bitset<X>> 而无需复制

我们正在使用boost::dynamic_bitset。我们正在寻找从使用 mmap 创建的内存块(无需复制)构造 std::vectorboost::dynamic_bitset 的方法。同样我们想要获得记忆

回答 1 投票 0

使用 Boost C++ 清理主机名

我试图将主机名/ipv4/ipv6 传递给 linux 中的 ping 实用程序(以避免使用原始套接字、root),但是,我想在运行命令之前确保它是有效的。例如,如果恶意

回答 1 投票 0

我可以使用 boost::asio::io_context 独立使用不同时间间隔的不同方法吗?

我正在尝试实现一个 C++ 代码,该代码应该以不同的时间间隔调用三个彼此独立的不同方法。 例如,假设 method_1 应该被称为 e...

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.