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

中国网站建设网页设计二维码生成器制作

中国网站建设网页设计,二维码生成器制作,网站开发的背景知识,建设官方网站企业网银登录std::enable_ifB, T::type 如果编译期满足B#xff0c;那么返回类型T#xff0c;否则编译报错 std::conditionalB, T, F::type 如果编译期满足B#xff0c;那么返回类型T#xff0c;否则返回类型F 下面是一个示例#xff0c;展示如何使用 std::condit…std::enable_ifB, T::type 如果编译期满足B那么返回类型T否则编译报错 std::conditionalB, T, F::type 如果编译期满足B那么返回类型T否则返回类型F 下面是一个示例展示如何使用 std::conditional 来选择返回类型 #include iostream #include type_traitstemplate typename T, typename U auto max(T a, U b) - typename std::conditional(sizeof(T) sizeof(U)), T, U::type {return (a b) ? a : b; }int main() {int a 5;double b 3.14;auto result max(a, b);std::cout Max value: result std::endl;return 0; } 在上面的示例中max 函数使用了 std::conditional 来根据两个参数的类型选择返回类型。如果 sizeof(T) sizeof(U)则返回类型为 T否则返回类型为 U。在 main 函数中我们调用 max 函数并打印返回值演示了根据条件选择返回类型的功能。 需要注意的是std::conditional 是一个模板类它提供了在编译时进行类型选择的能力。它在很多情况下可以用来实现类型萃取type traits和条件编译等功能。 std::integral_constantT, value std::integral_constantT, value 是 C 标准库中的一个模板类用于表示一个编译时常量的包装器。它接受两个参数T 表示常量的类型value 表示常量的值。 std::integral_constantbool, B 表示一个固定的常量布尔值其类型为 bool值为 B。 下面是一个示例展示如何使用 std::integral_constant 来表示编译时的布尔常量cpp   #include iostream #include type_traitsint main() {std::integral_constantbool, true true_value;std::integral_constantbool, false false_value;std::cout true_value: true_value std::endl;std::cout false_value: false_value std::endl;std::cout true_value type: typeid(true_value).name() std::endl;std::cout false_value type: typeid(false_value).name() std::endl;std::cout true_value value: true_value() std::endl;std::cout false_value value: false_value() std::endl;return 0; } 在上面的示例中我们创建了 true_value 和 false_value 两个 std::integral_constant 实例分别表示编译时的 true 和 false 布尔常量。我们使用 std::cout 打印了各个常量的值、类型和调用结果。 需要注意的是std::integral_constantbool, B 实际上是一个包装器它提供了类型信息和调用操作符函数调用运算符使得它在使用时可以像一个函数一样进行调用。调用 std::integral_constant 对象会返回其持有的常量值。 此外C 标准库中的 std::integral_constant 还提供了一系列的成员类型和成员函数如 value_type、operator()、operator bool 等用于操作和查询包装的常量。这些成员函数和成员类型可以用于进行类型推导、模板元编程和编译时条件判断等用途。 下面看一个比较难的应用将类型和自定义的数字联系起来做一些类型判断 #include iostream enum class type {none_type,// Integer types should go first,int_type,uint_type,long_long_type,ulong_long_type,int128_type,uint128_type,bool_type,char_type,last_integer_type char_type,// followed by floating-point types.float_type,double_type,long_double_type,last_numeric_type long_double_type,cstring_type,string_type,pointer_type,custom_type };// Maps core type T to the corresponding type enum constant. template typename T struct type_constant : std::integral_constanttype, type::custom_type {};#define FMT_TYPE_CONSTANT(Type, constant) \template \struct type_constantType \: std::integral_constanttype, type::constant {}FMT_TYPE_CONSTANT(int, int_type); FMT_TYPE_CONSTANT(unsigned, uint_type); FMT_TYPE_CONSTANT(long long, long_long_type); FMT_TYPE_CONSTANT(unsigned long long, ulong_long_type); FMT_TYPE_CONSTANT(bool, bool_type); FMT_TYPE_CONSTANT(float, float_type); FMT_TYPE_CONSTANT(double, double_type); FMT_TYPE_CONSTANT(long double, long_double_type); FMT_TYPE_CONSTANT(const void*, pointer_type);constexpr bool is_integral_type(type t) {return t type::none_type t type::last_integer_type; } constexpr bool is_arithmetic_type(type t) {return t type::none_type t type::last_numeric_type; }int main() {int a 12;std::cout is_integral_type(type_constantdecltype(a)::value)std::endl; //1bool* b nullptr;std::cout is_integral_type(type_constantdecltype(b)::value)std::endl; //0 } std::underlying_typeT::type std::underlying_typeT::type 是 C 标准库中的一个类型转换工具它用于获取枚举类型 T 的底层类型。 std::underlying_type 是一个模板类接受一个类型参数 T它用于表示一个枚举类型。std::underlying_typeT::type 表示枚举类型 T 的底层类型。 下面是一个示例展示如何使用 std::underlying_typeT::type 来获取枚举类型的底层类型 #include iostream #include type_traitsenum class MyEnum : unsigned int {Value1,Value2,Value3 };int main() {using UnderlyingType std::underlying_typeMyEnum::type;std::cout Underlying type of MyEnum: typeid(UnderlyingType).name() std::endl;return 0; } 在上面的示例中我们定义了一个枚举类型 MyEnum包含三个枚举值。然后我们使用 std::underlying_typeMyEnum::type 来获取 MyEnum 的底层类型并将其赋值给 UnderlyingType 类型别名。最后我们使用 std::cout 打印底层类型的类型信息。 在这个示例中我们使用 std::underlying_type 来获取 MyEnum 的底层类型。UnderlyingType 类型别名被推导为 unsigned int这是 MyEnum 底层的类型。 std::underlying_type 对于在编译时获取枚举类型的底层类型非常有用。它可以用于处理枚举类型的底层值进行位操作或其他需要底层类型的操作。 std::remove_cvremove_reference_tT::type 移除类型T的各种限定符。 比如const、volatile、左值引用T。 std::is_sameT, T2::value std::is_sameT, T2::value 是 C 标准库中的一个类型特性工具用于检查类型 T 和类型 T2 是否相同。值得注意的是cv限定符会让类型不同。 #include iostream #include type_traitsint main() {bool isSame std::is_sameint, int::value;std::cout isSame: isSame std::endl; // trueisSame std::is_sameint, double::value;std::cout isSame: isSame std::endl; // falsebool isSame std::is_sameconst int, int::value;std::cout isSame: isSame std::endl; // falseisSame std::is_samevolatile int, int::value;std::cout isSame: isSame std::endl; // falseisSame std::is_sameconst int, volatile int::value;std::cout isSame: isSame std::endl; // falsereturn 0; } std::is_base_ofT, D::value std::is_base_ofcompile_string, S 是 C 标准库中的一个模板类 std::is_base_of 的使用用于检查类型 S 是否是类型 compile_string 的基类或派生类。 std::is_base_of 是一个类型特性type trait它提供了一种在编译时判断一个类型是否是另一个类型的基类或派生类的机制。它属于 C 类型特性库type traits library的一部分位于 type_traits 头文件中。 在给定的代码中std::is_base_ofcompile_string, S 用于检查类型 S 是否是类型 compile_string 的基类或派生类。它返回一个编译时常量值 true 或 false表示 S 是否是 compile_string 的派生类。 具体的使用示例如下 // A base class for compile-time strings. struct compile_string {};template typename S struct is_compile_string : std::is_base_ofcompile_string, S {};template typename S, std::enable_ifis_compile_stringS::value::value constexpr auto to_string_view(const S s)- basic_string_viewtypename S::char_type {return basic_string_viewtypename S::char_type(s); } 在上面的示例中我们使用 std::is_base_of 来检查 derived_class 是否是 compile_string 的派生类。根据返回的结果我们输出相应的信息。 需要注意的是std::is_base_of 是在编译时进行类型检查的它只能用于判断类型之间的继承关系而不能用于检查对象之间的关系。 std::declvalT() std::declvalS 是 C 标准库中的一个模板函数 std::declval 的使用用于获取类型 S 的一个虚拟值引用。 std::declval 是一个函数模板它允许在不实际创建对象的情况下获取一个类型的虚拟值。它位于 utility 头文件中。 在给定的代码中std::declvalS 用于获取类型 S 的一个虚拟值。它返回一个该类型的右值引用Rvalue reference。 std::declval 的主要用途是用于在编译时创建对类型的引用以便在模板编程中进行类型推断。它通常与 decltype 一起使用用于声明返回类型或推断表达式的类型。需要注意的是std::declval 用于创建虚拟值但不能用于实际访问该值。它主要用于模板元编程中用于推断类型和进行 SFINAESubstitution Failure Is Not An Error。 template typename S struct is_string: std::is_classdecltype(detail::to_string_view(std::declvalS())) {};template typename S, typename void struct char_t_impl {}; template typename S struct char_t_implS, enable_if_tis_stringS::value {using result decltype(to_string_view(std::declvalS()));using type typename result::value_type; };// detail::to_string_view see belowtemplate typename Char, std::enable_ifis_charChar::value)::value inline auto to_string_view(const Char* s) - basic_string_viewChar {return s; } template typename Char, typename Traits, typename Alloc inline auto to_string_view(const std::basic_stringChar, Traits, Alloc s)- basic_string_viewChar {return s; } template typename Char constexpr auto to_string_view(basic_string_viewChar s)- basic_string_viewChar {return s; } template typename Char,std::enable_if!std::is_emptystd_string_viewChar::value::value inline auto to_string_view(std_string_viewChar s) - basic_string_viewChar {return s; } template typename S, std::enable_ifis_compile_stringS::value::value constexpr auto to_string_view(const S s)- basic_string_viewtypename S::char_type {return basic_string_viewtypename S::char_type(s); } void to_string_view(...);比如上面创建了一个虚拟的S对象的引用用于驱动detail::to_string_view模板进行类型推断从而判断是否可以继续编译。
http://www.pierceye.com/news/552778/

