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