Skip to content

Instantly share code, notes, and snippets.

@mrpollo
Last active February 3, 2016 07:29
Show Gist options
  • Save mrpollo/0e530f8108c4748e8479 to your computer and use it in GitHub Desktop.
Save mrpollo/0e530f8108c4748e8479 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string>
#include <stdint.h>
#include <unistd.h> // for abort
#include <string.h> // for strerror
#include <errno.h>
#include <stdlib.h>
#include <memory>
#include <string>
// from: http://stackoverflow.com/questions/2342162/stdstring-formatting-like-sprintf
template<typename ... Args>
std::string
string_format( const char* format, const Args ... args )
{
int32_t size = snprintf( nullptr, 0, format, args ... );
if (size < 0) {
::fprintf(stderr, "snprintf error (%d): %s\n", size, strerror(errno));
abort();
}
size += 1; // Extra space for '\0'
std::unique_ptr<char[]> buf( new char[ size ] );
snprintf( buf.get(), size, format, args ... );
return std::string( buf.get(), buf.get() + size - 1 ); // We don't want the '\0' inside
}
int
main(int argc, char*argv[])
{
std::string objectname = "";
for (uint8_t i=1; i<=100; i++) {
if (i != 1) {
objectname += ", ";
}
objectname += string_format("_%d", i);
::fprintf(stderr, "class Tuple%d{public Object %s;}\n", i, objectname.c_str());
}
}
for i=1:100;println("class Tuple$i {public Object _$(join(0:i-1,",_"));}");end
local $" = ", "; foreach (0..100) { push @objects, "_${_}"; print "class Tuple$_\{public Object @objects;\}\n"; }
0.upto(100){|i|puts "class Tuple#{i} {public Object _#{(0...i).to_a.join ',_'};}"}
@rtoal
Copy link

rtoal commented Feb 3, 2016

for i=1:100;println("class Tuple$i {public Object _$(join(0:i-1,",_"));}");end #Julia

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment