当前位置: 首页 > news >正文

网站怎么做流量统计上海十大广告公司排名

网站怎么做流量统计,上海十大广告公司排名,网站地图添加,有哪些是用到了网站推广C20增加了三路比较运算符<>&#xff08;戏称航天飞机运算符&#xff09;&#xff0c;用于对类的比较运算符进行统一的设计。有两种使用方式&#xff1a;默认比较对于某些类&#xff0c;如果按照其成员逐一比较即可决定比较运算符的值&#xff0c;那么可以使用默认的三路运…

C++20增加了三路比较运算符<=>(戏称航天飞机运算符),用于对类的比较运算符进行统一的设计。

有两种使用方式:

  1. 默认比较

对于某些类,如果按照其成员逐一比较即可决定比较运算符的值,那么可以使用默认的三路运算符,编译器为为类生成==,!=,<,>,<=,>=

#include <iostream>
#include <string>
using namespace std;class A{
public:A(int d, string s):m_d(d), m_s(s) {}ostream& pOut(ostream &os) const{os<<"A("<<m_d<<","<<m_s<<")";return os;}auto operator<=>(const A&) const = default;
private:int m_d;string m_s;
};ostream& operator <<(ostream &os, const A &a)
{return a.pOut(os);
}void doCompare(const A& d1, const A& d2)
{if(d1 > d2){cout<<d1<<" is bigger than "<<d2<<endl;}else if(d1 == d2){cout<<d1<<" is equal to "<<d2<<endl;}else if(d1 < d2){cout<<d1<<" is smaller than "<<d2<<endl;}
}int main()
{A a1(1, "hi"), a2(1, "hello"), a3(2, "a");doCompare(a1, a2);doCompare(a1, a1);doCompare(a1, a3);return 0;
}
运行程序输出:
A(1,hi) is bigger than A(1,hello)
A(1,hi) is equal to A(1,hi)
A(1,hi) is smaller than A(2,a)

默认的比较运算符将按照成员的顺序先比较m_d然后再比较m_s

如果将m_d与m_s定义的顺序反过来,那么会影响到比较的结果:

#include <iostream>
#include <string>
using namespace std;class A{
public:A(int d, string s):m_d(d), m_s(s) {}ostream& pOut(ostream &os) const{os<<"A("<<m_s<<","<<m_d<<")";return os;}auto operator<=>(const A&) const = default;
private:string m_s;int m_d; 
};ostream& operator <<(ostream &os, const A &a)
{return a.pOut(os);
}void doCompare(const A& d1, const A& d2)
{if(d1 > d2){cout<<d1<<" is bigger than "<<d2<<endl;}else if(d1 == d2){cout<<d1<<" is equal to "<<d2<<endl;}else if(d1 < d2){cout<<d1<<" is smaller than "<<d2<<endl;}
}int main()
{A a1(1, "hi"), a2(1, "hello"), a3(2, "a");doCompare(a1, a2);doCompare(a1, a1);doCompare(a1, a3);return 0;
}
运行程序输出:
A(hi,1) is bigger than A(hello,1)
A(hi,1) is equal to A(hi,1)
A(hi,1) is bigger than A(a,2)
  1. 定制比较

当默认的比较规则不合适时,可以通过定义<=>为类生成统一的比较运算符。

定制比较时可以分为三个级别,对应的返回值类型分别为:

返回类型

是否有无法比较的值

说明

(强序)std::strong_ordering

所有元素都可比较,且有严格的顺序关系(可比较,等值唯一),比如数值

(弱序)std::weak_ordering

所有元素都可比较,但存在近似相等的情况(可比较,等值不唯一),比如大小写字符

(偏序)std::partial_ordering

元素存在不可比较的情况(非全可比较,等值也不唯一),比如void*指针

以下实现一个不区分大小写的字符串比较:

#include <iostream>
#include <string>
using namespace std;auto strToUpper = [](string str)  
{string s = str;transform(s.begin(), s.end(), s.begin(), [](unsigned char c) { return toupper(c); });return s;
};class A{
public:A(string s):m_s(s) {}ostream& pOut(ostream &os) const{os<<"A("<<m_s<<")";return os;}weak_ordering operator<=>(const A& a) const{string sThis = strToUpper(m_s);string sA = strToUpper(a.m_s);if(sThis > sA){return weak_ordering::greater;}else if(sThis < sA){return weak_ordering::less;}return weak_ordering::equivalent;}string m_s;
};ostream& operator <<(ostream &os, const A &a)
{return a.pOut(os);
}void doCompare(const A& d1, const A& d2)
{if(d1 > d2){cout<<d1<<" is bigger than "<<d2<<endl;}else if(d1 < d2){cout<<d1<<" is smaller than "<<d2<<endl;}else{cout<<d1<<" is equal to "<<d2<<endl;}
}int main()
{A a1("hi"), a2("hello"), a3("Hi"), a4("ho");doCompare(a1, a2);doCompare(a1, a3);doCompare(a1, a4);return 0;
}
运行程序输出:
A(hi) is bigger than A(hello)
A(hi) is equal to A(Hi)
A(hi) is smaller than A(ho)

可以看到通过实现了<=>编译器会由此实现其他运算符。

http://www.yayakq.cn/news/541819/

相关文章:

  • 网站搜索功能代码wordpress 分类菜单高亮
  • app介绍网站模板四川建设行政主管部门官方网站
  • 聊城做网站的公司价位专门做销售培训的网站
  • 建自己的网站多少钱如何建立自己的小程序
  • 赣州住房与城乡建设厅网站最新房价数据出炉
  • 郑州企业网站托管公司电影网站的代理怎么做
  • 铜陵做网站的公司电子商务系统的构成
  • 南昌网站建设公司特色智能建站是什么
  • php网站开发课程wordpress修改社交标签
  • 合肥建设监理协会网站高校支付网站建设费需要入无形资产
  • 如何推广网站平台网站模板 酒类
  • 网店平台网站建设需求wordpress连不上
  • 大型建设网站四川专业网站建设
  • 衡水企业网站设计网页设计教程花之语
  • 有什么网站可以免费品牌广告设计制作公司网站源码
  • tp做的网站封装成app网站背景图片怎么做
  • 商河县做网站公司江苏网站建设市场
  • 网站流量突然暴增教育网站制作设计
  • 国内网站设计案例欣赏企业网站设计建设长春
  • 网站底部素材做flash网站框架引擎
  • 上海工商局企业查询seo对网络推广的作用是
  • 网站嵌套代码centos7.2 wordpress
  • 有哪些网站是做网批女装商务网站建设用的是什么软件
  • 网站建设西街重庆人社app
  • 彩票网站建设 极云儿童做网站
  • 湖北外贸网站建设多少钱泉州网站设计哪家公司好
  • 有链接的网站购买域名后怎样建公司官网
  • 电商网站成品案例聚名网域名注册
  • 网站的栏目和板块设计建设网站要多少页面
  • 济南章丘网站建设火车头采集并自动发布到wordpress