std :: less< void>和指针类型 [英] std::less<void> and pointer types

查看:87
本文介绍了std :: less< void>和指针类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

std::less<T *>都能提供总顺序,而不管两个指针是否指向同一数组.

std::less<T *> is guaranteed to provide total order, regardless of whether both pointers point into the same array.

在该标准的最新草案中,调用透明函数对象operator()时,透明函数对象std::less<void>(std::less<>)是否相同?

In the latest draft of the standard, is the same true for the transparent function object std::less<void> (std::less<>) when you call its operator()?

很显然,相同的问题适用于std::greater,但是我认为它们的指定相同.

Obviously, the same question applies to std::greater, but I assume they are specified the same.

推荐答案

来自github的当前草稿不包含任何与此相关的语言;实际上,其对less<>的定义明确地表示返回std::forward<T>(t) < std::forward<U>(u)",对于无可比拟的指针,这将是未定义的行为.所以...我想不要这样做.

The current draft from github does not contain any language to that effect; in fact, its definition of less<> says explicitly "returns std::forward<T>(t) < std::forward<U>(u)", which would be undefined behaviour for incomparable pointers. So... don't do it, I suppose.

如果需要异构指针比较器,最好编写自己的模板谓词,并在适当的时候使用std::less<T*>().

If you need a heterogeneous pointer comparator, it's probably best to write your own template predicate which uses std::less<T*>() at the appropriate moment.

这篇关于std :: less&lt; void&gt;和指针类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