在这份题目中~特别针对sort函数,我觉得值得探讨学习~ 首先 一般sort(begin,end,cmp),cmp这里只是bool类型的判断规则~ 然而代码中这里却好像调用了一个?对象?~所以一开始的时候我认为~这一个对象怎么可能有true or false?~ 然而却把(n,Distance)给忽略了~ 也就是说 其实这里是调用了()~所以需要重载
()运算符 将其返回一个bool类型~ 但是这里有一个疑问~这里的正确调用逻辑是? 先调用了构造函数,然后又调用()运算符?也就是说 被调用函数参数传了两次~
经过对 sort函数源码的观看 `template<class _Iter,
class _Sentinel>
constexpr void _Adl_verify_range(const _Iter& _First, const _Sentinel& _Last)
{ // check that [_First, _Last) forms an iterator range
_Adl_verify_range1(_First, _Last, bool_constant<_Range_verifiable_v<_Iter, _Sentinel>>{});
}
这里的第三个参数应该深入学习 但是目前存在诸多疑点~
_INLINE_VAR constexpr bool _Range_verifiable_v = _Range_verifiable<_Iter, _Sentinel>::value;
``` 首先这里的_Range_verifiable_v 代表另一个的值 继续点进去 是这样的`
template<class _Iter,
class _Sentinel = _Iter,
class = void>
struct _Range_verifiable
: false_type
{
};`
template<bool _Val>
using bool_constant = integral_constant<bool, _Val>;
using true_type = bool_constant<true>;
using false_type = bool_constant<false>;
_STD_BEGIN
// STRUCT TEMPLATE integral_constant
template<class _Ty,
_Ty _Val>
struct integral_constant
{ // convenient template for integral constant types
static constexpr _Ty value = _Val;
using value_type = _Ty;
using type = integral_constant;
constexpr operator value_type() const noexcept
{ // return stored value
return (value);
}
_NODISCARD constexpr value_type operator()() const noexcept
{ // return stored value
return (value);
}
};
// ALIAS TEMPLATE bool_constant
目前有诸多疑问 主要是关于sort()第三个参数
如何调用第一个参数 来返回bool类型值的?
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。