Boost logo

Boost :

From: Markus Werle (numerical.simulation_at_[hidden])
Date: 2008-08-07 05:53:26


Here is my "workaround", which is ugly, but works until this is fixed

#include <cmath>
#include <cstdlib>
#include <algorithm>

#include <boost/numeric/ublas/detail/config.hpp>

namespace boost { namespace numeric { namespace ublas {

    template<class T>
    struct type_traits;

    template<class T>
    struct scalar_traits;

    template<>
    struct scalar_traits<double> {
        typedef scalar_traits<double> self_type;
        typedef double value_type;
        typedef const double &const_reference;
        typedef double &reference;

        typedef double real_type;
        typedef real_type precision_type; // we do not know what type has
more precision then the real_type

        static const unsigned plus_complexity = 1;
        static const unsigned multiplies_complexity = 1;

        static
        BOOST_UBLAS_INLINE
        real_type real (const_reference t) {
                return t;
        }
        static
        BOOST_UBLAS_INLINE
        real_type imag (const_reference /*t*/) {
                return 0;
        }
        static
        BOOST_UBLAS_INLINE
        value_type conj (const_reference t) {
                return t;
        }

        static
        BOOST_UBLAS_INLINE
        real_type type_abs (const_reference t) {
            // we'll find either std::abs or else another version via ADL:
            using namespace std;
            return abs (t);
        }
        static
        BOOST_UBLAS_INLINE
        value_type type_sqrt (const_reference t) {
            using namespace std;
            // force a type conversion back to value_type for intgral types
            // we'll find either std::sqrt or else another version via ADL:
            return value_type (sqrt (t));
        }

        static
        BOOST_UBLAS_INLINE
        real_type norm_1 (const_reference t) {
            return self_type::type_abs (t);
        }
        static
        BOOST_UBLAS_INLINE
        real_type norm_2 (const_reference t) {
            return self_type::type_abs (t);
        }
        static
        BOOST_UBLAS_INLINE
        real_type norm_inf (const_reference t) {
            return self_type::type_abs (t);
        }

        static
        BOOST_UBLAS_INLINE
        bool equals (const_reference t1, const_reference t2) {
                        static double const eps =
                                std::sqrt(std::numeric_limits<double>::epsilon
());
                        
            return ((t1 - t2)
                                        <
                                        eps
                                        *
                                        (std::max)(((std::max)(std::abs(t1),
std::abs(t2))),
                                                           std::sqrt
((std::numeric_limits<double>::min)())));
        }
    };
}}}

#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/interval.hpp>

namespace ublas = boost::numeric::ublas;

void trigger_ublas_compile_error()
{
        ublas::vector<double> boom = ublas::zero_vector<double>(5);
}


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