|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r59374 - trunk/boost/accumulators/numeric/functional
From: eric_at_[hidden]
Date: 2010-01-30 19:27:22
Author: eric_niebler
Date: 2010-01-30 19:27:21 EST (Sat, 30 Jan 2010)
New Revision: 59374
URL: http://svn.boost.org/trac/boost/changeset/59374
Log:
avoid premature template evaluation in operator overload return types
Text files modified:
trunk/boost/accumulators/numeric/functional/valarray.hpp | 21 +++++++++++++++------
trunk/boost/accumulators/numeric/functional/vector.hpp | 21 +++++++++++++++------
2 files changed, 30 insertions(+), 12 deletions(-)
Modified: trunk/boost/accumulators/numeric/functional/valarray.hpp
==============================================================================
--- trunk/boost/accumulators/numeric/functional/valarray.hpp (original)
+++ trunk/boost/accumulators/numeric/functional/valarray.hpp 2010-01-30 19:27:21 EST (Sat, 30 Jan 2010)
@@ -29,12 +29,21 @@
{
namespace operators
{
+ namespace detail
+ {
+ template<typename Fun>
+ struct make_valarray
+ {
+ typedef std::valarray<typename Fun::result_type> type;
+ };
+ }
+
///////////////////////////////////////////////////////////////////////////////
// Handle valarray<Left> / Right where Right is a scalar and Right != Left.
template<typename Left, typename Right>
- typename enable_if<
+ typename lazy_enable_if<
mpl::and_<is_scalar<Right>, mpl::not_<is_same<Left, Right> > >
- , std::valarray<typename functional::divides<Left, Right>::result_type>
+ , detail::make_valarray<functional::divides<Left, Right> >
>::type
operator /(std::valarray<Left> const &left, Right const &right)
{
@@ -50,9 +59,9 @@
///////////////////////////////////////////////////////////////////////////////
// Handle valarray<Left> * Right where Right is a scalar and Right != Left.
template<typename Left, typename Right>
- typename enable_if<
+ typename lazy_enable_if<
mpl::and_<is_scalar<Right>, mpl::not_<is_same<Left, Right> > >
- , std::valarray<typename functional::multiplies<Left, Right>::result_type>
+ , detail::make_valarray<functional::multiplies<Left, Right> >
>::type
operator *(std::valarray<Left> const &left, Right const &right)
{
@@ -68,9 +77,9 @@
///////////////////////////////////////////////////////////////////////////////
// Handle valarray<Left> + valarray<Right> where Right != Left.
template<typename Left, typename Right>
- typename disable_if<
+ typename lazy_disable_if<
is_same<Left, Right>
- , std::valarray<typename functional::plus<Left, Right>::result_type>
+ , detail::make_valarray<functional::plus<Left, Right> >
>::type
operator +(std::valarray<Left> const &left, std::valarray<Right> const &right)
{
Modified: trunk/boost/accumulators/numeric/functional/vector.hpp
==============================================================================
--- trunk/boost/accumulators/numeric/functional/vector.hpp (original)
+++ trunk/boost/accumulators/numeric/functional/vector.hpp 2010-01-30 19:27:21 EST (Sat, 30 Jan 2010)
@@ -28,12 +28,21 @@
{
namespace operators
{
+ namespace detail
+ {
+ template<typename Fun>
+ struct make_vector
+ {
+ typedef std::vector<typename Fun::result_type> type;
+ };
+ }
+
///////////////////////////////////////////////////////////////////////////////
// Handle vector<Left> / Right where Right is a scalar.
template<typename Left, typename Right>
- typename enable_if<
+ typename lazy_enable_if<
is_scalar<Right>
- , std::vector<typename functional::divides<Left, Right>::result_type>
+ , detail::make_vector<functional::divides<Left, Right> >
>::type
operator /(std::vector<Left> const &left, Right const &right)
{
@@ -64,9 +73,9 @@
///////////////////////////////////////////////////////////////////////////////
// Handle vector<Left> * Right where Right is a scalar.
template<typename Left, typename Right>
- typename enable_if<
+ typename lazy_enable_if<
is_scalar<Right>
- , std::vector<typename functional::multiplies<Left, Right>::result_type>
+ , detail::make_vector<functional::multiplies<Left, Right> >
>::type
operator *(std::vector<Left> const &left, Right const &right)
{
@@ -82,9 +91,9 @@
///////////////////////////////////////////////////////////////////////////////
// Handle Left * vector<Right> where Left is a scalar.
template<typename Left, typename Right>
- typename enable_if<
+ typename lazy_enable_if<
is_scalar<Left>
- , std::vector<typename functional::multiplies<Left, Right>::result_type>
+ , detail::make_vector<functional::multiplies<Left, Right> >
>::type
operator *(Left const &left, std::vector<Right> const &right)
{
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