Boost logo

Boost :

From: Brian McNamara (lorgon_at_[hidden])
Date: 2003-09-01 01:44:57

On Mon, Sep 01, 2003 at 12:13:11AM -0600, Dave Gomboc wrote:
> I've been trying to set things up so that code is written for T that can
> then also use nilable<T> seamlessly, but doing things the other way around
> might be an improvement.


> > [Brian McNamara]
> > I was originally arguing with Joel because I thought he wanted to use
> > exactly "nv" and not anything like "nv.get()". I think now that we've
> > cleared up the confusion about get() returning a reference instead of a
> > pointer, we're all back on the same page.
> Well, I guess you're still arguing with me ;-) because I _do_ want to use
> exactly "nv" and not anything like "nv.get()". I don't like get() because
> I cannot write x.get() when x is a POD. This would mean I have to support
> nilable<T> and T with different code, which is exactly what I'm trying to
> avoid.

This is trivial to fix:

   // Adapters to uniform-ify the interface
   template <class T>
   nilable<T> adapt( T x ) { return nilable<T>(x); }
   template <class T>
   nilable<T> adapt( nilable<T> x ) { return x; }

   // generic function
   template <class T>
   void do_something( nilable<T> x ) { ... }

   // examples demonstrating how code looks same regardless of type
   do_something( adapt( 3 ) );
   do_something( adapt( nilable<int>(3) ) );
   do_something( adapt( foo ) ); // foo has unknown type

-Brian McNamara (lorgon_at_[hidden])

Boost list run by bdawes at, gregod at, cpdaniel at, john at