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

网站自动登录怎么做在线注册网站

网站自动登录怎么做,在线注册网站,开锁公司网站模板,国外代理ip地址和端口一、[[fallthrought]] 用途&#xff1a;在 switch 语句中标记某个分支 (case) 故意不写 break&#xff0c;明确告知编译器“执行穿透”是有意为之。 仅在需要向下穿透时使用&#xff0c;且应添加注释说明原因 #include<cstdio> #include<iostream> using namesp…

一、[[fallthrought]]

用途:在 switch 语句中标记某个分支 (case) 故意不写 break,明确告知编译器“执行穿透”是有意为之。

  • 仅在需要向下穿透时使用,且应添加注释说明原因
#include<cstdio>
#include<iostream>
using namespace std;
void do_to(){printf("do_to");
}
void do_(){printf("do_");
}
int main(int argc,const char* argv[])
{int value;scanf("%d",&value);switch(value){case 1:do_();[[fallthrought]];//明确告知编译器允许穿透case 2:do_to();break;default:break;}return 0;
}

二、[[nodiscard]]

用途:强制要求必须处理函数返回值或对象构造结果,防止资源泄漏或逻辑错误。

(表示函数的返回值没有被接收,在编译时会出现警告。)

  • 函数类型
#include<cstdio>
using namespace std;
[[nodiscard]] int createResource() {return 42; // 返回资源句柄,调用者必须处理
}int main(int argc, char const *argv[])
{// 调用时会警告//错误写法createResource(); // 警告:忽略 nodiscard 返回值//正确写法int n =createResource();return 0;
}
  • 结构体类型
#include<cstdio>
using namespace std;
struct [[nodiscard]] ErrorCode {int code;
};
int main(int argc, char const *argv[])
{//错误写法ErrorCode parseInput(); // 必须检查返回值ErrorCode parseInput{1};//正确写法return 0;
}
  • class类型
#include<cstdio>
using namespace std;
class [[nodiscard]] DatabaseConnection { 
public:DatabaseConnection(int a):a(a){}
public:int a;
};
int main(int argc, char const *argv[])
{//错误写法DatabaseConnection connect(); // 必须获取连接对象,不能直接丢弃//正确写法DatabaseConnection connect(1);return 0;
}

三、[[maybe_unused]]

用途:显式标记未使用的变量、函数或参数是预期行为,避免编译器警告。

  • 未使用的参数
void logMessage([[maybe_unused]] const std::string& msg) {// 代码中暂时未使用 msg,但保留接口兼容性
}
  • 未使用的变量
void process() {[[maybe_unused]] int debugCounter = 0; // 调试用变量,发布版可能未使用
}

四、variant

用途:是一个加强版的union,类型安全的联合体,允许保存多种可能的类型值,比如string,map等等。

表示一个可能存在的值。 当我们通过函数创建一个对象时,通常使用通过函数返回错误码,而通过出参返回对象本身。

需要头文件<variant>

#include<csdio>
#include<variant>
using namespace std;
int main() { // c++17可编译std::variant<int, std::string> var("hello");cout << var.index() << endl;//1var = 123;cout << var.index() << endl;//0try {var = "world";std::string str = std::get<std::string>(var); // 通过类型获取值var = 3;int i = std::get<0>(var); // 通过index获取对应值cout << str << endl;//worldcout << i << endl;//3} catch(...) {// xxx;}return 0;
}

五、optional

用途:表示一个可能存在或不存在的值,替代 nullptr 或特殊值判断。

需要头文件<optional>

  • 构造和赋值
std::optional<int> opt1;          // 空optional
std::optional<int> opt2 = 42;     // 含值42
std::optional<int> opt3 = opt2;   // 拷贝构造
opt1 = 10;                        // 赋值为10
opt1 = std::nullopt;              // 重置为空
  • 访问值
std::optional<std::string> opt = "Hello";// 安全访问方式
if (opt) {                     // 检查是否有值std::cout << *opt;         // 解引用访问std::cout << opt.value();  // 成员函数访问
}// 不安全访问(可能抛出异常)
try {std::cout << opt.value();  // 无值时抛出std::bad_optional_access
} catch(...) {}// 提供默认值
std::cout << opt.value_or("default");  // 无值时返回"default"
  • has_value():检查是否有值。

  • value():获取值(无值时抛异常)。

  • value_or(default):有值返回,否则返回默认值。

六、any

用途:存储任意类型的单个值,类似类型安全的 void*。

需要头文件<any>

#include <any>
#include <string>std::any data;
data = 42;                     // 存储 int
data = std::string("hello");   // 存储 string// 检查并获取值
if (data.type() == typeid(int)) {int val = std::any_cast<int>(data);
} else if (data.type() == typeid(std::string)) {std::string s = std::any_cast<std::string>(data);
}

七、string_view

  • std::string_view 是 C++17 引入的轻量级字符串视图类,用于高效地处理字符串数据而不涉及内存分配或所有权。`

    • string_view` 作为只读字符串参数
  • 需要头文件<string_view>

八、简化重复命令空间的属性列表

[[ using CC: opt(1), debug ]] void f() {}
//作用相同于 [[ CC::opt(1), CC::debug ]] void f() {}
  • 例如

在C++17之前,属性(attributes)的使用需要显式指定命名空间。

[[rpr::kernel]]
[[rpr::target(cpu, gpu)]]
void compute() {// Perform computations
}

C++17后允许在同一个命名空间下声明多个属性时省略重复的命名空间部分。

[[rpr::kernel, rpr::target(cpu, gpu)]]
void compute() {// Perform computations
}
http://www.dtcms.com/wzjs/102812.html

相关文章:

  • 长沙口碑好的做网站公司哪家好网站seo分析报告
  • 固始网站建设正规淘宝代运营去哪里找
  • 平面设计官方网站知名网站排名
  • 广元企业网站建设美国搜索引擎排名
  • 做网站是干什么用的2019网站seo
  • 网站建设技术公司企业网站制作费用
  • 富锦建设局网站排名首页服务热线
  • 广广东网站建设seo首页网站
  • 做网站需要的资质站长工具视频
  • 影视自助建站官网人民网今日头条
  • 上杭县城乡规划建设局网站如何创建网站站点
  • 珠海移动网站设计上海还能推seo吗
  • 建设通相似网站北京全网推广
  • wordpress中触发鼠标按钮事件动态动态代码代码百度搜索名字排名优化
  • 建立网站分为几阶段市场营销方案怎么做
  • wordpress 仿值得买seo岗位工作内容
  • 外贸建立网站怎么做推广网站免费
  • 网站建设类行业资讯如何做好网络营销工作
  • 广州做外贸网站公司岳阳网站建设推广
  • 如何查网站的外链seo推广招聘
  • 网站建设制作要学什么北京做网站的公司有哪些
  • 做网站后端需要掌握什么技术抖音代运营收费详细价格
  • 凯里做网站it培训学校
  • WordPress图片生成文章图片优化软件
  • 评论回复网站怎么做的百度指数查询官网大数据
  • 网站建设背景及目的公司运营策划方案
  • 专门做广东11选5的网站电脑优化大师哪个好
  • 全国建设项目竣工验收公示网站谷歌浏览器下载app
  • 家在深圳歌词网站如何优化流程
  • 企业网站建设专业性体现在山东关键词快速排名