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

网站建设 h5线上运营的5个步骤

网站建设 h5,线上运营的5个步骤,做网站的目的是什么,wordpress 博客群类sdk:any提供类型安全的容器来存储任何类型的单个值。通俗地说,std::any是一个容器,可以在其中存储任何值(或用户数据),而无需担心类型安全。void*的功能有限,仅存储指针类型,被视为不安全模式。std::any可以被视为vo…

      类sdk:any提供类型安全的容器来存储任何类型的单个值。通俗地说,std::any是一个容器,可以在其中存储任何值(或用户数据),而无需担心类型安全。void*的功能有限,仅存储指针类型,被视为不安全模式。std::any可以被视为void*的类型安全替代品。
      std::any初始化:拷贝初始化;使用参数化构造函数;大括号初始值设定(brace initializer);使用赋值运算符;使用std::make_any。
      必须使用std::any_cast<type>(any_var)函数将any_var值转换为原始类型。std::any_cast<type>(any_var)函数有一些重载,它可以返回副本、引用或指针,具体取决于调用方式。如果存储值的类型不是尝试转换的类型,则编译器将抛出std::bad_any_cast异常或返回nullptr转换期间的类型必须与原始类型完全相同

int test_any_init()
{// copy initialisationstd::any value = 66; // 推荐: std::any value = std::make_any<int>(66); // std::make_any:类型安全、异常安全std::cout << "value: " << std::any_cast<int>(value) << "\n"; // value: 66// assignment operatorvalue = "China";std::cout << "value: " << std::any_cast<const char*>(value) << "\n"; // value: China// parametrized constructorstd::any value2(88.);std::cout << "value2: " << std::any_cast<double>(value2) << "\n"; // value2: 88// brace initializertry {std::any value3{ "China" };std::cout << "value3: " << std::any_cast<std::string>(value3) << "\n"; // std::any_cast<const char*>(value3)} catch (std::bad_any_cast& e) {std::cout << "Error: " << e.what() << "\n"; // value3: Error: Bad any_cast}auto value4 = std::make_any<std::string>("Beijing");std::cout << "value4: " << std::any_cast<std::string&>(value4) << "\n"; // value4: Beijing 推荐转换为引用类型来避免创建临时对象std::string str = "Tianjin";std::any value5 = std::move(str);std::cout << "value5: " << std::any_cast<std::string&>(value5) << "\n"; // value5: Tianjinreturn 0;
}

      std::any的成员函数
      (1).emplace:改变存储的对象,直接构造新对象;
      (2).reset:通过调用对象的析构函数来销毁存储的对象;
      (3).has_value:用于检查对象是否存储值;
      (4).type:返回一个type_info结构体,可用于获取存储对象的属性,如存储值的类型ID

int test_any_member_functions()
{// emplace, typestd::any value = 6;std::cout << "value: " << std::any_cast<int>(value) << "\n"; // value: 6std::cout << "type name: " << value.type().name() << "\n"; // type name: int(windows), i(linux)auto& tmp = std::any_cast<int&>(value); // 引用tmp = 8;std::cout << "value: " << std::any_cast<int>(value) << "\n"; // value: 8std::any_cast<int&>(value) = 10;std::cout << "value: " << std::any_cast<int>(value) << "\n"; // value: 10auto ptr = std::any_cast<int>(&value); // 指针std::cout << "value: " << *ptr << "\n"; // value: 10// 避免抛异常auto ptr2 = std::any_cast<std::string>(&value);if (ptr2 == nullptr)std::cout << "value dons't contain a string\n"; // value dons't contain a stringvalue.emplace<std::string>("China");std::cout << "value: " << std::any_cast<std::string>(value) << "\n"; // value: Chinastd::cout << "type name: " << value.type().name() << "\n"; // windows: type name: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >// linux:   type name: NSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEif (value.type() == typeid(std::string))std::cout << "value type is std::string\n"; // value type is std::string// reset, has_valueif (value.has_value()) std::cout << "value found\n"; // value foundvalue.reset();if (!value.has_value()) std::cout << "no value found\n"; // no value foundstd::any tmp2;if (!tmp2.has_value()) std::cout << "tmp2 no value found\n"; // tmp2 no value found// std::any的主要问题是额外的动态内存分配std::cout << "size(any): " << sizeof(std::any) << "\n"; // size(any): 64(windows 10 vs2022), 16(ubuntu22.04 g++ 11.4)value = std::vector<int>{ 1, 2, 3 };std::cout << "value size: " << std::any_cast<std::vector<int>&>(value).size() << "\n"; // value size: 3return 0;
}

      执行结果如下图所示:注意:windows与linux上的差异

      尽管std::any为C++提供了很大的灵活性,但std::any的主要问题是额外的动态内存分配(堆内存)。由于容器不知道所包含的对象,因此动态分配成为任何对象都必须的。
      如果你了解所存储的类型(除了所存储的类型必须是可复制的这一事实之外),那么std::any可能不是合适的工具:它的灵活性会带来性能成本。如果恰好存在一个这样的类型T,则应该使用std::Optional。如果要存储的类型始终是具有特定签名的函数对象(例如回调),那么你需要std::function。如果你只需要存储编译时固定的某个集合中的类型,std::variant是一个不错的选择

      GitHub:https://github.com/fengbingchun/Messy_Test

http://www.hkea.cn/news/299627/

相关文章:

  • 天河做网站开发免费留电话号码的广告
  • 成都市金堂县网站建设免费seo在线工具
  • 计算机培训中心网站高端网站建设的公司
  • 成都建设路小学网站大作设计网站
  • 桂林创新大厦网站今日十大热点新闻事件
  • 做网站空间哪家好windows7系统优化工具
  • 网站建设首选公司seo推广一个月见效
  • 微信做模板下载网站有哪些推广网站要注意什么
  • 做网站 java c常德seo快速排名
  • 仙桃做网站找谁常用的网络推广方法
  • 品牌推广网站怎样做百度手机助手苹果版
  • 武汉工业网站制作百度人工服务热线24小时
  • 新闻头条最新消息今日头条站长之家seo综合
  • app与网站宁波seo网络推广渠道介绍
  • 国外学做咖啡的网站百度高级搜索网址
  • 建网站开源代码游戏推广怎么找玩家
  • 莱州哪里有做网站的浙江网站建设平台
  • ps网站设计与制作免费推广seo
  • 网站查询功能怎么做关键词搜索量怎么查
  • 付费网站推广网站优化包括哪些内容
  • 在日本做色情网站广州seo外包
  • 最棒的网站建设考研最靠谱的培训机构
  • 广州建设企业网站黑河seo
  • 招商网站建设性价比高seo排名优化的
  • 产品网站怎么做的长沙正规关键词优化价格从优
  • 怎样查询江西省城乡建设厅网站杭州seo网
  • 网站建设空间是指什么软件网站优化最为重要的内容是
  • 做美工要开通什么网站的会员呢新网站友链
  • 网站集约化建设推进情况推广app赚钱
  • 番禺大石做网站域名污染查询网站