[29 / 0 / ?]
Quoted By:
...so I wrote something that I won't understand five bits of in 5 years. See if you can understand what it does without compiling it. It's valid C++, except for the __int64 type, which is Microsoft-specific (replace with whatever your compiler uses). Have fun. #include <iostream> using namespace std; typedef __int64 pszint; /* FOR 64-BIT POINTERS */ typedef unsigned __int64 uint64; typedef const char* charptr; template<typename T> inline void For( T val, const T& end, T (*inc)( const T& ), void (*proc)( const T& ) ) { if( val < end ) { proc( val ); For( inc( val ), end, inc, proc ); } } template<typename T> inline T If( bool cond, T (*proc)(), T (*eproc)() ) { return ( cond ? proc() : eproc() ); } template<typename T, typename Q> inline Q Comp( T (*one)(), Q (*two)( const T& ) ) { return two( one() ); } //template<typename T> inline pszint TypeId() { static T tag; return (pszint) &tag; } void NullProc() {} int IncrementInt( const int& i ) { return i + 1; } uint64 GetValue() { return 36762444129608; /* BIG-ENDIAN */ } charptr ToString( const uint64& str ) { static uint64 temp; temp = str; return (charptr) &temp; } charptr GetString() { return Comp<uint64, charptr>( GetValue, ToString ); } void PrintAndPause( const charptr& str ) { cout << str; getchar(); } void InnerProc() { Comp<charptr, void>( GetString, PrintAndPause ); } void Body( const int &i ) { If<void>( i <= 5, InnerProc, NullProc ); } int main() { For<int>( 1, 10, IncrementInt, Body ); }
Anonymous
Quoted By:
God-awful template metaprogramming for a memory access violation? for i in [1,10]: if (i<=5): Print(DereferenceMemoryAt(InvalidLocation)) // segfault here? WaitForKeypress()
Anonymous
Quoted By:
Actually, I'm an idiot. I blame it on lack of sleep. Nice work with the 64bit constant to string thing.
Ikari Yui
Quoted By:
You thought it was a constant pointer (missed the &)? That'd be fun, you'd need about 34 TB of addressable RAM to run the program even if there was something meaningful there to print (and no memory safeguards in the OS) ...
Anonymous
Quoted By:
__int64 more like long long
Anonymous
Quoted By:
My guess is that it just prints out the number in GetValue() as a string five times. I don't know what it says though.
Anonymous
Quoted By:
Actually, can someone explain what TypeId does? If type T isn't the same size as pszint, wouldn't that cause problems?
Ikari Yui
Quoted By:
TypeId() declares a static variable of type T, T being the template argument that it was called with (for instance, calling TypeId<int>() will make "tag" have type int). Due to the way templates work, this means that there will be one unique instance of "tag" for each type, allocated on the first call to TypeId with that type. Now, since all instances are unique, they will have unique memory addresses which are not used for anything else = one unique ID for each type. In effect, TypeId enables run-time type identification without RTTI (which creates overhead). I commented it out because my shitty little app doesn't use it. That make any sense?
Anonymous
Quoted By:
>>8 Ah.. that's pretty clever. Though decrypting the whole thing was pretty straightforward considering the for, if, composite functions were self-describing.
Christy McJesus !DcbLlAZi7U
10 Christy McJesus !DcbLlAZi7U Wed 23 Feb 2005 20:47:00 No. 448 Report Quoted By:
Needs more intercal.
Anonymous
Quoted By:
WELCOME TO THE PAST BITCHES. FUCKING BUMP.
Anonymous
Quoted By:
WELCOME TO THE PAST BITCHES. FUCKING BUMP.
Quoted By:
GOODBYE TO THE PAST BITCHES. FUCKING SAGE.
Anonymous
Quoted By:
That's a nasty little slice of code, doesn't /prog/ think?
Anonymous
Quoted By:
Needs more SICP ed2k://|file|Mit%20Press%20-%20Structure%20And%20Interpretation%20Of%20Classical%20Mechanics(1).pdf|10934837|720CD66AE234FE38EE764A157B253889|/
Anonymous
Quoted By:
>>15 that is sicm, you dolt
Anonymous
Quoted By:
Type declaration implying DOCTYPE.
Quoted By:
64 bytes. # input pushed at start of code { # start function . # dup '\s\n' # space, newline ? # find (-1 if not space or nl) ) # increment (now >0, which is true, if space or nl) ### = "if" argument 1: condition {} # do nothing ### = "if" argument 2: do nothing if space or nl { # start block '[o][u]'# push string 3/ # divide in chunks of three 1 # push 1 ) # increment :1 # store new value in 1, giving the numeral 1 a new meaning 2% # modulo 2 = # n'th element of divided string .@\ # stack operation dup, rot, swap: [A B] -> [B A B] (; # drop first '[/' # push string \ # swap + # join strings } # end block ### = "if" argument 3: handle bbcode if not space or nl if # execute if }% # end and map function over input string '[b][i]'# push this \ # swap with input '[/i][/b]'# push this strings are printed "raw" on exit
Quoted By:
{.' '?){}{'[o][u]'3/1):1 2%=.@\(;'[/'\+}if}%'[b][i]'\'[/i][/b]' 64 bytes. # input pushed at start of code { # start function . # dup '\s\n' # space, newline ? # find (-1 if not space or nl) ) # increment (now >0, which is true, if space or nl) ### = "if" argument 1: condition {} # do nothing ### = "if" argument 2: do nothing if space or nl { # start block '[o][u]'# push string 3/ # divide in chunks of three 1 # push 1 ) # increment :1 # store new value in 1, giving the numeral 1 a new meaning 2% # modulo 2 = # n'th element of divided string .@\ # stack operation dup, rot, swap: [A B] -> [B A B] (; # drop first '[/' # push string \ # swap + # join strings } # end block ### = "if" argument 3: handle bbcode if not space or nl if # execute if }% # end and map function over input string '[b][i]'# push this \ # swap with input '[/i][/b]'# push this strings are printed "raw" on exit
Quoted By:
necrosis distending the equilibrium
Quoted By:
<--- check my dubs!!!
Anonymous
Quoted By:
Has been done to death. Yes, templates are touring-complete.
Quoted By:
You can calculate template error messages to produce ascii graphics with T's, <'s and >'s. Maybe even animations (which will be animated by the virtue of scrolling the fuck out of your terminal emulator window)
Anonymous
Anonymous