From adcc875c2961ca86c3880eedfd98019467d243d8 Mon Sep 17 00:00:00 2001 From: Vahagn Khachatryan Date: Tue, 26 May 2015 10:21:50 +0400 Subject: [PATCH] Microsoft's joke about new operators -~x and ~-x. --- cpp/joke_microsoft_operators.cpp | 36 ++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 cpp/joke_microsoft_operators.cpp diff --git a/cpp/joke_microsoft_operators.cpp b/cpp/joke_microsoft_operators.cpp new file mode 100644 index 0000000..5179264 --- /dev/null +++ b/cpp/joke_microsoft_operators.cpp @@ -0,0 +1,36 @@ +/* +VIM: let g:lcppflags="-std=c++11 -O2 -pthread" +VIM: let g:wcppflags="/O2 /EHsc /DWIN32" +VIM: let g:argv="" +*/ +#include +#include + +void joke( const int x ) +{ + std::cout << "("<< x << "+1)=" << -~x << std::endl; + std::cout << "("<< x << "-1)=" << ~-x << std::endl; +} + +int main ( void ) +{try{ + + joke(10); + joke(-10); + joke(0); + + return 0; +} +catch ( const std::exception& e ) +{ + std::cerr << std::endl + << "std::exception(\"" << e.what() << "\")." << std::endl; + return 2; +} +catch ( ... ) +{ + std::cerr << std::endl + << "unknown exception." << std::endl; + return 1; +}} +