C ++ for Perl programmers

    There is an old joke that a Fortran programmer will write in Fortran in any programming language.

    Here is a 3-line program that compiles with any C ++ 11 compiler, after which it starts and works fine.
    int main(){
        return !<:]()<%;[=:>(){<:&](){;%>();%>();};

    An example in the Online IDE
    In principle, this line can be used as a detector for C ++ programmers - not everyone can immediately understand how it works.

    The post was written as a social experiment. From my point of view, a professional should thoroughly understand his tool. If you guessed what is happening in the code - write in the comments.

    In order not to lose the intrigue, the explanation under the spoiler:
    int main(){
        return ![](){;  

    Just some characters are replaced by digraphs.
    Digraphs are part of the language and the standard of ISO C 99 Digraphs . For C ++, there are Trigraphs . True, in most C ++ compilers, trigraphs are disabled by default. But the digraph digraphs are included.

    All these * -graphs appeared because the seven-bit ISO / IEC 646 code page (1972) assigned some characters [,], {,}, ^, ~ to national characters, so it was necessary to ensure compatibility of the source code with the new standard. So <: is the equivalent of an opening square bracket.

    Time passed, the 21st century came, everyone began to use UTF-8, but digraphs remained in the standard. And what is most disgusting, in many legacy projects are still found. So do not be alarmed by seeing this in the old source

    Also popular now: