|
Boost : |
From: Brian McNamara (lorgon_at_[hidden])
Date: 2003-09-01 20:39:43
On Mon, Sep 01, 2003 at 04:05:59PM -0600, Dave Gomboc wrote:
> [Brian McNamara]
> > do_something( adapt( 3 ) );
> > do_something( adapt( nilable<int>(3) ) );
> > do_something( adapt( foo ) ); // foo has unknown type
>
> But I'd like to write
> do_something(3);
> do_something(foo); // of type T
> do_something(bar); // of type nilable<T>
>
> Can I have my cake and eat it too? ;-)
Yes:
template <class T>
void do_something( T x ) {
do_something_helper( adapt(x) );
}
template <class T>
void do_something_helper( nilable<T> x ) {
/* actually do it */
}
(Shameless plus: Note that with FC++,
do_something = compose( do_something_helper, adapt );
or
do_something = do_something_helper ^of^ adapt;
provided that things are defined as functoids.)
-- -Brian McNamara (lorgon_at_[hidden])
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk