Cpp11 compat

Fix compilation with C++11 and without GNU extensions.

1. s/typeof/decltype/g in may places
2. Use std::remove_reference<>::type to avoid pointer-to-reference variable declaration.