Boost logo

Boost :

From: Mat Marcus (mmarcus_at_[hidden])
Date: 2001-12-06 14:05:08


Daryle,

Here is a solution in a different style (untested off the top of my head):

#include <limits>
#include <boost/config.hpp>
#include <boost/mpl/select_type.hpp> // compile time if

// ...
namespace detail {
struct gcd_euclidean_evaluator
{
  template < typename T>
  static inline T execute ( T const &a, T const &b )
    {
      return gcd_euclidean( a, b );
    }
};

struct gcd_integer_evaluator
{
  template < typename T >
  static inline T execute ( T const &a, T const &b )
    {
      return gcd_integer( a, b );
    }
};
} // namespace detail

template < typename T >
struct gcd_optimal_evaluator
{
private:
  typedef ::std::numeric_limits<T> limits_type;
  BOOST_STATIC_CONSTANT(bool,
    use_integer = limits_type::is_specialized && limits_type::is_signed);

  typedef typename ::boost::mpl::select_type<use_integer,
                         detail::gcd_integer_evaluator,
                         detail::gcd_euclidean_evaluator
>::type evaluator;

public:
  static inline T execute( T const &a, T const &b )
    {
      return evaluator::execute(a, b);
    }
};

// - Mat

-----Original Message-----
From: David Abrahams [mailto:david.abrahams_at_[hidden]]
Sent: Wednesday, December 05, 2001 9:03 PM
To: boost_at_[hidden]
Subject: Re: [boost] Need help converting code for MSVC

Daryle,

let's narrow this to where the partial specialization occurs:

----- Original Message -----

> // Function objects to find the best way of computing GCD or LCM
> template < typename T, bool IsSpecialized, bool IsSigned >
> struct gcd_optimal_evaluator_helper
> {
> T operator ()( T const &a, T const &b )
> {
> return gcd_euclidean( a, b );
> }
> };
>
> template < typename T >
> struct gcd_optimal_evaluator_helper< T, true, true >
> {
> T operator ()( T const &a, T const &b )
> {
> return gcd_integer( a, b );
> }
> };

The trick is to use "poor man's partial specialization". First break the
template into two parts:

// untested
template <bool IsSpecialized, bool IsSigned>
struct gcd_optimal_evaluator_helper_outer
{
    template <class T>
    struct inner
    {
          T operator ()( T const &a, T const &b )
          {
              return gcd_euclidean( a, b );
          }
    };
};

// now you can fully specialize:

template <>
struct gcd_optimal_evaluator_helper_outer<true,true>
{
    template <class T>
    struct inner
    {
          T operator ()( T const &a, T const &b )
          {
              return gcd_integer( a, b );
          }
    };
};

and finally:

template < typename T, bool IsSpecialized, bool IsSigned >
struct gcd_optimal_evaluator_helper
    : gcd_optimal_evaluator_helper_outer<IsSpecialized,IsSigned>
        ::BOOST_NESTED_TEMPLATE inner<T>
    {};

I'm sure you can apply the same transformation to
lcm_optimal_evaluator_helper. If you can get this to work with your
compiler, you stand a good chance that it'll work with MSVC6 too.

-Dave

Info: http://www.boost.org Send unsubscribe requests to:
<mailto:boost-unsubscribe_at_[hidden]>

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk