Auf Kommentar antworten

C++ ASCII literals

I didn't invent it! But as I can't find the original code, here is my own version. The idea was most likely inspired by the somewhat cleverer, but no more useful analogue literals.

Create your own ASCII art, drawing it directly in the source code. Can you think of anything more beautiful?!

#include <iostream>
#include <string>
#include <algorithm>
#include <iterator>

struct AsciiLiteral
{
    AsciiLiteral() : n(false) {}
    AsciiLiteral& operator--() { val += "  "; return *this; }
    AsciiLiteral& operator-() { val += ' '; return *this; }
    AsciiLiteral& operator++() { val += "**"; return *this; }
    AsciiLiteral& operator+() { val += '*'; return *this; }
    AsciiLiteral& operator~() { val += '='; return *this; }
    AsciiLiteral& operator!() { if (n = !n, n) val += '\n'; return *this; }
    AsciiLiteral& operator*() { val += '@'; return *this; }
    operator bool() const { return false; }
    std::string const& value() const { return val; }
private:
    std::string val;
    bool n;
};

std::ostream&
operator<<(std::ostream& o, AsciiLiteral const& l)
{
    std::copy(l.value().rbegin(), l.value().rend(),
            std::ostream_iterator<char>(o));
    return o;
}

int main()
{

    std::cout <<
    !--------------------------------*+********+*-----------------------------------!
    !-----------------------------******************--------------------------------!
    !----------------------------+*******************+*-----------------------------!
    !---------------------------************************+---------------------------!
    !--------------------------+*************************+--------------------------!
    !--------------------------***************************+-------------------------!
    !--------------------------***+++********++++*********+-------------------------!
    !-------------------------***+---++*****+-----+********-------------------------!
    !-------------------------+**--**--****+--***--********-------------------------!
    !-------------------------+**-***--****+-****--+*******-------------------------!
    !-------------------------~**-~**--****+*-**~--********-------------------------!
    !--------------------------**-++++++**+++++*---********-------------------------!
    !--------------------------**+++++*++++*+++++++********-------------------------!
    !--------------------------+*~++++~++++~+++++~+**********-----------------------!
    !--------------------------+***++++++++++++~---**********-----------------------!
    !--------------------------+**+-~++++++++~-----+***********---------------------!
    !-------------------------***-----~++++~--------~***********--------------------!
    !-----------------------*****---------------------~**********-------------------!
    !---------------------*****-------------------------~**********-----------------!
    !-------------------******+--------------------------***********----------------!
    !------------------******+~--------------------------************---------------!
    !-----------------*******+++*-----------*-------**++++***********+*-------------!
    !----------------********~~------~+++~~------------~~++*************------------!
    !----------------******------------+------------------~++************-----------!
    !---------------+****+~------------+--------------------~************+----------!
    !--------------******--------------+---------------------++************---------!
    !--------------****+~------------------------------------++************---------!
    !--------------****---------------*----------------------++*************--------!
    !----------*+******---------------+----------------------++************++-------!
    !----------********---------------+----------------------++*************+-------!
    !----------********---------------+----------------------++*************+-------!
    !----------~+******---------------~----------------------++************+~-------!
    !------------*+*-**+*-----------------------------------*+*************~--------!
    !----------++++++*~**+*------------+------------------*++-***********~+---------!
    !--*+++++++++++++++*~*****----------------------------++++~********~+++*--------!
    !--++++++++++++++++++*~*****--------------------------+++++*~****~++++++*-------!
    !--++++++++++++++++++++*~****+*-----------------------+++++++*~~+++++++++-------!
    !--~+++++++++++++++++++++*~**+~---------------------*~++++++++++++++++++++**----!
    !----+++++++++++++++++++++*~**--------------------*++-+++++++++++++++++++++++---!
    !--*+++++++++++++++++++++++*-**---------------*++****-+++++++++++++++++++++++---!
    !--+++++++++++++++++++++++++*~*****--------*++*******-++++++++++++++++++++~-----!
    !--~+++++++++++++++++++++++++-***********************-+++++++++++++++++~--------!
    !----~+++++++++++++++++++++++-***********************-+++++++++++++++~----------!
    !--------~++++++++++++++++++++******++~~~++**********-~++++++++++++~------------!
    !-------------~~+*++++++++++~-------------------------*+~++++++~~---------------!
    AsciiLiteral();
}

Warning: some compilers can't handle the number of chained function calls needed to compile the code. GCC can.

Antworten

  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen

CAPTCHA
Diese Frage prüft, ob Sie ein Mensch sind und kein Bot, um Spam vorzubeugen.
Bild-CAPTCHA
Enter the characters shown in the image.