zoukankan      html  css  js  c++  java
  • c++17 structure binding test

     1 /*test for struct binding*/
     2 
     3 #include <string>
     4 #include <iostream>
     5 using namespace std;
     6 //命名空间 可以缩写为A::B
     7 namespace NA::NB
     8 {
     9     class Data
    10     {
    11     public:
    12         float a;
    13         int b;
    14         string data;
    15     };
    16     Data ff()
    17     {
    18         //保证声明时 属性是可访问的
    19         return { 23.0f,41,"abcdef" };
    20     }
    21 }
    22 
    23 int main()
    24 {
    25     {
    26         //这里可以使A,B,C 可以用来捕获
    27         //作用于当前范围
    28         auto[A, B, C] = NA::NB::ff();
    29         //[[std:cout]]
    30         cout << A << endl;
    31         cout << B << endl;
    32         cout << C << endl;
    33     }
    34     using namespace NA::NB;
    35     //无法使用auto
    36     Data obj = { 23.0f,41,"abcdef" };
    37     //编译期断言 ,如果不满足条件则会error
    38     //static_assert(false,"这个地方编译不通过");
    39     static_assert(true, "这个地方编译不通过");
    40     return 0;
    41 }
  • 相关阅读:
    设计模式总结
    centos7.5 安装python3.7
    搭建yum软件源
    centos安装gitbook
    编译技术
    samba安装
    docker命令
    shell基础知识
    随笔
    虚拟机字节码执行引擎(三)
  • 原文地址:https://www.cnblogs.com/yang131/p/13570237.html
Copyright © 2011-2022 走看看