我想绑定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)给出一个错误(见下文):我做错了什么?Bertwim
> 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);
};