|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r77340 - sandbox/big_number/boost/multiprecision
From: john_at_[hidden]
Date: 2012-03-15 06:47:49
Author: johnmaddock
Date: 2012-03-15 06:47:48 EDT (Thu, 15 Mar 2012)
New Revision: 77340
URL: http://svn.boost.org/trac/boost/changeset/77340
Log:
Allow construction/assignment from expression templates that yield a different type to *this.
Text files modified:
sandbox/big_number/boost/multiprecision/mp_number.hpp | 21 +++++++++++++++++++--
1 files changed, 19 insertions(+), 2 deletions(-)
Modified: sandbox/big_number/boost/multiprecision/mp_number.hpp
==============================================================================
--- sandbox/big_number/boost/multiprecision/mp_number.hpp (original)
+++ sandbox/big_number/boost/multiprecision/mp_number.hpp 2012-03-15 06:47:48 EDT (Thu, 15 Mar 2012)
@@ -77,7 +77,8 @@
template <class tag, class Arg1, class Arg2, class Arg3>
mp_number& operator=(const detail::mp_exp<tag, Arg1, Arg2, Arg3>& e)
{
- do_assign(e, tag());
+ typedef typename is_same<mp_number, typename detail::mp_exp<tag, Arg1, Arg2, Arg3>::result_type>::type tag_type;
+ do_assign(e, tag_type());
return *this;
}
@@ -121,7 +122,7 @@
template <class tag, class Arg1, class Arg2, class Arg3>
mp_number(const detail::mp_exp<tag, Arg1, Arg2, Arg3>& e)
{
- do_assign(e, tag());
+ *this = e;
}
#ifndef BOOST_NO_RVALUE_REFERENCES
@@ -538,6 +539,22 @@
return m_backend;
}
private:
+ template <class tag, class Arg1, class Arg2, class Arg3>
+ void do_assign(const detail::mp_exp<tag, Arg1, Arg2, Arg3>& e, const mpl::true_&)
+ {
+ do_assign(e, tag());
+ }
+ template <class tag, class Arg1, class Arg2, class Arg3>
+ void do_assign(const detail::mp_exp<tag, Arg1, Arg2, Arg3>& e, const mpl::false_&)
+ {
+ // The result of the expression isn't the same type as this -
+ // create a temporary result and assign it to *this:
+ typedef typename detail::mp_exp<tag, Arg1, Arg2, Arg3>::result_type temp_type;
+ temp_type t(e);
+ *this = t;
+ }
+
+
template <class V>
void check_shift_range(V val, const mpl::true_&, const mpl::true_&)
{
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk