// 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) #ifndef BOOST_UNITS_LAMBDA_HPP #define 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-05 /// /// 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. /// /// \todo Work out a solution for boost::lambda:bind's limitation /// concerning the binding of overloaded functions. The required /// static_cast to the function pointer (referring, e.g., a /// function from boost/units/cmath.hpp) is tedious. Steven /// proposed to use functors with appropriate sig template. /// //////////////////////////////////////////////////////////////////////// #include #include #include #include #include #include #include namespace boost { namespace lambda { //////////////////////////////////////////////////////////////////////// // Partial specialization of Boost.Lambda's trait classes for all // operators overloaded in //////////////////////////////////////////////////////////////////////// /// Partial specialization of return type trait for action /// quantity += quantity. template struct plain_return_type_2, boost::units::quantity, boost::units::quantity > { BOOST_STATIC_ASSERT((boost::is_same::type, Unit>::value == true)); typedef typename boost::units::quantity type; }; /// Partial specialization of return type trait for action /// quantity -= quantity. template struct plain_return_type_2, boost::units::quantity, boost::units::quantity > { BOOST_STATIC_ASSERT((boost::is_same::type, Unit>::value == true)); typedef typename boost::units::quantity type; }; /// Partial specialization of return type trait for action /// quantity *= quantity. template struct plain_return_type_2, boost::units::quantity, boost::units::quantity > { BOOST_STATIC_ASSERT((boost::is_same::type, Unit>::value == true)); typedef typename boost::units::quantity type; }; /// Partial specialization of return type trait for action /// quantity /= quantity. template struct plain_return_type_2, boost::units::quantity, boost::units::quantity > { BOOST_STATIC_ASSERT((boost::is_same::type, Unit>::value == true)); typedef typename boost::units::quantity 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::quantity 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::quantity type; }; /// 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; }; /// 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; }; /// 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; }; /// 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; }; /// 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 - 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 * 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 return type trait for action /// quantity == quantity. template struct plain_return_type_2, boost::units::quantity, boost::units::quantity > { typedef bool type; }; /// Partial specialization of return type trait for action /// quantity != quantity. template struct plain_return_type_2, boost::units::quantity, boost::units::quantity > { typedef bool type; }; /// Partial specialization of return type trait for action /// quantity < quantity. template struct plain_return_type_2, boost::units::quantity, boost::units::quantity > { typedef bool type; }; /// Partial specialization of return type trait for action /// quantity <= quantity. template struct plain_return_type_2, boost::units::quantity, boost::units::quantity > { typedef bool type; }; /// Partial specialization of return type trait for action /// quantity > quantity. template struct plain_return_type_2, boost::units::quantity, boost::units::quantity > { typedef bool type; }; /// Partial specialization of return type trait for action /// quantity >= quantity. template struct plain_return_type_2, boost::units::quantity, boost::units::quantity > { typedef bool 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 > { BOOST_STATIC_ASSERT((boost::is_same::value == true)); 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 > { BOOST_STATIC_ASSERT((boost::is_same::value == true)); 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 return type trait for action /// unit == unit. template struct plain_return_type_2, boost::units::unit, boost::units::unit > { typedef bool type; }; /// Partial specialization of return type trait for action /// unit != unit. template struct plain_return_type_2, boost::units::unit, boost::units::unit > { typedef bool 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 /// 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 + 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::unit, T> type; }; /// 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::unit, T> type; }; } // namespace lambda } // namespace boost #endif // BOOST_UNITS_LAMBDA_HPP