1. ------------------------------------------------------------------------------
  2. #include <vector>
  3. #include <algorithm>
  4. #include <random>
  5.  
  6. int main()
  7. {
  8. std::vector<int> a{, , , , , , , , , , };
  9. std::vector<int> b();
  10.  
  11. std::sample(a.begin(), a.end(),
  12. b.begin(), b.size(),
  13. std::mt19937{std::random_device{}()});
  14. return ;
  15. }
  16. ------------------------------------------------------------------------------
  17. #include <iostream>
  18. #include <string>
  19.  
  20. int main()
  21. {
  22. const std::string myString = "Hello World";
  23.  
  24. // C++17 with init if:
  25. if (const auto it = myString.find("Hello"); it != std::string::npos)
  26. std::cout << it << " Hello\n";
  27.  
  28. if (const auto it = myString.find("World"); it != std::string::npos)
  29. std::cout << it << " World\n";
  30. }
  31. ------------------------------------------------------------------------------
  32. #include <iostream>
  33. #include <string>
  34.  
  35. using namespace std;
  36.  
  37. template<typename ...Args> auto sum(Args ...args)
  38. {
  39. return (args + ... + );
  40. }
  41.  
  42. template<typename ...Args> auto sum2(Args ...args)
  43. {
  44. return (args + ...);
  45. }
  46.  
  47. int main()
  48. {
  49. cout << sum(, , , , , , ) << "\n";
  50. cout << sum2(, , , , , , ) << "\n";
  51. }
  52. ------------------------------------------------------------------------------
  53. #include <utility>
  54. #include <tuple>
  55. #include <iostream>
  56.  
  57. int main() {
  58. std::pair d(, 0.0);
  59. std::tuple t(, , );
  60.  
  61. std::cout << std::get<>(t) << ", " << std::get<>(t) << ", " << std::get<>(t) << "\n";
  62. }
  63. ------------------------------------------------------------------------------
  64. #include <iostream>
  65. #include <string>
  66.  
  67. struct S
  68. {
  69. int n;
  70. std::string s;
  71. float d;
  72. };
  73.  
  74. template <std::size_t I>
  75. auto& get(S& s)
  76. {
  77. if constexpr (I == )
  78. return s.n;
  79. else if constexpr (I == )
  80. return s.s;
  81. else if constexpr (I == )
  82. return s.d;
  83. }
  84.  
  85. int main()
  86. {
  87. S obj { , "hello", 10.0f };
  88. std::cout << get<>(obj) << ", " << get<>(obj) << "\n";
  89. }
  90. ------------------------------------------------------------------------------
  91. https://www.codingame.com/playgrounds/2205/7-features-of-c17-that-will-simplify-your-code/introduction
  92. ------------------------------------------------------------------------------

