1. Home
  2. Computing & Technology
  3. C / C++ / C#
photo of David Bolton
David's C / C++ / C# Blog

By David Bolton, About.com Guide to C / C++ / C#

A Different kind of Visual(ish) C++!

Wednesday October 8, 2008
I think this is interesting, ingenious and also very odd! It's a C++ library (well header file) that lets you have Multi Dimensional Analog literals. It's using standard C++ operators to replace a literal like 4 with

unsigned int b = I---------I;
unsigned int a = 4;
assert( a == b ) ;

The assert is there just to prove that b is really 4. The number of dashes between two two I's is 9. Due to the way C++ operators work, the number of dashes must be = 2*n + 1. If you think that's odd, what about 2 dimensions? These one-dimensional analog literals are of type analog_literals::line, which is convertible to unsigned int.

Moving into two dimensions...

analog_literals::rectangle<X, Y>
  unsigned int c = ( o-----o
                      |
                      !
                      !
                      o-----o ).area;

I can't see myself ever making use of Analog Literals but if you want to try something a bit "out there"!

Comments

No comments yet. Leave a Comment

Leave a Comment

Line and paragraph breaks are automatic. Some HTML allowed: <a href="" title="">, <b>, <i>, <strike>

Explore C / C++ / C#
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. C / C++ / C#

©2009 About.com, a part of The New York Times Company.

All rights reserved.