07.03.2013 Views

here - Chara - University of Illinois at Urbana-Champaign

here - Chara - University of Illinois at Urbana-Champaign

here - Chara - University of Illinois at Urbana-Champaign

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Lecture<br />

04—Templ<strong>at</strong>e<br />

P<strong>at</strong>terns I<br />

Chase Geigle<br />

Announcements<br />

Templ<strong>at</strong>e<br />

Specializ<strong>at</strong>ion<br />

Partial<br />

Templ<strong>at</strong>e<br />

Specializ<strong>at</strong>ion<br />

Templ<strong>at</strong>e<br />

Templ<strong>at</strong>e<br />

Parameters<br />

Next Time<br />

Example Cont’d<br />

#include <br />

#include <br />

templ<strong>at</strong>e <br />

class vector {<br />

public:<br />

bool oper<strong>at</strong>or[]( size_t i ) {<br />

size_t idx = i / 8;<br />

// I hope this is correct...<br />

return ( d<strong>at</strong>a_[ idx ] >> ( 7 - ( i % 8 ) ) ) & 1;<br />

}<br />

// other things<br />

priv<strong>at</strong>e:<br />

uint8_t * d<strong>at</strong>a_;<br />

};<br />

The decision to keep the same interface was arbitrary<br />

No requirement to do so! In fact, it may make sense to<br />

have a different interface for your specializ<strong>at</strong>ions.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!