Chris@16: // Boost.Units - A C++ library for zero-overhead dimensional analysis and Chris@16: // unit/quantity manipulation and conversion Chris@16: // Chris@16: // Copyright (C) 2003-2008 Matthias Christian Schabel Chris@16: // Copyright (C) 2008 Steven Watanabe Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. (See Chris@16: // accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: // $Id: lambda.hpp 27 2008-06-16 14:50:58Z maehne $ Chris@16: Chris@16: #ifndef BOOST_UNITS_LAMBDA_HPP Chris@16: #define BOOST_UNITS_LAMBDA_HPP Chris@16: Chris@16: Chris@16: //////////////////////////////////////////////////////////////////////// Chris@16: /// Chris@16: /// \file lambda.hpp Chris@16: /// Chris@16: /// \brief Definitions to ease the usage of Boost.Units' quantity, Chris@16: /// unit, and absolute types in functors created with the Chris@16: /// Boost.Lambda library. Chris@16: /// Chris@16: /// \author Torsten Maehne Chris@16: /// \date 2008-06-16 Chris@16: /// Chris@16: /// Boost.Lambda's return type deduction system is extented to make Chris@16: /// use of Boost.Units' typeof_helper trait classes for Boost.Units' Chris@16: /// quantity, absolute, and unit template classes. Chris@16: /// Chris@16: //////////////////////////////////////////////////////////////////////// Chris@16: Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost { Chris@16: Chris@16: namespace lambda { Chris@16: Chris@16: /// Partial specialization of return type trait for action Chris@16: /// unit * Y. Chris@16: template Chris@16: struct plain_return_type_2, Chris@16: boost::units::unit, Chris@16: Y > { Chris@16: typedef typename boost::units::multiply_typeof_helper< Chris@16: boost::units::unit, Y >::type type; Chris@16: }; Chris@16: Chris@16: } // namespace lambda Chris@16: Chris@16: namespace units { Chris@16: Chris@16: template Chris@16: struct multiply_typeof_helper, boost::lambda::lambda_functor > { Chris@16: typedef boost::lambda::lambda_functor< Chris@16: boost::lambda::lambda_functor_base< Chris@16: boost::lambda::arithmetic_action, Chris@16: tuple >::type, boost::lambda::lambda_functor > Chris@16: > Chris@16: > type; Chris@16: }; Chris@16: Chris@16: /// Disambiguating overload for action Chris@16: /// unit * lambda_functor Chris@16: /// based on \. Chris@16: template Chris@16: inline const typename multiply_typeof_helper, boost::lambda::lambda_functor >::type Chris@16: operator*(const boost::units::unit& a, Chris@16: const boost::lambda::lambda_functor& b) { Chris@16: return typename multiply_typeof_helper, boost::lambda::lambda_functor >::type::inherited Chris@16: (tuple >::type, Chris@16: boost::lambda::lambda_functor > Chris@16: (a, b)); Chris@16: } Chris@16: Chris@16: } // namespace units Chris@16: Chris@16: namespace lambda { Chris@16: Chris@16: /// Partial specialization of return type trait for action Chris@16: /// unit / Y. Chris@16: template Chris@16: struct plain_return_type_2, Chris@16: boost::units::unit, Chris@16: Y > { Chris@16: typedef typename boost::units::divide_typeof_helper< Chris@16: boost::units::unit, Y >::type type; Chris@16: }; Chris@16: Chris@16: } // namespace lambda Chris@16: Chris@16: namespace units { Chris@16: Chris@16: template Chris@16: struct divide_typeof_helper, boost::lambda::lambda_functor > { Chris@16: typedef boost::lambda::lambda_functor< Chris@16: boost::lambda::lambda_functor_base< Chris@16: boost::lambda::arithmetic_action, Chris@16: tuple >::type, boost::lambda::lambda_functor > Chris@16: > Chris@16: > type; Chris@16: }; Chris@16: Chris@16: /// Disambiguating overload for action Chris@16: /// unit / lambda_functor Chris@16: /// based on \. Chris@16: template Chris@16: inline const typename divide_typeof_helper, boost::lambda::lambda_functor >::type Chris@16: operator/(const boost::units::unit& a, Chris@16: const boost::lambda::lambda_functor& b) { Chris@16: return typename divide_typeof_helper, boost::lambda::lambda_functor >::type::inherited Chris@16: (tuple >::type, Chris@16: boost::lambda::lambda_functor > Chris@16: (a, b)); Chris@16: } Chris@16: Chris@16: } // namespace units Chris@16: Chris@16: namespace lambda { Chris@16: Chris@16: /// Partial specialization of return type trait for action Chris@16: /// Y * unit. Chris@16: template Chris@16: struct plain_return_type_2, Chris@16: Y, Chris@16: boost::units::unit > { Chris@16: typedef typename boost::units::multiply_typeof_helper< Chris@16: Y, boost::units::unit >::type type; Chris@16: }; Chris@16: Chris@16: } // namespace lambda Chris@16: Chris@16: namespace units { Chris@16: Chris@16: template Chris@16: struct multiply_typeof_helper, boost::units::unit > { Chris@16: typedef boost::lambda::lambda_functor< Chris@16: boost::lambda::lambda_functor_base< Chris@16: boost::lambda::arithmetic_action, Chris@16: tuple, typename boost::lambda::const_copy_argument >::type> Chris@16: > Chris@16: > type; Chris@16: }; Chris@16: Chris@16: /// Disambiguating overload for action Chris@16: /// lambda_functor * unit Chris@16: /// based on \. Chris@16: template Chris@16: inline const typename multiply_typeof_helper, boost::units::unit >::type Chris@16: operator*(const boost::lambda::lambda_functor& a, Chris@16: const boost::units::unit& b) { Chris@16: return typename multiply_typeof_helper, boost::units::unit >::type::inherited Chris@16: (tuple, Chris@16: typename boost::lambda::const_copy_argument >::type> Chris@16: (a, b)); Chris@16: } Chris@16: Chris@16: } // namespace units Chris@16: Chris@16: namespace lambda { Chris@16: Chris@16: /// Partial specialization of return type trait for action Chris@16: /// Y / unit. Chris@16: template Chris@16: struct plain_return_type_2, Chris@16: Y, Chris@16: boost::units::unit > { Chris@16: typedef typename boost::units::divide_typeof_helper< Chris@16: Y, boost::units::unit >::type type; Chris@16: }; Chris@16: Chris@16: } // namespace lambda Chris@16: Chris@16: namespace units { Chris@16: Chris@16: template Chris@16: struct divide_typeof_helper, boost::units::unit > { Chris@16: typedef boost::lambda::lambda_functor< Chris@16: boost::lambda::lambda_functor_base< Chris@16: boost::lambda::arithmetic_action, Chris@16: tuple, typename boost::lambda::const_copy_argument >::type> Chris@16: > Chris@16: > type; Chris@16: }; Chris@16: Chris@16: /// Disambiguating overload for action Chris@16: /// lambda_functor / unit Chris@16: /// based on \. Chris@16: template Chris@16: inline const typename divide_typeof_helper, boost::units::unit >::type Chris@16: operator/(const boost::lambda::lambda_functor& a, Chris@16: const boost::units::unit& b) { Chris@16: return typename divide_typeof_helper, boost::units::unit >::type::inherited Chris@16: (tuple, Chris@16: typename boost::lambda::const_copy_argument >::type> Chris@16: (a, b)); Chris@16: } Chris@16: Chris@16: } // namespace units Chris@16: Chris@16: namespace lambda { Chris@16: Chris@16: /// Partial specialization of return type trait for action Chris@16: /// quantity * X. Chris@16: template Chris@16: struct plain_return_type_2, Chris@16: boost::units::quantity, Chris@16: X> { Chris@16: typedef typename boost::units::multiply_typeof_helper< Chris@16: boost::units::quantity, X>::type type; Chris@16: }; Chris@16: Chris@16: /// Partial specialization of return type trait for action Chris@16: /// X * quantity. Chris@16: template Chris@16: struct plain_return_type_2, Chris@16: X, Chris@16: boost::units::quantity > { Chris@16: typedef typename boost::units::multiply_typeof_helper< Chris@16: X, boost::units::quantity >::type type; Chris@16: }; Chris@16: Chris@16: /// Partial specialization of return type trait for action Chris@16: /// quantity / X. Chris@16: template Chris@16: struct plain_return_type_2, Chris@16: boost::units::quantity, Chris@16: X> { Chris@16: typedef typename boost::units::divide_typeof_helper< Chris@16: boost::units::quantity, X>::type type; Chris@16: }; Chris@16: Chris@16: /// Partial specialization of return type trait for action Chris@16: /// X / quantity. Chris@16: template Chris@16: struct plain_return_type_2, Chris@16: X, Chris@16: boost::units::quantity > { Chris@16: typedef typename boost::units::divide_typeof_helper< Chris@16: X, boost::units::quantity >::type type; Chris@16: }; Chris@16: Chris@16: /// Partial specialization of return type trait for action Chris@16: /// unit * quantity. Chris@16: template Chris@16: struct plain_return_type_2, Chris@16: boost::units::unit, Chris@16: boost::units::quantity > { Chris@16: typedef typename boost::units::multiply_typeof_helper< Chris@16: boost::units::unit, Chris@16: boost::units::quantity >::type type; Chris@16: }; Chris@16: Chris@16: /// Partial specialization of return type trait for action Chris@16: /// unit / quantity. Chris@16: template Chris@16: struct plain_return_type_2, Chris@16: boost::units::unit, Chris@16: boost::units::quantity > { Chris@16: typedef typename boost::units::divide_typeof_helper< Chris@16: boost::units::unit, Chris@16: boost::units::quantity >::type type; Chris@16: }; Chris@16: Chris@16: /// Partial specialization of return type trait for action Chris@16: /// quantity * unit. Chris@16: template Chris@16: struct plain_return_type_2, Chris@16: boost::units::quantity, Chris@16: boost::units::unit > { Chris@16: typedef typename boost::units::multiply_typeof_helper< Chris@16: boost::units::quantity, Chris@16: boost::units::unit >::type type; Chris@16: }; Chris@16: Chris@16: /// Partial specialization of return type trait for action Chris@16: /// quantity / unit. Chris@16: template Chris@16: struct plain_return_type_2, Chris@16: boost::units::quantity, Chris@16: boost::units::unit > { Chris@16: typedef typename boost::units::divide_typeof_helper< Chris@16: boost::units::quantity, Chris@16: boost::units::unit >::type type; Chris@16: }; Chris@16: Chris@16: /// Partial specialization of return type trait for action Chris@16: /// +quantity. Chris@16: template Chris@16: struct plain_return_type_1, Chris@16: boost::units::quantity > { Chris@16: typedef typename boost::units::unary_plus_typeof_helper< Chris@16: boost::units::quantity >::type type; Chris@16: }; Chris@16: Chris@16: /// Partial specialization of return type trait for action Chris@16: /// -quantity. Chris@16: template Chris@16: struct plain_return_type_1, Chris@16: boost::units::quantity > { Chris@16: typedef typename boost::units::unary_minus_typeof_helper< Chris@16: boost::units::quantity >::type type; Chris@16: }; Chris@16: Chris@16: /// Partial specialization of return type trait for action Chris@16: /// quantity + quantity. Chris@16: template Chris@16: struct plain_return_type_2, Chris@16: boost::units::quantity, Chris@16: boost::units::quantity > { Chris@16: typedef typename boost::units::add_typeof_helper< Chris@16: boost::units::quantity, Chris@16: boost::units::quantity >::type type; Chris@16: }; Chris@16: Chris@16: /// Partial specialization of return type trait for action Chris@16: /// quantity + Y. Chris@16: template Chris@16: struct plain_return_type_2, Chris@16: boost::units::quantity, Chris@16: Y> { Chris@16: typedef typename boost::units::add_typeof_helper< Chris@16: boost::units::quantity, Chris@16: Y>::type type; Chris@16: }; Chris@16: Chris@16: /// Partial specialization of return type trait for action Chris@16: /// X + quantity. Chris@16: template Chris@16: struct plain_return_type_2, Chris@16: X, Chris@16: boost::units::quantity > { Chris@16: typedef typename boost::units::add_typeof_helper< Chris@16: X, Chris@16: boost::units::quantity >::type type; Chris@16: }; Chris@16: Chris@16: /// Partial specialization of return type trait for action Chris@16: /// quantity - quantity. Chris@16: template Chris@16: struct plain_return_type_2, Chris@16: boost::units::quantity, Chris@16: boost::units::quantity > { Chris@16: typedef typename boost::units::subtract_typeof_helper< Chris@16: boost::units::quantity, Chris@16: boost::units::quantity >::type type; Chris@16: }; Chris@16: Chris@16: /// Partial specialization of return type trait for action Chris@16: /// quantity - Y. Chris@16: template Chris@16: struct plain_return_type_2, Chris@16: boost::units::quantity, Chris@16: Y> { Chris@16: typedef typename boost::units::subtract_typeof_helper< Chris@16: boost::units::quantity, Chris@16: Y>::type type; Chris@16: }; Chris@16: Chris@16: /// Partial specialization of return type trait for action Chris@16: /// X - quantity. Chris@16: template Chris@16: struct plain_return_type_2, Chris@16: X, Chris@16: boost::units::quantity > { Chris@16: typedef typename boost::units::subtract_typeof_helper< Chris@16: X, Chris@16: boost::units::quantity >::type type; Chris@16: }; Chris@16: Chris@16: /// Partial specialization of return type trait for action Chris@16: /// quantity * quantity. Chris@16: template Chris@16: struct plain_return_type_2, Chris@16: boost::units::quantity, Chris@16: boost::units::quantity > { Chris@16: typedef typename boost::units::multiply_typeof_helper< Chris@16: boost::units::quantity, Chris@16: boost::units::quantity >::type type; Chris@16: }; Chris@16: Chris@16: /// Partial specialization of return type trait for action Chris@16: /// quantity / quantity. Chris@16: template Chris@16: struct plain_return_type_2, Chris@16: boost::units::quantity, Chris@16: boost::units::quantity > { Chris@16: typedef typename boost::units::divide_typeof_helper< Chris@16: boost::units::quantity, Chris@16: boost::units::quantity >::type type; Chris@16: }; Chris@16: Chris@16: Chris@16: //////////////////////////////////////////////////////////////////////// Chris@16: // Partial specialization of Boost.Lambda's trait classes for all Chris@16: // operators overloaded in Chris@16: //////////////////////////////////////////////////////////////////////// Chris@16: Chris@16: /// Partial specialization of return type trait for action Chris@16: /// +unit. Chris@16: template Chris@16: struct plain_return_type_1, Chris@16: boost::units::unit > { Chris@16: typedef typename boost::units::unary_plus_typeof_helper< Chris@16: boost::units::unit >::type type; Chris@16: }; Chris@16: Chris@16: /// Partial specialization of return type trait for action Chris@16: /// -unit. Chris@16: template Chris@16: struct plain_return_type_1, Chris@16: boost::units::unit > { Chris@16: typedef typename boost::units::unary_minus_typeof_helper< Chris@16: boost::units::unit >::type type; Chris@16: }; Chris@16: Chris@16: /// Partial specialization of return type trait for action Chris@16: /// unit + unit. Chris@16: template Chris@16: struct plain_return_type_2, Chris@16: boost::units::unit, Chris@16: boost::units::unit > { Chris@16: typedef typename boost::units::add_typeof_helper< Chris@16: boost::units::unit, Chris@16: boost::units::unit >::type type; Chris@16: }; Chris@16: Chris@16: /// Partial specialization of return type trait for action Chris@16: /// unit - unit. Chris@16: template Chris@16: struct plain_return_type_2, Chris@16: boost::units::unit, Chris@16: boost::units::unit > { Chris@16: typedef typename boost::units::subtract_typeof_helper< Chris@16: boost::units::unit, Chris@16: boost::units::unit >::type type; Chris@16: }; Chris@16: Chris@16: /// Partial specialization of return type trait for action Chris@16: /// unit * unit. Chris@16: template Chris@16: struct plain_return_type_2, Chris@16: boost::units::unit, Chris@16: boost::units::unit > { Chris@16: typedef typename boost::units::multiply_typeof_helper< Chris@16: boost::units::unit, Chris@16: boost::units::unit >::type type; Chris@16: }; Chris@16: Chris@16: /// Partial specialization of return type trait for action Chris@16: /// unit / unit. Chris@16: template Chris@16: struct plain_return_type_2, Chris@16: boost::units::unit, Chris@16: boost::units::unit > { Chris@16: typedef typename boost::units::divide_typeof_helper< Chris@16: boost::units::unit, Chris@16: boost::units::unit >::type type; Chris@16: }; Chris@16: Chris@16: Chris@16: //////////////////////////////////////////////////////////////////////// Chris@16: // Partial specialization of Boost.Lambda's trait classes for all Chris@16: // operators overloaded in Chris@16: //////////////////////////////////////////////////////////////////////// Chris@16: Chris@16: Chris@16: /// Partial specialization of return type trait for action Chris@16: /// absolute + Y. Chris@16: template Chris@16: struct plain_return_type_2, Chris@16: boost::units::absolute, Chris@16: Y> { Chris@16: typedef typename boost::units::absolute type; Chris@16: }; Chris@16: Chris@16: /// Partial specialization of return type trait for action Chris@16: /// Y + absolute. Chris@16: template Chris@16: struct plain_return_type_2, Chris@16: Y, Chris@16: boost::units::absolute > { Chris@16: typedef typename boost::units::absolute type; Chris@16: }; Chris@16: Chris@16: /// Partial specialization of return type trait for action Chris@16: /// absolute - Y. Chris@16: template Chris@16: struct plain_return_type_2, Chris@16: boost::units::absolute, Chris@16: Y> { Chris@16: typedef typename boost::units::absolute type; Chris@16: }; Chris@16: Chris@16: /// Partial specialization of return type trait for action Chris@16: /// absolute - absolute. Chris@16: template Chris@16: struct plain_return_type_2, Chris@16: boost::units::absolute, Chris@16: boost::units::absolute > { Chris@16: typedef Y type; Chris@16: }; Chris@16: Chris@16: /// Partial specialization of return type trait for action Chris@16: /// T * absolute >. Chris@16: template Chris@16: struct plain_return_type_2, Chris@16: T, Chris@16: boost::units::absolute > > { Chris@16: typedef typename boost::units::quantity< Chris@16: boost::units::absolute >, T> type; Chris@16: }; Chris@16: Chris@16: } // namespace lambda Chris@16: Chris@16: namespace units { Chris@16: Chris@16: template Chris@16: struct multiply_typeof_helper, boost::units::absolute > > { Chris@16: typedef boost::lambda::lambda_functor< Chris@16: boost::lambda::lambda_functor_base< Chris@16: boost::lambda::arithmetic_action, Chris@16: tuple, Chris@16: typename boost::lambda::const_copy_argument > >::type> Chris@16: > Chris@16: > type; Chris@16: }; Chris@16: Chris@16: /// Disambiguating overload for action Chris@16: /// lambda_functor * absolute > Chris@16: /// based on \. Chris@16: template Chris@16: inline const typename multiply_typeof_helper, boost::units::absolute > >::type Chris@16: operator*(const boost::lambda::lambda_functor& a, Chris@16: const boost::units::absolute >& b) { Chris@16: return typename multiply_typeof_helper, boost::units::absolute > >::type::inherited Chris@16: (tuple, Chris@16: typename boost::lambda::const_copy_argument > >::type> Chris@16: (a, b)); Chris@16: } Chris@16: Chris@16: } // namespace units Chris@16: Chris@16: namespace lambda { Chris@16: Chris@16: /// Partial specialization of return type trait for action Chris@16: /// absolute > * T. Chris@16: template Chris@16: struct plain_return_type_2, Chris@16: boost::units::absolute >, Chris@16: T> { Chris@16: typedef typename boost::units::quantity< Chris@16: boost::units::absolute >, T> type; Chris@16: }; Chris@16: Chris@16: } // namespace lambda Chris@16: Chris@16: namespace units { Chris@16: Chris@16: template Chris@16: struct multiply_typeof_helper >, boost::lambda::lambda_functor > { Chris@16: typedef boost::lambda::lambda_functor< Chris@16: boost::lambda::lambda_functor_base< Chris@16: boost::lambda::arithmetic_action, Chris@16: tuple > >::type, Chris@16: boost::lambda::lambda_functor > Chris@16: > Chris@16: > type; Chris@16: }; Chris@16: Chris@16: /// Disambiguating overload for action Chris@16: /// absolute > * lambda_functor Chris@16: /// based on \. Chris@16: template Chris@16: inline const typename multiply_typeof_helper >, boost::lambda::lambda_functor >::type Chris@16: operator*(const boost::units::absolute >& a, Chris@16: const boost::lambda::lambda_functor& b) { Chris@16: return typename multiply_typeof_helper >, boost::lambda::lambda_functor >::type::inherited Chris@16: (tuple > >::type, Chris@16: boost::lambda::lambda_functor > Chris@16: (a, b)); Chris@16: } Chris@16: Chris@16: } // namespace units Chris@16: Chris@16: } // namespace boost Chris@16: Chris@16: #endif // BOOST_UNITS_LAMBDA_HPP