我如何用其他没有痛苦的东西代替std :: binary_function
How do I replace std::binary_function with something else without pain?
我们当前正在使用一些使用某些std :: binary_function,std :: unary_function的第三方软件包。如您所知,这些功能已在C 14中弃用,现在它们都从C 17中删除了。我们将使用C 17的一些新功能,同时我们不会做出一些重大更改,因为这可能会导致代码中的某些不稳定。我们如何简单地用其他疼痛较小的东西替换这些遗产C 功能(std :: binary_function,...(。
预先感谢您的帮助。
我不知道标准库中的任何现有类型,但是创建自己的东西并不重要:
template<class Arg1, class Arg2, class Result>
struct binary_function
{
using first_argument_type = Arg1;
using second_argument_type = Arg2;
using result_type = Result;
};
template <typename ArgumentType, typename ResultType>
struct unary_function
{
using argument_type = ArgumentType;
using result_type = ResultType;
};
这两个类都是用户定义的功能对象的简单基类,例如:
struct MyFuncObj : std::unary_function<int, bool>
{
bool operator()(int arg) { ... }
};
具有允许参数的别名使用某些内置功能中内置的标准库,例如std::not1
:std::not1(MyFuncObj())
。
我的猜测为什么不弃用是因为在C 11之后,大多数是使用lambdas来创建功能对象。并且具有variadic模板非常容易创建not
和其他事物的通用版本,而没有std::not1
,std::not2
。
相关文章:
- 使用std::multimap迭代器创建std::list
- C++中std::resize(n)和std::shrink_to_fit之间的区别
- 来自 std::list 的迭代器 .end() 按预期返回"0xcdcdcdcdcdcdcdcd"但 .begin()
- C++17复制构造函数,在std::unordereded_map上进行深度复制
- 如何导出包含具有"std::unique_ptr"值的"std::map"属性的
- 从持续时间构造std::chrono::system_clock::time_point
- std::具有相同基类的类的变体
- std::向量与传递值的动态数组
- 使用std::vector的OpenCL矩阵乘法
- std::map<struct,struct>::find 找不到匹配项,但是如果我循环通过 begin() 到 end(),我在那里看到匹配项
- std::condition_variable::wait()如何评估给定的谓词
- 如何获取std::result_of函数的返回类型
- std::原子加载和存储都需要吗
- 将对象移动到std::shared_ptr
- POCO::PostgreSQL:如何将std::vector支持添加到`Binder::bind`
- 使用一个考虑到std::map中键值的滚动或换行的键
- std::ios::binary 或 std::ifstream::binary 和类似
- 使用 std::sort 时"invalid operands to binary expression"
- 为什么我打开一个没有std::ios::binary的文件(std::ifstream)
- 不能将 boost::stream 与 std::string<unsigned char> 一起使用来实例化 boost::binary_oarchive 或 boost::binary