什么是“std::greater”或“std::less_equal”的类型
what is the type of `std::greater` or `std::less_equal`
template <class T> struct greater : binary_function <T,T,bool> {
bool operator() (const T& x, const T& y) const
{return x>y;}
};
template <class T> struct logical_and : binary_function <T,T,bool> {
bool operator() (const T& x, const T& y) const
{return x&&y;}
};
// (i > 5 && i <=10)
countBoost = std::count_if(vecInts.begin(), vecInts.end(),
boost::bind(std::logical_and<bool>(),
^^^^ // ???? Why ????
boost::bind(std::greater<int>(), _1, 5),
boost::bind(std::less_equal<int>(), _1, 10))
);
根据我的理解,std::logical_and<T>
的传入类型T
是函数operator()
的传入参数的类型。给定上面的代码,似乎bool
std::greater
的类型由返回值 operator()
确定。
这是对的吗?
谢谢
operator()
函数的返回类型为 bool。 的类型 std::greater
是std::greater
. 它是一个功能对象。 因此:
std::greater<int> g;
std::cout << typeof( g ).name() << std::endl;
将返回编译器用于显示实例化的任何内容类模板的类型:对于 VC++,"struct std::greater<int>"
例。
增强活页夹的作用比您预期的要多一些。当其中一个绑定参数是绑定表达式本身时,它将在调用期间执行该表达式并使用结果。在这种情况下,内部绑定表达式是对 std::less<int>
和 std::greater<int>
的调用,两者都产生一个bool
,然后传递给std::logical_and<bool>
。
相关文章:
- 使用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::equal 模板由两个类参数化?
- std::具有用户定义类的equal函数
- 是 'char* p=0;std::equal(p,p,p)' 根据C++标准明确定义
- 在“abcd”和“abc”的情况下,“std::equal”是否取消引用“end()”
- 是否有一个安全的替代std::equal
- 为什么std::equal比两个小std::数组的手卷循环慢得多?
- std::hash 是否保证"equal"浮点数的哈希值相等?