2-5. Working with Compile Time Constants
#include <array>
#include <cstdint>
#include <iostream> class MyClass
{
private:
uint32_t m_Member; public:
constexpr MyClass(uint32_t parameter)
: m_Member{parameter}
{
}
constexpr uint32_t GetValue() const
{
return m_Member;
}
}; int main()
{
constexpr uint32_t ARRAY_SIZE{ MyClass{ }.GetValue() };
std::array<uint32_t, ARRAY_SIZE> myArray{ , , , , };
for (auto&& number : myArray)
{
std::cout << number << std::endl;
}
return ;
}
C++有时候为了运行效率,提供了很多的feature,虽然比较难用
关键字constexpr 就是在编译时进行推导,提升运行效率。
Using constexpr to Define the Size of an array
#include <array>
#include <cstdint>
#include <iostream> int main()
{
constexpr uint32_t ARRAY_SIZE{ };
std::array<uint32_t, ARRAY_SIZE> myArray{ , , , , };
for (auto&& number : myArray)
{
std::cout << number << std::endl;
}
return ;
}
Creating constexpr class Constructors
2-5. Working with Compile Time Constants的更多相关文章
- Modern C++ CHAPTER 2(读书笔记)
CHAPTER 2 Recipe 2-1. Initializing Variables Recipe 2-2. Initializing Objects with Initializer Lists ...
- 最近编译POCO 库和 Boost库的笔记
最近在编译POCO库和BOOST库 先讲一下编译POCO库,我编译的是1.9.0,过程相当曲折,要OPENSSL修改版本的,个OPENSSL在这里下载,如果你用一般未修改的OPENSSL 是编译不了, ...
- STL空间分配器源码分析(二)mt_allocator
一.简介 mt allocator 是一种以2的幂次方字节大小为分配单位的空间配置器,支持多线程和单线程.该配置器灵活可调,性能高. 分配器有三个通用组件:一个描述内存池特性的数据,一个包含该池的策略 ...
- CLR via C# 3rd - 07 - Constants and Fields
1. Constants A constant is a symbol that has a never-changing value. When defining a constant ...
- 深入浅出OOP(五): C#访问修饰符(Public/Private/Protected/Internal/Sealed/Constants)
访问修饰符(或者叫访问控制符)是面向对象语言的特性之一,用于对类.类成员函数.类成员变量进行访问控制.同时,访问控制符也是语法保留关键字,用于封装组件. Public, Private, Protec ...
- Effective Java 30 Use Enums instead of int constants
Enumerated type is a type whose legal values consist of a fixed set of constants, such as the season ...
- 7.Constants and Fields
1.Constants is a symbol that has a never-changing value. its value must be determinable at compile ...
- compile time - run-time
php.net Class member variables are called "properties". You may also see them referred to ...
- Vue源码详细解析:transclude,compile,link,依赖,批处理...一网打尽,全解析!
用了Vue很久了,最近决定系统性的看看Vue的源码,相信看源码的同学不在少数,但是看的时候却发现挺有难度,Vue虽然足够精简,但是怎么说现在也有10k行的代码量了,深入进去逐行查看的时候感觉内容庞杂并 ...
随机推荐
- Postgresql-xl 调研
Postgresql-xl 调研 来历 这个项目的背后是一家叫做stormDB的公司.整个代买基于postgres-xc.开源版本应该是stormdb的一个分支. In 2010, NTT's Ope ...
- rabbitMQ+php
RabbitMQ与PHP(一) 项目中使用RabbitMQ作为队列处理用户消息通知,消息由前端PHP代码产生,处理消息使用Python,这就导致代码一致性问题,调整消息定义时需要PHP和Python都 ...
- 【转】jqGrid 各种参数 详解
[原文]http://www.cnblogs.com/younggun/archive/2012/08/27/2657922.htmljqGrid 各种参数 详解 JQGrid JQGrid是一个 ...
- eclipse技巧,快捷键
快捷键: ctrl + 1,快速修复 ctrl + d, 快捷删除行 shift + Enter,快速移动光标到下一行 ctrl + F11,运行代码 alt + ↑/↓,快速移动行 ctrl + a ...
- Java 实现多线程的两种方式
1:继承Therad类2:实现Runnable 接口 1.继承Thread类实现多线程继承Thread类的方法尽管被我列为一种多线程实现方式,但Thread本质上也是实现了Runnable接口的一个实 ...
- Jenkins自动部署Tomcat项目
Jenkins自动部署Tomcat项目 1.安装jenkins 插件 启动Jenkins,进入系统管理-插件管理: 选择Deploy to container Plugin 插件安装:
- fastclick 解决js穿透问题
http://www.tuicool.com/articles/VniQRr http://www.cnblogs.com/MrBackKom/archive/2012/06/26/2564501.h ...
- completed solution matches microsoft sequential workflow tutorial
microsoft sequential workflow tutorial website:http://msdn.microsoft.com/en-us/library/ms734794(v=vs ...
- 第十八周个人作业--The Final
项目计划 完成这个项目需要的时间:5-7天项目开发 需求分析: 作为一名排球赛事管理者,我希望能够根据比赛查询每场比赛的结果,以便于确定每支球队的比赛名次. 设计文档 由排球比赛用 ...
- Android菜鸟成长记10 -- ListVew
ListView在我们学习Android的过程中是非常重要得一个部分. listview主要有两个职责 1)将数据填充到布局. 2)处理用户的选择点击等操作. 一个ListView的创建需要3个元素 ...