c++ - 如何绑定 std::filesystem::copy?
问题描述
我想绑定std::filesystem::copy的第三个参数,即
void copy( const std::filesystem::path& from,
const std::filesystem::path& to,
std::filesystem::copy_options options );
到某个值,比如 std::filesystem::copy_options::none。
当我做:
namespace fs = std::filesystem;
auto f1 = std::bind( fs::copy, _1, _2, fs::copy_options::none );
gcc 编译器(10.3.0,c++20)给出错误(见下文):我做错了什么?伯特温
> error: no matching function for call to ‘bind(<unresolved overloaded
> function type>, const std::_Placeholder<1>&, const
> std::_Placeholder<2>&, std::filesystem::copy_options)’ 641 |
> auto f2 = std::bind( fs::copy, std::placeholders::_1,
> std::placeholders::_2, fs::copy_options::none );
解决方案
std::filesystem::copy
是一个重载函数。这意味着它的名称不能衰减为单一类型,因为我们不知道您想要哪个重载。您可以通过强制转换来解决这个问题,但您可以使用 lambda 表达式来创建包装器,而不是这样做
auto f1 = [](const auto& from, const auto& to) {
fs::copy(from, to, fs::copy_options::none);
};
推荐阅读
- python - 为什么 python pathlib Path('').exists() 返回 True?
- sql-server - SQL Server Reporting Services CSV 报告导出选项缺失
- python - sqlalchemy:如何返回加入 3 个表的对象列表?
- ssl - Asio 流式传输 - SSL/TLS 加密速度慢
- php - 将变体描述移至 Woocommerce 产品变量描述
- angular - Angular 中不再有来自 rxjs 6.X 的异步或回调
- android - Android-Studio 模拟器音频错误
- python - 作为通过 pyodbc 调用 MSSQL 的一部分,如何以编程方式清除临时内存使用情况
- javascript - 应用程序的单独会话
- sql-server - 从同一张表的不同列获取固定数量的记录