//#include //#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace boost { //----------------------------------------------------------------------------// // // // 20.6.1 Class template ratio [ratio.ratio] // // // //----------------------------------------------------------------------------// template class ratio { static const boost::intmax_t ABS_N = mpl::abs_c::value; static const boost::intmax_t ABS_D = mpl::abs_c::value; BOOST_RATIO_STATIC_ASSERT(ABS_N >= 0, BOOST_RATIO_NUMERATOR_IS_OUT_OF_RANGE, ()); BOOST_RATIO_STATIC_ASSERT(ABS_D > 0, BOOST_RATIO_DENOMINATOR_IS_OUT_OF_RANGE, ()); BOOST_RATIO_STATIC_ASSERT(D != 0, BOOST_RATIO_DIVIDE_BY_0 , ()); static const boost::intmax_t SIGN_N = mpl::sign_c::value * mpl::sign_c::value; static const boost::intmax_t GCD = mpl::gcd_c::value; public: BOOST_STATIC_CONSTEXPR boost::intmax_t num = SIGN_N * ABS_N / GCD; BOOST_STATIC_CONSTEXPR boost::intmax_t den = ABS_D / GCD; #ifdef BOOST_RATIO_EXTENSIONS typedef mpl::rational_c_tag tag; typedef boost::rational value_type; typedef boost::intmax_t num_type; typedef boost::intmax_t den_type; ratio() {} template ratio(const ratio<_N2, _D2>&, typename enable_if_c < (ratio<_N2, _D2>::num == num && ratio<_N2, _D2>::den == den) >::type* = 0) {} template typename enable_if_c < (ratio<_N2, _D2>::num == num && ratio<_N2, _D2>::den == den), ratio& >::type operator=(const ratio<_N2, _D2>&) {return *this;} static value_type value() {return value_type(num,den);} value_type operator()() const {return value();} #endif typedef ratio type; }; #if defined(BOOST_NO_CXX11_CONSTEXPR) template const boost::intmax_t ratio::num; template const boost::intmax_t ratio::den; #endif //----------------------------------------------------------------------------// // // // 20.6.2 Arithmetic on ratio types [ratio.arithmetic] // // // //----------------------------------------------------------------------------// template struct ratio_add : boost::ratio_detail::ratio_add::type { }; template struct ratio_subtract : boost::ratio_detail::ratio_subtract::type { }; template struct ratio_multiply : boost::ratio_detail::ratio_multiply::type { }; template struct ratio_divide : boost::ratio_detail::ratio_divide::type { }; //----------------------------------------------------------------------------// // // // 20.6.3 Comparision of ratio types [ratio.comparison] // // // //----------------------------------------------------------------------------// // ratio_equal template struct ratio_equal : public boost::integral_constant {}; template struct ratio_not_equal : public boost::integral_constant::value> {}; // ratio_less template struct ratio_less : boost::integral_constant::value> {}; template struct ratio_less_equal : boost::integral_constant::value> {}; template struct ratio_greater : boost::integral_constant::value> {}; template struct ratio_greater_equal : boost::integral_constant::value> {}; template struct ratio_gcd : ratio::value, mpl::lcm_c::value>::type { }; //----------------------------------------------------------------------------// // // // More arithmetic on ratio types [ratio.arithmetic] // // // //----------------------------------------------------------------------------// #ifdef BOOST_RATIO_EXTENSIONS template struct ratio_negate : ratio<-R::num, R::den>::type { }; template struct ratio_abs : ratio::value, R::den>::type { }; template struct ratio_sign : mpl::sign_c { }; template struct ratio_inverse : ratio::type { }; template struct ratio_lcm : ratio::value, mpl::gcd_c::value>::type { }; template struct ratio_modulo : ratio<(R1::num * R2::den) % (R2::num * R1::den), R1::den * R2::den>::type { }; namespace detail { template struct ratio_min : R1 {}; template struct ratio_min : R2 {}; template struct ratio_max : R2 {}; template struct ratio_max : R1 {}; } template struct ratio_min : detail::ratio_min::value>::type { }; template struct ratio_max : detail::ratio_max::value>::type { }; template struct ratio_power : ratio_multiply< typename ratio_power::type, typename ratio_power::type, p/2>::type >::type {}; template struct ratio_power : ratio<1>::type {}; template struct ratio_power : R {}; template struct ratio_power : ratio_divide, R>::type {}; #endif } // namespace boost //#include #include #if defined(__SUNPRO_CC) && !defined(BOOST_COMMON_TYPE_DONT_USE_TYPEOF) # define BOOST_COMMON_TYPE_DONT_USE_TYPEOF #endif #if defined(__IBMCPP__) && !defined(BOOST_COMMON_TYPE_DONT_USE_TYPEOF) # define BOOST_COMMON_TYPE_DONT_USE_TYPEOF #endif //----------------------------------------------------------------------------// #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && !defined(BOOST_COMMON_TYPE_ARITY) #define BOOST_COMMON_TYPE_ARITY 3 #endif //----------------------------------------------------------------------------// #if defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_COMMON_TYPE_DONT_USE_TYPEOF) #include // boost wonders never cease! #endif //----------------------------------------------------------------------------// #ifndef BOOST_NO_CXX11_STATIC_ASSERT #define BOOST_COMMON_TYPE_STATIC_ASSERT(CND, MSG, TYPES) static_assert(CND,MSG) #elif defined(BOOST_COMMON_TYPE_USES_MPL_ASSERT) #include #include #define BOOST_COMMON_TYPE_STATIC_ASSERT(CND, MSG, TYPES) \ BOOST_MPL_ASSERT_MSG(boost::mpl::bool_< (CND) >::type::value, MSG, TYPES) #else #include #define BOOST_COMMON_TYPE_STATIC_ASSERT(CND, MSG, TYPES) BOOST_STATIC_ASSERT(CND) #endif #if !defined(BOOST_NO_CXX11_STATIC_ASSERT) || !defined(BOOST_COMMON_TYPE_USES_MPL_ASSERT) #define BOOST_COMMON_TYPE_MUST_BE_A_COMPLE_TYPE "must be complete type" #endif #if defined(BOOST_NO_CXX11_DECLTYPE) && defined(BOOST_COMMON_TYPE_DONT_USE_TYPEOF) #include #include #endif #include #include #include //----------------------------------------------------------------------------// // // // C++03 implementation of // // 20.9.7.6 Other transformations [meta.trans.other] // // Written by Howard Hinnant // // Adapted for Boost by Beman Dawes, Vicente Botet and Jeffrey Hellrung // // // //----------------------------------------------------------------------------// namespace boost { // prototype #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) template struct common_type; #else // or no specialization template struct common_type { public: typedef typename common_type::type, V>::type type; }; #endif // 1 arg template #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) struct common_type #else struct common_type #endif { BOOST_COMMON_TYPE_STATIC_ASSERT(sizeof(T) > 0, BOOST_COMMON_TYPE_MUST_BE_A_COMPLE_TYPE, (T)); public: typedef T type; }; // 2 args namespace type_traits_detail { template struct common_type_2 { private: BOOST_COMMON_TYPE_STATIC_ASSERT(sizeof(T) > 0, BOOST_COMMON_TYPE_MUST_BE_A_COMPLE_TYPE, (T)); BOOST_COMMON_TYPE_STATIC_ASSERT(sizeof(U) > 0, BOOST_COMMON_TYPE_MUST_BE_A_COMPLE_TYPE, (U)); static bool declval_bool(); // workaround gcc bug; not required by std static typename add_rvalue_reference::type declval_T(); // workaround gcc bug; not required by std static typename add_rvalue_reference::type declval_U(); // workaround gcc bug; not required by std static typename add_rvalue_reference::type declval_b(); #if !defined(BOOST_NO_CXX11_DECLTYPE) public: typedef decltype(declval() ? declval() : declval()) type; #elif defined(BOOST_COMMON_TYPE_DONT_USE_TYPEOF) public: typedef typename detail_type_traits_common_type::common_type_impl< typename remove_cv::type, typename remove_cv::type >::type type; #else public: typedef BOOST_TYPEOF_TPL(declval_b() ? declval_T() : declval_U()) type; #endif #if defined(__GNUC__) && __GNUC__ == 3 && __GNUC_MINOR__ == 3 public: void public_dummy_function_just_to_silence_warning(); #endif }; template struct common_type_2 { typedef T type; }; } #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) template struct common_type #else template struct common_type #endif : public type_traits_detail::common_type_2 { }; // 3 or more args #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) template struct common_type { public: typedef typename common_type::type, V...>::type type; }; #endif } // namespace boost using namespace std; int a = 5;