|
Boost Users : |
From: Robert Dailey (rcdailey_at_[hidden])
Date: 2007-12-12 10:07:28
Are function calls allowed to default initialize a construction parameter?
Does the compiler turn the function into a constant? How does that work? I
wasn't aware you could do this...
On Dec 11, 2007 8:02 PM, Stjepan Rajko <stipe_at_[hidden]> wrote:
> On Dec 11, 2007 1:03 PM, Robert Dailey <rcdailey_at_[hidden]> wrote:
> >
> > template< typename T >
> > struct default_alpha;
> >
> > template<>
> > struct default_alpha<float>
> > {
> > static const float value = 1.0f; // Note that this is not legal. I'm
> > simply just presenting pseudo code.
> >
> > };
> >
> > template<>
> > struct default_alpha<unsigned char>
> > {
> > static const unsigned char value = 255;
> > };
> >
> >
> > template< typename T >
> > class Color
> > {
> > Color( T r, T g, T b, T a = default_alpha<T>::value );
> > };
> >
>
> So why not use Jeff Flinn's suggestion:
>
> template< typename T >
> struct default_alpha;
>
> template<>
> struct default_alpha<float>
> {
> static float value() { return 1.0f; }
> };
>
> template<>
> struct default_alpha<unsigned char>
> {
> static unsigned char value() { return 255; }
> };
>
> template< typename T >
> class Color
> {
> public:
> Color( T r, T g, T b, T a = default_alpha<T>::value() );
> };
>
>
> ...?
>
> Stjepan
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net