Boost logo

Boost Users :

From: François Duranleau (duranlef_at_[hidden])
Date: 2006-08-22 12:43:57


On Mon, 21 Aug 2006, chun ping wang wrote:

[...]
> template <class T>
> boost::function<void*(const T&, const T&, const T&)> getVerxFunc3()
> {
> BOOST_STATIC_ASSERT(boost::is_integral<T>::value ||
> boost::is_floating_point<T>::value);
> return (boost::is_integral<T>::value) ? &glVertex3i : &glVertex3d;
> }
>
[...]
>
> template <class T>
> void drawDot(const T& x, const T& y, const T& z) {
> boost::function<void(const T&, const T&, const T&)>
> myFunc(getVerxFunc3<T>());
> glBegin(GL_POINTS);
> myFunc(x, y, z);
> glEnd();
> glFlush();
> }
>
[just kept one example from the above]

Isn't using boost::function overkill here? I would rather do this:

template < typename T >
void gl_vertex( const T& x , const T& y , const T& z )
{
     // you can use the BOOST_STATIC_ASSERT as above here, or use
     // boost::enable_if with the same condition around the void return

     if ( boost::is_floating_point< T >::value )
     {
         glVertex3d( x , y , z ) ;
     }
     else
     {
         glVertex3i( x , y , z ) ;
     }
}

or even simply this:

void gl_vertex( GLdouble x , GLdouble y , GLdouble z )
{
     glVertex3d( x , y , z ) ;
}

void gl_vertex( GLint x , GLint y , GLint z )
{
     glVertex3i( x , y , z ) ;
}

and then:

template < typename T >
void drawDot( const T& x , const T& y , const T& z )
{
     glBegin( GL_POINTS ) ;
     gl_vertex( x , y , z ) ;
     glEnd() ;
}

That should be more efficient and, especially for the second case, is a
simpler to read overall.

Anyway, just my two cents.

-- 
François Duranleau
LIGUM, Université de Montréal
"Sacrifices are a necessary factor in creating a new destiny. A small
  misfortune becomes the cornerstone of a greater happiness."
                          - Emperor Dornkirk, in _The Vision of Escaflowne_

_______________________________________________
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