c++17 代码你能看懂吗?的更多相关文章

  1. 最近老是有兄弟问我,Vue双向绑定的原理,以及简单的原生js写出来实现,我就来一个最简单的双向绑定,原生十行代码让你看懂原理

    废话不多说直接看效果图 代码很好理解,但是在看代码之前需要知道Vue双向绑定的原理其实就是基于Object.defineProperty 实现的双向绑定 官方传送门 这里我们用官方的话来说Object ...

  2. Holding Bin-Laden Captive!(hdoj1085)代码并未完全看懂

    We all know that Bin-Laden is a notorious terrorist, and he has disappeared for a long time. But rec ...

  3. C语言-人狼羊菜问题-最容易看懂的解决方法及代码

    题目描述:农夫需要把狼.羊.菜和自己运到河对岸去,只有农夫能够划船,而且船比较小,除农夫之外每次只能运一种东西,还有一个棘手问题,就是如果没有农夫看着,羊会偷吃菜,狼会吃羊.请考虑一种方法,让农夫能够 ...

  4. 写在最前面 - 《看懂每一行代码 - kubernetes》

    我要写什么 <看懂每一行代码 - kubernetes>会包含k8s整个项目的源码解析,考虑到门槛问题,在开始分析k8s之前我会通过一些更低难度的golang开源项目讲解来帮助大家提升go ...

  5. T4代码生成脚本从添加注释,添加命名空间开始(一款强大的代码生成工具从看懂脚本,到随心所欲的玩弄代码,本文只是T4的冰山一角,博主将不断深入探索并完善该文章)

    精通T4脚本要从读懂脚本的关键代码片段开始  1.1. 给类添加注释-->看懂类对应的代码:<#=codeStringGenerator.EntityClassOpening(entity ...

  6. 从零开始一起学习SLAM | 理解图优化,一步步带你看懂g2o代码

    首发于公众号:计算机视觉life 旗下知识星球「从零开始学习SLAM」 这可能是最清晰讲解g2o代码框架的文章 理解图优化,一步步带你看懂g2o框架 小白:师兄师兄,最近我在看SLAM的优化算法,有种 ...

  7. 一文看懂Stacking!(含Python代码)

    一文看懂Stacking!(含Python代码) https://mp.weixin.qq.com/s/faQNTGgBZdZyyZscdhjwUQ

  8. 小白学习VUE第一篇文章---如何看懂网上搜索到的VUE代码或文章---使用VUE的三种模式:

    小白学习VUE第一篇文章---如何看懂网上搜索到的VUE代码或文章---使用VUE的三种模式: 直接引用VUE; 将vue.js下载到本地后本目录下使用; 安装Node环境下使用; ant-desig ...

  9. 127个常用的JS代码片段,每段代码花30秒就能看懂(上)

    127个常用的JS代码片段,每段代码花30秒就能看懂(上) JavaScript 是目前最流行的编程语言之一,正如大多数人所说:“如果你想学一门编程语言,请学JavaScript.” FreeCode ...

随机推荐

  1. VS2019 实用操作

    本文列出了在编写程序过程中的几个非常实用的操作方式,通过这些操作方式,可以在一定程度上减少重复操作.提高编码效率.改善编程体验. 列模式操作 列操作是一项很常用且实用的功能,可以一次性修改不同的行. ...

  2. pytorch识别CIFAR10:训练ResNet-34(准确率80%)

    版权声明:本文为博主原创文章,欢迎转载,并请注明出处.联系方式:460356155@qq.com CNN的层数越多,能够提取到的特征越丰富,但是简单地增加卷积层数,训练时会导致梯度弥散或梯度爆炸. 何 ...

  3. linux下JNI开发—Hello为例

    转自:https://www.cnblogs.com/snake-hand/archive/2012/05/25/2517412.html 前期准备: 1.Java JDK 2.gcc 3.g++ 确 ...

  4. docker添加阿里云专属镜像

    阿里云镜像地址:https://link.zhihu.com/?target=https%3A//cr.console.aliyun.com/%23/accelerator 根据提示开启容器镜像服务, ...

  5. vue关于为空使用默认值

    参考地址:https://segmentfault.com/q/1010000009898107/a-1020000009898747 实现效果如下:

  6. MATLAB-卡尔曼滤波简单运用示例

    1.角度和弧度之间的转换公式? 设角度为 angle,弧度为 radian radian = angle * pi / 180; angle = radian * 180 / pi; 所以在matla ...

  7. Http input plugin

    logstash作为一个数据输入端.提供http服务,接收客户端的http请求,获取发送的内容. 在config目录下新建文件: vim config/http-input.yml input { h ...

  8. Linux 内核文档翻译 - kobject.txt

    原文地址:Linux 内核文档翻译 - kobject.txt 作者:qh997 Everything you never wanted to know about kobjects, ksets, ...

  9. 20175209 《Arrays和String单元测试》

    20175209 <Arrays和String单元测试> 题目 在IDEA中以TDD的方式对String类和Arrays类进行学习,测试相关方法的正常,错误和边界情况 String类 ch ...

  10. Python菜鸟快乐游戏编程_pygame(1)

    Python菜鸟快乐游戏编程_pygame(博主录制,2K分辨率,超高清) https://study.163.com/course/courseMain.htm?courseId=100618802 ...