跳到主要內容

發表文章

目前顯示的是 11月, 2018的文章

VIM on Windows

I have done with the slowness of cygwin git and switch to git-for-windows. Unfortunately, vim on cygwin doesn’t work well with git-for-windows per various path problems (e.g. plugin, path delimiters, etc). Here are some notes for tweaking vim on Windows. .vim or vimfiles Directories? Later one is used on Windows, however, many plugin or your scripts may refer the previous one. Thus, mklink it! i.e. .vim <==> vimfiles . VIM with Python Support Official vim81 compiles vim.exe without python support and gvim.exe with python/dyn (verify that with gvim --version ). Thus, Python support is only avail as of gvim.exe per official packages. Assume python.exe and python27.dll was installed in C:\Python\bin Add following environment variables PYTHONHOME=C:\Python\bin PATH=%PATH%;%PYTHONHOME% For :h pythonhome and :h pythondll . Verify above settings with :python print '' . Color Scheme gvim requires true color to apply color scheme correctly. Convert you

C++: 延遲函式實例化與 CRTP

C++: 延遲函式實例化與 CRTP Curiously recurring template pattern (CRTP) 是很有趣的模式,在標準函式庫中也有像 enable_shared_from_this 等應用,各種應用情境請參照前面的 Wiki 頁面。下面寫一個簡化的例子: template < typename T > struct base { auto interface ( ) { return static_cast < T * > ( this ) - > foo ( ) ; } } ; struct derived : base < derived > { int foo ( ) { return 123 ; } } ; int main ( ) { // your code goes here derived ( ) . interface ( ) ; return 0 ; } 這個範例中的 auto interface() 寫法,在 C++14 後才支援,在 C++11 以前,編譯器無法自動推導出 int 這個回傳型別而會吐出以下錯誤: error : 'interface' function uses 'auto' type specifier without trailing return type auto interface ( ) { ^ 也就是我們得自己寫出 auto interface() -> XXX {} ;那要 XXX 要怎麼推導呢? 直覺的寫法: template < typename T > struct base { auto interface ( ) - > decltype ( static_cast < T * > ( nullptr ) - > foo ( ) ) { return static_cast < T * >