Thursday, December 18, 2014

I don't know C++ any more

C++11 seems to be a completely new beast. It also seems to be becoming more like Perl in that there's more than one way (now) to do it (TIMTOWTDI, read "tim-toady"). And this can be quite obfuscatory. Case in point:



#include <iostream>
#include <type_traits>

int main()
{
        typedef std::integral_constant<int, 2> two_t;
        two_t::type::type::type second;
        std::cout << std::boolalpha;
        std::cout << std::is_same<decltype(second), two_t>::value << std::endl;
        std::cout << std::is_same<decltype(second)::type, two_t>::value << std::endl;

        return 0;
}



The stuff highlighted in red above is superfluous, but completely legal per the syntax. And there are several more plays on this to really write obfuscated code.

No comments: