为啥推荐使用scoped_lock和RAII idiom变流行是一样的原因:因为你可以确包任何情况下离开执行范围都会解锁mutex注意,这不仅仅是说你可能忘记调用unlock():在你的mutex被锁定之后,还有可能抛出异常,你写的unlock调用语句有可能永远没有机会执行,即使在lock()和un...
分类:
其他好文 时间:
2014-10-21 00:55:24
阅读次数:
379
在公共头文件中作如下定义:
#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
使用时:
if( IS_IPAD )
{
// ipad处理
}
else
{
// iphone处理
}...
分类:
其他好文 时间:
2014-10-20 15:12:14
阅读次数:
119
原文出处:http://www.cnblogs.com/hsinwang/articles/214663.html ????RAII是指C++语言中的一个惯用法(idiom),它是“Resource?Acquisition?Is?Initialization”的首字母缩写。中文可将其翻译为“资源获...
分类:
编程语言 时间:
2014-10-09 21:14:18
阅读次数:
298
pimpl idiom
flyfish 2014-9-30
pimpl是Pointer to implementation的缩写
为什么要使用pimpl
1最小化编译依赖
2接口与实现分离
3可移植
pimpl idiom也被称作Cheshire Cat , Compiler Firewall idiom.,d-pointer
这个技术在设计模式中作为桥接模式(Brid...
分类:
其他好文 时间:
2014-09-30 19:29:39
阅读次数:
199
【翻译自维基百科 http://en.wikipedia.org/wiki/Initialization_on_demand_holder_idiom,并进行适当增删】
可能你听过,使用单例模式(singleton)会有线程安全问题,当然可以通过同步加锁等方法解决。但,更简单的方法请看本文。...
分类:
其他好文 时间:
2014-08-24 23:53:03
阅读次数:
295
Idiomatic Phrases Game
Time Limit: 2 Seconds Memory Limit: 65536 KB
Tom is playing a game called Idiomatic Phrases Game. An idiom consists of several Chinese characters and has a certain ...
分类:
其他好文 时间:
2014-08-18 16:22:52
阅读次数:
228
【C++自我精讲】基础系列六 PIMPL模式0 前言很实用的一种基础模式。1 PIMPL解释 PIMPL(Private Implementation 或 Pointer to Implementation)是通过一个私有的成员指针,将指针所指向的类的内部实现数据进行隐藏。2 PIMPL优点举例:/...
分类:
编程语言 时间:
2014-08-13 00:41:34
阅读次数:
274
前言 你是否总因头文件包含冲突而苦恼? 你是否因头文件包含错乱而苦恼? 你是否因封装暴露了数据而苦恼? 你是否因经常改动实现而导致重新编译而苦恼?在这里, 这些问题都不是问题, 跟随作者, 揭秘pimpl.正文先来看一段例子: 有A, B 2个类, 分别由A.h, A.cpp, B.h, B.cpp...
分类:
其他好文 时间:
2014-08-11 11:42:52
阅读次数:
193
Any class that manages a resource (awrapper, like a smart pointer) needs to implementThe Big Three. While the goals and implementation of the copy-con...
分类:
其他好文 时间:
2014-08-08 15:51:06
阅读次数:
262
经验:当std::swap对你的类型效率不高时,提供一个swap成员函数,并确定这个函数不抛出异常
示例:
stl里的swap算法
namespace std{
template
void swap(T &a, T &b){
T temp(a);
a = b;
b = temp;
}
}
//“pimpl手法”(pointer to implementation) --> 文件间的编译依存度
class WidgetImpl{
public:
//...
pr...
分类:
编程语言 时间:
2014-07-10 19:35:50
阅读次数:
240