Improve uBas integration to allow use of expression templates inside uBas templates.

Fixes #8292.

[SVN r83439]
This commit is contained in:
John Maddock
2013-03-15 17:29:20 +00:00
parent 726b2ffc32
commit 6582c85fd8
11 changed files with 117 additions and 23 deletions

View File

@@ -330,12 +330,19 @@ struct expression<tag, Arg1, void, void, void>
const Arg1& left_ref()const BOOST_NOEXCEPT { return arg; }
static const unsigned depth = left_type::depth + 1;
#ifndef BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS
explicit operator bool()const
{
result_type r(*this);
return static_cast<bool>(r);
}
#else
operator unmentionable_type()const
{
result_type r(*this);
return r ? &unmentionable::proc : 0;
}
#endif
private:
typename expression_storage<Arg1>::type arg;
@@ -355,10 +362,17 @@ struct expression<terminal, Arg1, void, void, void>
static const unsigned depth = 0;
#ifndef BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS
explicit operator bool()const
{
return static_cast<bool>(arg);
}
#else
operator unmentionable_type()const
{
return arg ? &unmentionable::proc : 0;
}
#endif
private:
typename expression_storage<Arg1>::type arg;
@@ -383,12 +397,19 @@ struct expression<tag, Arg1, Arg2, void, void>
const Arg1& left_ref()const BOOST_NOEXCEPT { return arg1; }
const Arg2& right_ref()const BOOST_NOEXCEPT { return arg2; }
#ifndef BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS
explicit operator bool()const
{
result_type r(*this);
return static_cast<bool>(r);
}
#else
operator unmentionable_type()const
{
result_type r(*this);
return r ? &unmentionable::proc : 0;
}
#endif
static const unsigned left_depth = left_type::depth + 1;
static const unsigned right_depth = right_type::depth + 1;
static const unsigned depth = left_depth > right_depth ? left_depth : right_depth;
@@ -423,12 +444,19 @@ struct expression<tag, Arg1, Arg2, Arg3, void>
const Arg2& middle_ref()const BOOST_NOEXCEPT { return arg2; }
const Arg3& right_ref()const BOOST_NOEXCEPT { return arg3; }
#ifndef BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS
explicit operator bool()const
{
result_type r(*this);
return static_cast<bool>(r);
}
#else
operator unmentionable_type()const
{
result_type r(*this);
return r ? &unmentionable::proc : 0;
}
#endif
static const unsigned left_depth = left_type::depth + 1;
static const unsigned middle_depth = middle_type::depth + 1;
static const unsigned right_depth = right_type::depth + 1;
@@ -472,12 +500,19 @@ struct expression
const Arg3& right_middle_ref()const BOOST_NOEXCEPT { return arg3; }
const Arg4& right_ref()const BOOST_NOEXCEPT { return arg4; }
#ifndef BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS
explicit operator bool()const
{
result_type r(*this);
return static_cast<bool>(r);
}
#else
operator unmentionable_type()const
{
result_type r(*this);
return r ? &unmentionable::proc : 0;
}
#endif
static const unsigned left_depth = left_type::depth + 1;
static const unsigned left_middle_depth = left_middle_type::depth + 1;
static const unsigned right_middle_depth = right_middle_type::depth + 1;

View File

@@ -541,13 +541,19 @@ public:
//
// Use in boolean context:
//
#ifndef BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS
BOOST_MP_FORCEINLINE explicit operator bool()const
{
return !is_zero();
}
#else
typedef bool (self_type::*unmentionable_type)()const;
BOOST_MP_FORCEINLINE operator unmentionable_type()const
{
return is_zero() ? 0 : &self_type::is_zero;
}
#endif
//
// swap:
//
@@ -623,11 +629,12 @@ public:
{
return this->template convert_to<T>();
}
/*
explicit operator bool()const
{
using default_ops::eval_is_zero;
return !eval_is_zero(backend());
}
}*/
explicit operator void()const {}
#endif
#endif
@@ -1764,26 +1771,12 @@ inline multiprecision::number<T, ExpressionTemplates> denominator(const rational
return a.denominator();
}
namespace numeric { namespace ublas {
//
// uBlas interoperability:
//
template<class V>
class sparse_vector_element;
template <class V, class Backend, multiprecision::expression_template_option ExpressionTemplates>
inline bool operator == (const sparse_vector_element<V>& a, const ::boost::multiprecision::number<Backend, ExpressionTemplates>& b)
{
typedef typename sparse_vector_element<V>::const_reference ref_type;
return static_cast<ref_type>(a) == b;
}
}} // namespaces
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
} // namespaces
#include <boost/multiprecision/detail/ublas_interop.hpp>
#endif