C++11外部模板
    
            
摘要:【C++11之外部模板】 在标准C++中,只要在编译单元内遇到被完整定义的模板,编译器都必须将其实例化(instantiate)。这会大大增加编译时间,特别是模板在许多编译单元内使用相同的参数实例化。看起来没有办法告诉C++不要引发模板的多次实例化。 C++11将会引入外部模板这一概念。C++已经有了强制编译器在特定位置开始实例化的语法: template class std::vector; 而C++所缺乏的是阻止编译器在某个编译单元内实例化模板的能力。C++11将简单地扩充前文语法如下: extern template class std::vector; 这样就告诉编译器不要...
        
阅读全文
摘要:【C++11之常量表达式】 关键字:constexpr; 中文学名:常量表达式。 constexpr用于把运行期计算放置在编译期。 使用constexpr有3个限制: 1、函数中只能有一个return语句(有极少特例) 2、只能调用其它constexpr函数 3、只能使用全局constexpr变量 一个constexpr函数,只允许包含一行可执行代码。但允许包含typedefs、 using declaration && directives、静态断言等。 假如你将一个成员函数标记为constexpr,则顺带也将它标记为了const。如果你将一个变量标记为constexpr,则
        
阅读全文
摘要:【C++11右值引用】 1、什么是左值?什么是右值? 左值是表达式结束后依然存在的对象;右值是表达式结束时就不再存在的对象。 2、在早期的C++中,普通 & 无法对右值取引用。只有 const & 可以对右值取引用。 右值引用能够解决两个问题。 1)非必要的拷贝操作 2)模板函数,按照实际类型进行转
        
阅读全文
摘要:【tty & pty & pts】基本概念:1> tty(终端设备的统称):tty一词源于Teletypes,或者teletypewriters,原来指的是电传打字机,是通过串行线用打印机键盘通过阅读和发送信息的东西,后来这东西被键盘与显示器取代,所以现在叫终端比较合适。终端是一种字符型设备,它有多种类型,通常使用tty来简称各种类型的终端设备。2> pty(虚拟终端):但是如果我们远程telnet到主机或使用xterm时不也需要一个终端交互么?是的,这就是虚拟终端pty(pseudo-tty)3> pts/ptmx(pts/ptmx结合使用,进而实现pty)
        
阅读全文
摘要:【PageRank】 PageRank,即网页排名,又称网页级别、Google左侧排名或佩奇排名。 在PageRank提出之前,已经有研究者提出利用网页的入链数量来进行链接分析计算,这种入链方法假设一个网页的入链越多,则该网页越重要。早期的很多搜索引擎也采纳了入链数量作为链接分析方法,对于搜索引擎效果提升也有较明显的效果。 PageRank除了考虑到入链数量的影响,还参考了网页质量因素,两者相结合获得了更好的网页重要性评价标准。对于某个互联网网页A来说,该网页PageRank的计算基于以下两个基本假设:数量假设:在Web图模型中,如果一个页面节点接收到的其他网页指向的入链数量越多,那么这..
        
阅读全文
摘要:【How to run a terminal inside of vim?】 :sh turn vim into shell mode d+trl back to vim 参考:http://stackoverflow.com/questions/1236563/how-to-run-a-terminal-inside-of-vim
        
阅读全文
摘要:【vimdiff】启动方法首先保证系统中的diff命令是可用的。Vim的diff模式是依赖于diff命令的。Vimdiff的基本用法就是:# vimdiff FILE_LEFT FILE_RIGHT或者# vim -d FILE_LEFT FILE_RIGHT光标移动接下来试试在行间移动光标,可以看到左右两侧的屏幕滚动是同步的。这是因为"scrollbind"选项被设置了的结果,vim会尽力保证两侧文件的对齐。如果不想要这个特性,可以设置::set noscrollbind可以使用快捷键在各个差异点之间快速移动。跳转到下一个差异点:]c反向跳转是:[c如果在命令前加上数字的
        
阅读全文
摘要:【svn's tree conflict】 A tree conflict occurs when a developer moved/renamed/deleted a file or folder, which another developer either also has moved/r...
        
