Perl macros for GLIC

Speaking of templates, here’s their all-powerful replacement (or complement, probably) in GLIC:

    macro class PrintName {
        # Transition to Perl code (should probably be more clearly marked)
        sub GENERATE {
            my ($class, @params) = @_;
            my $template = join(', ', map { $_->name } @params);
            <<CODE;
                void print() { cout << "My name is $class<$template>\n" }
CODE
        }
    };
    PrintName<int> p;
    p.print();       // "My name is PrintName<int>"

Do you have any idea how powerful that is!? And the best part: Do you have any idea how damn easy that is to implement!? So, yay.

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s