相关文章:

  • 网站怎么做充值系统php图书管理系统网站开发
  • 多商家网站建设自助建站系统源码 资源网
  • 广州番禺网站制作公司哪家好文章网站建设
  • 漯河网站建设e辽宁身营商环境建设局网站
  • 营销网站建设套餐企业信息公示管理系统
  • 网站布局设计排版网站外部链接做多少合适呢
  • 成品网站 源码1688上海网站建设 找德华专业
  • 网站建设费用申报佛山电脑培训班哪里有
  • 免费网站服务器厦门网站建设推广哪家好
  • 青海海东平安县建设局网站如何建设旅游网站
  • 成都响应式网站开发百度里面的站长工具怎么取消
  • 手机购物网站设计广告设计有限公司
  • 新手制作网站wordpress lamp 教程
  • 响应式的网站做优化好吗wordpress删掉自豪
  • 做网站第一步创建网站根目录
  • vs2010做网站前台专门做试题的网站
  • 柳州集团学校网站建设做美食推广的网站
  • 网站开发 发送邮件功能深圳做分销商城网站
  • 网站备案 取消网上智慧团建官网入口
  • 网站开发 无代码app 外包开发公司
  • 做网站应该用什么配置的手提电脑免费微商城小程序模板
  • 义乌外贸网站建设公司服务外包和劳务外包区别
  • 四川长昕建设工程有限公司网站兰州网站哪里做
  • 电子商务网站规划与管理申请一个域名后怎么做网站
  • 中小企业网站制作方法桂林景区网站策划
  • shopify做全品类网站提交链接
  • 网站建设和运营哪家公司好宠物医疗设计素材网站
  • 泰州网站制作公司中国空间站机械臂
  • 信誉好的常州网站建设网监备案网站更换域名
  • 淮南品牌网站建设电话南昌网站建设q479185700棒