阅读全文
摘要:[svn's diff command] svn diff 比较的是版本快照, 跟merge的应用diff完全不一样.缺省情况下,svn diff忽略文件的祖先,只会比较两个文件的内容。如果你使用--notice-ancestry,比较修订版本(也就是,当你运行svn diff比较两个内容相同,...
        
阅读全文
摘要:【符号表分离】 gcc编译环境下,debug & release的区别主要在于-g选项,当指定-g后会生成大量调试信息。此时可通过objcopy把调试符号剥离。参考:http://blog.csdn.net/cyteven/article/details/13015511
        
阅读全文
摘要:【gcc -D】-Dname Predefinenameas a macro, with definition1. 通常debug和release版的区别就在于是否有DEBUG宏,DEBUG宏可以通过-D选项传递。如:-DDEBUG参考: 1、http://gcc.gnu.org/onlinedocs/gcc-4.8.2/gcc/Preprocessor-Options.html#Preprocessor-Options 2、http://blog.csdn.net/blaider/article/details/7043444
        
阅读全文
摘要:【Options for Debugging Your Program or GCC】-g Produce debugging information in the operating system's native format (stabs, COFF, XCOFF, or DWARF 2). GDB can work with this debugging information.On most systems that use stabs format,-genables use of extra debugging information that only GDB can 
        
阅读全文
摘要:【invoking gdb】The most usual way to startgdbis with one argument, specifying an executable program: gdb programYou can also start with both an executable program and a core file specified: gdb program coreYou can, instead, specify a process ID as a second argument, if you want to debug a run...
        
阅读全文
摘要:[Debugging Information in Separate Files] gdballows you to put a program's debugging information in a file separate from the executable itself, in a way that allowsgdbto find and load the debugging information automatically. Since debugging information can be very large—sometimes larger than the
        
阅读全文
摘要:【Bash's ArithmeticExpression】let command: 1 let a=17+232 echo "a = $a" # Prints a = 403 let a=17 + 23 # WRONG4 let a="17 + 23" # Right5 let a=28/66 echo "a = $a" # Prints a = 4In addition to theletcommand, one may use the(())syntax to enforce an arithmetic context. 
        
阅读全文
摘要:【shell's glob】 basic glob example: range glob example: 参考:http://bash.cumulonim.biz/glob.html
        
阅读全文
摘要:【int* V.S. int[]】 在C++中,int[]有2种形态,一种是指针形态,即使用方法和int*一样,另一种是符号形态,即只是一个编译期的符号(意味着在runtime期,所定义的int[]根本不存在) int *p = "abc"; int p[] = "abc"; 对于上面2行代码,调用p[i]时结果是一样的,但执行过程不一样。具体参见《C专家编程》。
        
阅读全文
摘要:【anonymous namespace V.S. static variant】 在C语言中,如果我们在多个tu(translationunit)中使用了同一个名字做为函数名或者全局变量名,则在链接阶段就会发生重定义错误,为了解决这个问题,我们可以在定义这些标识符(identifier)的时候加...
        
阅读全文
摘要:【screen command of linux】 常用键: 补充: Ctrl-a S # split terminal horizon Ctrl-a TAB # switch to another splitted part then use step 3 to select a screen C
        
阅读全文
摘要:[define中的:#,##,#@]#defineConn(x,y)x##y#defineToChar(x)#@x#defineToString(x)#x(2)x##y表示什么?表示x连接y,让compiler认为 xy 需要组合在一起, 被看作是一个符号而不是其它. 举例说:intn=Conn(123,456);/* 结果就是n=123456;*/char*str=Conn("asdf","adf");/*结果就是 str = "asdfadf";*/(2)再来看#@x,其实就是给x加上单引号,结果返回是一个const char。举
        
阅读全文
摘要:【shell-array】Creating Array:1 $ names=("Bob" "Peter" "$USER" "Big Bad John")2 $ names=([0]="Bob" [1]="Peter" [20]="$USER" [21]="Big Bad John")3 # or...4 $ names[0]="Bob"You can get the number of elements of an 
        
阅读全文
摘要:[bash's parameter expansion] #: find first from left, remove-left ##: find last from left, remove left %: find first from right, remove right %%: find last from right, remove right example 1:1 parameter result2 ----------- ------------------------------3 ${NAME} polish.ostrich.racing.cha...
        
阅读全文
摘要:[bash's [ command & [[ keyword][ (test) command: bash中的条件测试語句, [ condition ], 并不是一个語句, 而是一个命令, 命令的名字是 [ , 这个命令期待最后一个参数是 ] . 在terminal中键入 whereis [, 可以看到[ 命令被放在系统中的哪个地方. [[ keyword: [[是[的扩展, 是bash中的keyword,提供比[更强大的功能, 更方便的使用方法. Special primitives that[[is defined to have, but[may be lacking (
        
阅读全文
摘要:[python's fnmatch&glob&os.listdir]fnmatch: fnmatch只有4种special character,用于提供和shell中一样的文件名的匹配. For a literal match, wrap the meta-characters in brackets. For example,'[?]'matches the character'?'. 主要函数有: fnmatch.fnmatch(), fnmatch.fnmatchcase(), fnmatch.filter(), fnmatch.t
        
阅读全文
摘要:【python's unittest】 unittestsupports some important concepts: 从上图可以看到,unittest中的test-case、test-suit概念和一般的unittest中的内容没有区别。 下面给出编写单元测试的示例: 编写要点: 1、继承自unittest.TestCase。 2、setUp、tearDown就是所谓的fixture。 3、测试函数以test开头。 开启测试: TheTestCaseclass provides a number of methods to check f...
        
阅读全文
摘要:[python 文件的读取&更新] 任务抽象: 读取一个文件, 更新内容后, 重新写入文件. 实际应用: 磁盘上的一个配置文件, 读入内存后为一个dict, 对dict更新后重新写入磁盘. demo: 关键应用在于读取文件后,使用seek&truncate把文件给清空, 然后再写入.参考:http://docs.python.org/2.7/library/stdtypes.html#file-objects
        
阅读全文
摘要:[linux fg&bg]Linux 提供了 fg 和 bg 命令,让我们调度正在运行的任务。假设你发现前台运行的一个程序需要很长的时间,但是需要干其他的事情,你就可以用 Ctrl-Z ,挂起这个程序,然后可以看到系统提示(方括号中的是作业号): [1]+ Stopped /root/bin/rsync.sh然后我们可以把程序调度到后台执行:(bg 后面的数字为作业号) #bg 1 [1]+ /root/bin/rsync.sh &用 jobs 命令查看正在运行的任务: #jobs [1]+ Running /root/bin/rsync.sh &如果想把它调回到前台运
        
阅读全文
摘要:【python's metaclass】 和objc中类似,metaclass用于创建一个类对象,但与objc不同的是,objc中每个类对象有各自不同的metaclass,而python中的metaclass主要用于创建class object。 首先,type可以像这样工作: __metaclass__属性 那么在__metaclass__中放置些什么代码呢? This allows classes or functions to be written which monitor or alter the class creation process.参考: 1...
        
阅读全文
摘要:【python's descriptor】1、实现了以下三个方法任意一个的,且作为成员变量存在的对象,就是descriptor。 1)object.__get__(self,instance,owner):instance是实例的引用,owner是类对象的引用。 2)object.__set__...
        
阅读全文
摘要:【__str__&__repr__】 object.__str__(self): Called by the str() built-in function and by the print statement to compute the “informal” string representat
        
阅读全文
摘要:【python要点之III】1、实现交换。 在C/C++中,交换两个变量,需要2个变量,tmp=x;x=y;y=tmp;。 在python中,交换两个变量可以这么写:x,y=y,x。2、is&is not操作符用于测试两个变量是否指向同一个对象。 a is b 等价于 id(a)==id(b)。3、//是地板除运算符。4、[::x]是步长切片,例如:s='abcdefgh',则s[::2]的结果是'aceg'。5、__dict__内部cpython实现使用了hash_table,非常耗内存,为了节省内存,可以在定义属性时使用__slots__,__slo
        
阅读全文
摘要:【python's is&==区别】 通常我们写: 1 if foo is None: pass 这个写法与以下的写法有何区别呢? 1 if foo == None: pass is当比较的是相同的对象实例时总是返回True。而==则完全决定于__eq__()方法的实现。例如:1 >>> class foo(object):2 def __eq__(self, other):3 return True4 5 >>> f = foo()6 >>> f == None7 True8 >>> f is None9
        
阅读全文