1

I remember a library (a single header I think) based on templates and operators overloading that allowed to visualize 2D and 3D shapes in code, with expressions like:

assert( (I-----o
         |     |
         o-----I).area() == (I---o
                             |   |
                             |   |
                             o---I).area() );

And even more complicated stuff for 3D shapes.

I had a link to this library but can't find the link... (I may have bookmarked it, but can't find the bookmark). Google is not much helpful either, at least not with my search keywords.

Anybody knows what I'm talking about?

Amir Kirsh
  • 12,564
  • 41
  • 74
  • http://www.eelis.net/C++/analogliterals.xhtml ? – StoryTeller - Unslander Monica Oct 13 '20 at 14:07
  • @StoryTeller-UnslanderMonica YES! Thanks man! Hurry-up to post it as an answer before the question is voted for being closed :-/ – Amir Kirsh Oct 13 '20 at 14:17
  • And here is where I saw it before! After having the link it's easier to locate it: [Undefined behavior and sequence Points reloaded](https://stackoverflow.com/questions/4638364/undefined-behavior-and-sequence-points-reloaded/4640419#4640419). Appears also here: [What is the most hard to understand piece of C++ code you know?](https://stackoverflow.com/questions/178265/what-is-the-most-hard-to-understand-piece-of-c-code-you-know/178446#178446). – Amir Kirsh Oct 13 '20 at 16:02
  • ... and here: [“Fun” C++ library that interprets ASCII figures in code - what is it called? (“Multi-Dimensional Analog Literals”)](https://stackoverflow.com/questions/885819/fun-c-library-that-interprets-ascii-figures-in-code-what-is-it-called-m). – Amir Kirsh Oct 13 '20 at 16:03

1 Answers1

1

Thanks to Story Teller, the link is: http://www.eelis.net/C++/analogliterals.xhtml

With a fork here: https://github.com/Quuxplusone/analog-literals

Some actual code examples:

  unsigned int c = ( o-----o
                     |     !
                     !     !
                     !     !
                     o-----o ).area;

  assert( c == (I-----I) * (I-------I) );

  assert( ( o-----o
            |     !
            !     !
            !     !
            !     !
            o-----o ).area == ( o---------o
                                |         !
                                !         !
                                o---------o ).area );

And with 3D shapes:

  assert( top( o-------o
               |L       \
               | L       \
               |  o-------o
               |  !       !
               !  !       !
               o  |       !
                L |       !
                 L|       !
                  o-------o ) == ( o-------o
                                   |       !
                                   !       !
                                   o-------o ) );

  assert( ( o-------------o
            |L             \
            | L             \
            |  L             \
            |   o-------------o
            |   !             !
            !   !             !
            o   |             !
             L  |             !
              L |             !
               L|             !
                o-------------o ).volume == ( o-------------o
                                              |             !
                                              !             !
                                              !             !
                                              o-------------o ).area
                                                   * int(I-------------I) );

And it is mentioned in other SO posts, added in comments to the question.

Amir Kirsh
  • 12,564
  • 41
  • 74