Skip to content

template aliases

November 8, 2011

Template aliases have just been implemented in GCC. Essentially they are a template typedef. Before now, the only way to typedef templated types was to create the full type with all the parameters set. Now you can only bind some of the parameters. For the functional programmers, this is partial function application for templates.

Here is an example of how to use it:

template <typename A, typename B>
class X;

template <typename F>
using Xint = X<F, int>;

This declares an alias Xint which is templated with one parameter. It is just an alias for X where the second parameter has been fixed to int, and the first parameter comes from the parameter to Xint.

Advertisements

From → Language, Templates

2 Comments
  1. Shreehari permalink

    dude, i think you’re missing a semi colon after
    using Xint = X

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

%d bloggers like this: