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

新的南宁网站建设公司百度下载安装最新版

新的南宁网站建设公司,百度下载安装最新版,国外知名网站,宁波seo推广报价多少先说结论: 如果问号表达式能编译通过,那么std::common_type就能通过。因为common_type的底层依赖的就是?: common_type的实现里,利用了问号表达式:ternary conditional operator (?:) https://stackoverflow.com/questions/14…

先说结论:

如果问号表达式能编译通过,那么std::common_type就能通过。因为common_type的底层依赖的就是?:

common_type的实现里,利用了问号表达式:ternary conditional operator (?:)

https://stackoverflow.com/questions/14328034/what-is-the-point-of-this-condition-found-in-the-implementation-of-stdcommon-tstd::common_type的部分实现:template <class T, class U>
struct common_type<T, U> {typedef decltype(true ? declval<T>() : declval<U>()) type;
};

?:这个表达式,有类型两个属性。有以下知识点:

1、表达式的。是运行时的逻辑,这个大家都很熟悉。比如一个问号表达式true : 2 : 1.0。它有一个值,这个值是根据condition判断出来的(这个例子里是true)。咱们可以用auto val来接住该值,auto val = true : 2 : 1.0; 那么val的值就是2.0。(注意,为什么是2.0,看下面分解

2、表达式的类型。是编译时获取的。也就是说true : 2 : 1.0作为一个整体,它有一个类型,系统会取其“共同”的类型。至于怎么提取的,是系统决定的。这个类型可以用decltype()在编译器来取,比如decltype(true : 2 : 1.0)。记住它是在编译期来确定的,而不是运行期来确定,所以它不管condition的。所以第一条里面,true : 2 : 1.0的值为什么是2.0呢,因为decltype对其分析的结果就是double。为了验证这一点,参看下面的写法,编译不成功:

auto x = true ? 1 : L"123";编译错误:
error C2446: “:”: 没有从“const wchar_t *”到“int”的转换
note: 没有使该转换得以执行的上下文
error C3536: “x”: 初始化之前无法使用为什么编译不成功呢,那是因为int和const wchar_t*是没有共同类型的。using T = decltype(true? std::declval<int>() : std::declval<const wchar_t *>());
或者
using T = decltype(false ? std::declval<int>() : std::declval<const wchar_t *>());结果都一样,编译错误:
error C2446: “:”: 没有从“const wchar_t *”到“_Ty1”的转换
1>        with
1>        [
1>            _Ty1=int
1>        ]
note: 没有使该转换得以执行的上下文
而以下的写法,表达式的类型均为double输出double
using T = decltype(1 ? 1 : 1.0);
std::cout << boost::typeindex::type_id_with_cvr<T>().pretty_name() << std::endl;输出double
using T = decltype(0 ? 1 : 1.0);
std::cout << boost::typeindex::type_id_with_cvr<T>().pretty_name() << std::endl;输出double
using T = decltype(0 ? 1.0 : 1);
std::cout << boost::typeindex::type_id_with_cvr<T>().pretty_name() << std::endl;输出double
using T = decltype(true ? std::declval<int>() : std::declval<double>());
std::cout << boost::typeindex::type_id_with_cvr<T>().pretty_name() << std::endl;输出double
using T = decltype(false? std::declval<int>() : std::declval<double>());
std::cout << boost::typeindex::type_id_with_cvr<T>().pretty_name() << std::endl;

再看自定义指针的例子: 

提取shit0*和shit1*的共同类型。
运行结果:struct shit0 * __ptr64struct shit0
{};
struct shit1 : shit0
{};void Test()
{using T = decltype(true ? std::declval<shit0*>() : std::declval<shit1*>());
std::cout << boost::typeindex::type_id_with_cvr<T>().pretty_name() << std::endl;}///
提取shit0和shit1的共同类型。
运行结果:struct shit0struct shit0
{};
struct shit1 : shit0
{};void Test()
{using T = decltype(true ? std::declval<shit0*>() : std::declval<shit1*>());
std::cout << boost::typeindex::type_id_with_cvr<T>().pretty_name() << std::endl;}

貌似等于号=也有类似属性,之后再研究吧

http://www.mmbaike.com/news/62109.html

相关文章:

  • 天津贝宏建筑工程有限公司解释seo网站推广
  • 网站运营专员月薪多少公司员工培训方案
  • 企业网站建设亮点今日刚刚发生的重大新闻
  • 做i网站seo关键词查询排名软件
  • 做网站用什么软件ps字体朋友圈广告投放价格表
  • 自己如何做电影网站百度云下载
  • 蓝色网站后台站长素材官网
  • 网站导航布局短视频营销常用平台有
  • vs2017做的网站如何发布免费的行情软件app网站
  • 做产品批发的网站有哪些青岛百度推广seo价格
  • 网站建设服务器选择可以推广赚钱的软件
  • 网站代码需要注意什么最近中国新闻热点大事件
  • 找人开发软件去什么网站新闻源软文推广平台
  • b2c电子商务模式的网站有哪些新浪体育nba
  • wordpress 微网站模板怎么用进入百度app查看
  • 网站专题页策划软文世界平台
  • 大型门户网站系统黑科技引流推广神器
  • 德州网站推广怎么做线上推广
  • 网站建设 软件有哪些方面培训学校管理制度大全
  • 门户网站建设方案目录如何推广公司网站
  • 网站设计的摘要成都谷歌seo
  • 西安公司网站制作价格太原免费网站建站模板
  • 学校网站制作方案网站百度百科
  • 电子网站建设设计seo 推广教程
  • 做网站jsp和php合肥百度搜索优化
  • 哪家公司做的网站好网店推广联盟
  • 热 综合-网站正在建设中网站搭建步骤
  • 网站外链建设的15个小技巧网络销售怎么做
  • 深圳网站设计师百度收录提交入口网址
  • 长沙专业网站建设公司哪家好长沙关键词快速排名