Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/boost/units/operators.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // Boost.Units - A C++ library for zero-overhead dimensional analysis and 
0002 // unit/quantity manipulation and conversion
0003 //
0004 // Copyright (C) 2003-2008 Matthias Christian Schabel
0005 // Copyright (C) 2008 Steven Watanabe
0006 //
0007 // Distributed under the Boost Software License, Version 1.0. (See
0008 // accompanying file LICENSE_1_0.txt or copy at
0009 // http://www.boost.org/LICENSE_1_0.txt)
0010 
0011 #ifndef BOOST_UNITS_OPERATORS_HPP 
0012 #define BOOST_UNITS_OPERATORS_HPP
0013 
0014 
0015 ///
0016 /// \file
0017 /// \brief Compile time operators and typeof helper classes.
0018 /// \details
0019 ///   These operators declare the compile-time operators needed to support dimensional
0020 ///   analysis algebra.  They require the use of Boost.Typeof, emulation or native.
0021 ///   Typeof helper classes define result type for heterogeneous operators on value types.
0022 ///   These must be defined through specialization for powers and roots.
0023 ///
0024 
0025 #include <boost/static_assert.hpp>
0026 #include <boost/type_traits/is_same.hpp>
0027 
0028 #include <boost/units/config.hpp>
0029 
0030 namespace boost {
0031 namespace units {
0032 
0033 #if BOOST_UNITS_HAS_TYPEOF
0034 
0035 #ifndef BOOST_UNITS_DOXYGEN
0036 
0037 // to avoid need for default constructor and eliminate divide by zero errors.
0038 namespace typeof_ {
0039 
0040 /// INTERNAL ONLY
0041 template<class T> T make();
0042 
0043 } // namespace typeof_
0044 
0045 #endif
0046 
0047 #if (BOOST_UNITS_HAS_BOOST_TYPEOF)
0048 
0049 template<typename X> struct unary_plus_typeof_helper            
0050 {
0051     BOOST_TYPEOF_NESTED_TYPEDEF_TPL(nested, (+typeof_::make<X>()))
0052     typedef typename nested::type type;
0053 };
0054 
0055 template<typename X> struct unary_minus_typeof_helper           
0056 {
0057     BOOST_TYPEOF_NESTED_TYPEDEF_TPL(nested, (-typeof_::make<X>()))
0058     typedef typename nested::type type;
0059 };
0060 
0061 template<typename X,typename Y> struct add_typeof_helper        
0062 {
0063     BOOST_TYPEOF_NESTED_TYPEDEF_TPL(nested, (typeof_::make<X>()+typeof_::make<Y>()))
0064     typedef typename nested::type type;
0065 };
0066 
0067 template<typename X,typename Y> struct subtract_typeof_helper   
0068 {
0069     BOOST_TYPEOF_NESTED_TYPEDEF_TPL(nested, (typeof_::make<X>()-typeof_::make<Y>()))
0070     typedef typename nested::type type;
0071 };
0072 
0073 template<typename X,typename Y> struct multiply_typeof_helper   
0074 {
0075     BOOST_TYPEOF_NESTED_TYPEDEF_TPL(nested, (typeof_::make<X>()*typeof_::make<Y>()))
0076     typedef typename nested::type type;
0077 };
0078 
0079 template<typename X,typename Y> struct divide_typeof_helper     
0080 {
0081     BOOST_TYPEOF_NESTED_TYPEDEF_TPL(nested, (typeof_::make<X>()/typeof_::make<Y>()))
0082     typedef typename nested::type type;
0083 };
0084 
0085 #elif (BOOST_UNITS_HAS_MWERKS_TYPEOF)
0086 
0087 template<typename X> struct unary_plus_typeof_helper            { typedef __typeof__((+typeof_::make<X>())) type; };
0088 template<typename X> struct unary_minus_typeof_helper           { typedef __typeof__((-typeof_::make<X>())) type; };
0089 
0090 template<typename X,typename Y> struct add_typeof_helper        { typedef __typeof__((typeof_::make<X>()+typeof_::make<Y>())) type; };
0091 template<typename X,typename Y> struct subtract_typeof_helper   { typedef __typeof__((typeof_::make<X>()-typeof_::make<Y>())) type; };
0092 template<typename X,typename Y> struct multiply_typeof_helper   { typedef __typeof__((typeof_::make<X>()*typeof_::make<Y>())) type; };
0093 template<typename X,typename Y> struct divide_typeof_helper     { typedef __typeof__((typeof_::make<X>()/typeof_::make<Y>())) type; };
0094 
0095 #elif (BOOST_UNITS_HAS_GNU_TYPEOF) || defined(BOOST_UNITS_DOXYGEN)
0096 
0097 template<typename X> struct unary_plus_typeof_helper            { typedef typeof((+typeof_::make<X>())) type; };
0098 template<typename X> struct unary_minus_typeof_helper           { typedef typeof((-typeof_::make<X>())) type; };
0099 
0100 template<typename X,typename Y> struct add_typeof_helper        { typedef typeof((typeof_::make<X>()+typeof_::make<Y>())) type; };
0101 template<typename X,typename Y> struct subtract_typeof_helper   { typedef typeof((typeof_::make<X>()-typeof_::make<Y>())) type; };
0102 template<typename X,typename Y> struct multiply_typeof_helper   { typedef typeof((typeof_::make<X>()*typeof_::make<Y>())) type; };
0103 template<typename X,typename Y> struct divide_typeof_helper     { typedef typeof((typeof_::make<X>()/typeof_::make<Y>())) type; };
0104 
0105 #endif
0106 
0107 #else // BOOST_UNITS_HAS_TYPEOF
0108 
0109 template<typename X> struct unary_plus_typeof_helper            { typedef X type; };
0110 template<typename X> struct unary_minus_typeof_helper           { typedef X type; };
0111 
0112 template<typename X,typename Y> struct add_typeof_helper        { BOOST_STATIC_ASSERT((is_same<X,Y>::value == true)); typedef X type; };
0113 template<typename X,typename Y> struct subtract_typeof_helper   { BOOST_STATIC_ASSERT((is_same<X,Y>::value == true)); typedef X type; };
0114 template<typename X,typename Y> struct multiply_typeof_helper   { BOOST_STATIC_ASSERT((is_same<X,Y>::value == true)); typedef X type; };
0115 template<typename X,typename Y> struct divide_typeof_helper     { BOOST_STATIC_ASSERT((is_same<X,Y>::value == true)); typedef X type; };
0116 
0117 #endif // BOOST_UNITS_HAS_TYPEOF
0118 
0119 template<typename X,typename Y> struct power_typeof_helper;
0120 template<typename X,typename Y> struct root_typeof_helper;
0121 
0122 #ifdef BOOST_UNITS_DOXYGEN
0123 
0124 /// A helper used by @c pow to raise
0125 /// a runtime object to a compile time
0126 /// known exponent.  This template is intended to
0127 /// be specialized.  All specializations must
0128 /// conform to the interface shown here.
0129 /// @c Exponent will be either the exponent
0130 /// passed to @c pow or @c static_rational<N>
0131 /// for and integer argument, N.
0132 template<typename BaseType, typename Exponent>
0133 struct power_typeof_helper
0134 {
0135     /// specifies the result type
0136     typedef detail::unspecified type;
0137     /// Carries out the runtime calculation.
0138     static BOOST_CONSTEXPR type value(const BaseType& base);
0139 };
0140 
0141 /// A helper used by @c root to take a root
0142 /// of a runtime object using a compile time
0143 /// known index.  This template is intended to
0144 /// be specialized.  All specializations must
0145 /// conform to the interface shown here.
0146 /// @c Index will be either the type
0147 /// passed to @c pow or @c static_rational<N>
0148 /// for and integer argument, N.
0149 template<typename Radicand, typename Index>
0150 struct root_typeof_helper
0151 {
0152     /// specifies the result type
0153     typedef detail::unspecified type;
0154     /// Carries out the runtime calculation.
0155     static BOOST_CONSTEXPR type value(const Radicand& base);
0156 };
0157 
0158 #endif
0159 
0160 } // namespace units
0161 
0162 } // namespace boost
0163 
0164 #endif // BOOST_UNITS_OPERATORS_HPP