Compile Time Reflection in C++11
故事背景
故事发生在遥远的我在使用C++来处理JSON和对象绑定的时候,我厌倦了写这样的代码:
C++11内存模型
Introduction
// cpp concurrency in action 里的例子
void undefined_behaviour_with_double_checked_locking() {
if (!resource_ptr) { // 1
std::lock_guard<std::mutex> lk(resource_mutex);
if (!resource_ptr) { // 2
resource_ptr.reset(new some_resource); // 3
}
}
resource_ptr->do_something(); // 4
}
在C++17中的部分新特性
C++17已经发布了有一些时候,并且很多的编译器已经完成了对C++17的支持,那对于C++17中的新特性,我也好奇的玩了一些,其中的几个新特性特别吸引我的注意。
if-init
Grammar
if ( init-statement condition ) init-statement 可以是:
- 表达式语句(可以是空语句,仅
;
) - 声明语句
Const Reference of Pointer
问题起源: 在子类中实现一个模板父类的纯虚函数的时候,不能正确的通过编译。
template<typename T>
struct Fuck {
virtual void shit(const T&) = 0;
}
编译时期常量数组及常用操作
文中所有的代码均遵循C++11的标准并编译通过。