Skip to content

Commit

Permalink
Remove C++03 workarounds; remove support for extensions; alias to <ra…
Browse files Browse the repository at this point in the history
…tio>
  • Loading branch information
pdimov committed Oct 13, 2023
1 parent 3708bca commit e273d6b
Show file tree
Hide file tree
Showing 30 changed files with 281 additions and 1,255 deletions.
2 changes: 1 addition & 1 deletion example/duration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ namespace chrono {
class duration
{
BOOST_EX_CHRONO_STATIC_ASSERT(!boost_ex::chrono::detail::is_duration<Rep>::value, BOOST_EX_CHRONO_A_DURATION_REPRESENTATION_CAN_NOT_BE_A_DURATION, ());
BOOST_EX_CHRONO_STATIC_ASSERT(boost::ratio_detail::is_ratio<Period>::value, BOOST_EX_CHRONO_SECOND_TEMPLATE_PARAMETER_OF_DURATION_MUST_BE_A_STD_RATIO, ());
//BOOST_EX_CHRONO_STATIC_ASSERT(boost::ratio_detail::is_ratio<Period>::value, BOOST_EX_CHRONO_SECOND_TEMPLATE_PARAMETER_OF_DURATION_MUST_BE_A_STD_RATIO, ());
BOOST_EX_CHRONO_STATIC_ASSERT(Period::num>0, BOOST_EX_CHRONO_DURATION_PERIOD_MUST_BE_POSITIVE, ());
public:
typedef Rep rep;
Expand Down
91 changes: 2 additions & 89 deletions include/boost/ratio/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,93 +9,6 @@
#ifndef BOOST_RATIO_CONFIG_HPP
#define BOOST_RATIO_CONFIG_HPP

#include <boost/ratio/detail/requires_cxx11.hpp>
#include <boost/config.hpp>
#include <boost/config/pragma_message.hpp>
#include <boost/cstdint.hpp>
// This header is no longer useful and is only retained for compatibility


#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 5) || !defined(__GXX_EXPERIMENTAL_CXX0X__)
# if ! defined BOOST_NO_CXX11_U16STRING
# define BOOST_NO_CXX11_U16STRING
# endif
# if ! defined BOOST_NO_CXX11_U32STRING
# define BOOST_NO_CXX11_U32STRING
# endif
#endif


#if !defined BOOST_RATIO_VERSION
#define BOOST_RATIO_VERSION 2
#else
#if BOOST_RATIO_VERSION!=1 && BOOST_RATIO_VERSION!=2
#error "BOOST_RATIO_VERSION must be 1 or 2"
#endif
#endif

#if BOOST_RATIO_VERSION==1
#if ! defined BOOST_RATIO_DONT_PROVIDE_DEPRECATED_FEATURES_SINCE_V2_0_0
#define BOOST_RATIO_PROVIDES_DEPRECATED_FEATURES_SINCE_V2_0_0
#endif
#endif

#if BOOST_RATIO_VERSION==2
#if ! defined BOOST_RATIO_PROVIDES_DEPRECATED_FEATURES_SINCE_V2_0_0
#define BOOST_RATIO_DONT_PROVIDE_DEPRECATED_FEATURES_SINCE_V2_0_0
#endif
#endif

#ifdef INTMAX_C
#define BOOST_RATIO_INTMAX_C(a) INTMAX_C(a)
#elif __cplusplus >= 201103L
#define BOOST_RATIO_INTMAX_C(a) a##LL
#else
#define BOOST_RATIO_INTMAX_C(a) a##L
#endif

#ifdef UINTMAX_C
#define BOOST_RATIO_UINTMAX_C(a) UINTMAX_C(a)
#elif __cplusplus >= 201103L
#define BOOST_RATIO_UINTMAX_C(a) a##ULL
#else
#define BOOST_RATIO_UINTMAX_C(a) a##UL
#endif

#define BOOST_RATIO_INTMAX_T_MAX (0x7FFFFFFFFFFFFFFELL)


#ifndef BOOST_NO_CXX11_STATIC_ASSERT
#define BOOST_RATIO_STATIC_ASSERT(CND, MSG, TYPES) static_assert(CND,MSG)
#elif defined(BOOST_RATIO_USES_STATIC_ASSERT)
#include <boost/static_assert.hpp>
#define BOOST_RATIO_STATIC_ASSERT(CND, MSG, TYPES) BOOST_STATIC_ASSERT(CND)
#elif defined(BOOST_RATIO_USES_MPL_ASSERT)
#include <boost/mpl/assert.hpp>
#include <boost/mpl/bool.hpp>
#define BOOST_RATIO_STATIC_ASSERT(CND, MSG, TYPES) \
BOOST_MPL_ASSERT_MSG(boost::mpl::bool_< (CND) >::type::value, MSG, TYPES)
#else
//~ #elif defined(BOOST_RATIO_USES_ARRAY_ASSERT)
#define BOOST_RATIO_CONCAT(A,B) A##B
#define BOOST_RATIO_NAME(A,B) BOOST_RATIO_CONCAT(A,B)
#define BOOST_RATIO_STATIC_ASSERT(CND, MSG, TYPES) static char BOOST_RATIO_NAME(__boost_ratio_test_,__LINE__)[(CND)?1:-1]
//~ #define BOOST_RATIO_STATIC_ASSERT(CND, MSG, TYPES)
#endif

#if !defined(BOOST_NO_CXX11_STATIC_ASSERT) || !defined(BOOST_RATIO_USES_MPL_ASSERT)
#define BOOST_RATIO_OVERFLOW_IN_ADD "overflow in ratio add"
#define BOOST_RATIO_OVERFLOW_IN_SUB "overflow in ratio sub"
#define BOOST_RATIO_OVERFLOW_IN_MUL "overflow in ratio mul"
#define BOOST_RATIO_OVERFLOW_IN_DIV "overflow in ratio div"
#define BOOST_RATIO_NUMERATOR_IS_OUT_OF_RANGE "ratio numerator is out of range"
#define BOOST_RATIO_DIVIDE_BY_0 "ratio divide by 0"
#define BOOST_RATIO_DENOMINATOR_IS_OUT_OF_RANGE "ratio denominator is out of range"
#endif

#if defined(BOOST_RATIO_EXTENSIONS)

BOOST_PRAGMA_MESSAGE("Support for BOOST_RATIO_EXTENSIONS is deprecated and will be removed when Boost.Ratio is implemented in terms of <ratio>.")

#endif

#endif // header
#endif // #ifndef BOOST_RATIO_CONFIG_HPP
4 changes: 1 addition & 3 deletions include/boost/ratio/include.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,5 @@

#include <boost/ratio/ratio.hpp>
#include <boost/ratio/ratio_io.hpp>
#ifdef BOOST_RATIO_EXTENSIONS
#include <boost/ratio/mpl/rational_constant.hpp>
#endif

#endif // BOOST_RATIO_INCLUDE_HPP
245 changes: 2 additions & 243 deletions include/boost/ratio/ratio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,261 +32,20 @@ time2_demo contained this comment:
#ifndef BOOST_RATIO_RATIO_HPP
#define BOOST_RATIO_RATIO_HPP

#include <boost/ratio/config.hpp>
#include <boost/ratio/detail/mpl/abs.hpp>
#include <boost/ratio/detail/mpl/sign.hpp>
#include <boost/ratio/detail/mpl/gcd.hpp>
#include <boost/ratio/detail/mpl/lcm.hpp>
#include <cstdlib>
#include <climits>
#include <limits>
#include <boost/cstdint.hpp>
#include <boost/type_traits/integral_constant.hpp>
#include <boost/core/enable_if.hpp>
#include <boost/integer_traits.hpp>
#include <boost/ratio/ratio_fwd.hpp>
#include <boost/ratio/detail/overflow_helpers.hpp>
#ifdef BOOST_RATIO_EXTENSIONS
#include <boost/rational.hpp>
#include <boost/ratio/mpl/rational_c_tag.hpp>
#endif

//
// We simply cannot include this header on gcc without getting copious warnings of the kind:
//
// boost/integer.hpp:77:30: warning: use of C99 long long integer constant
//
// And yet there is no other reasonable implementation, so we declare this a system header
// to suppress these warnings.
//
#if defined(__GNUC__) && (__GNUC__ >= 4)
#pragma GCC system_header
#endif

namespace boost
{


//----------------------------------------------------------------------------//
// //
// 20.6.1 Class template ratio [ratio.ratio] //
// //
//----------------------------------------------------------------------------//

template <boost::intmax_t N, boost::intmax_t D>
class ratio
{
static const boost::intmax_t ABS_N = mpl::abs_c<boost::intmax_t, N>::value;
static const boost::intmax_t ABS_D = mpl::abs_c<boost::intmax_t, D>::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<boost::intmax_t,N>::value
* mpl::sign_c<boost::intmax_t,D>::value;
static const boost::intmax_t GCD = mpl::gcd_c<boost::intmax_t, ABS_N, ABS_D>::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<boost::intmax_t> value_type;
typedef boost::intmax_t num_type;
typedef boost::intmax_t den_type;
ratio()
{}
template <boost::intmax_t _N2, boost::intmax_t _D2>
ratio(const ratio<_N2, _D2>&,
typename enable_if_c
<
(ratio<_N2, _D2>::num == num &&
ratio<_N2, _D2>::den == den)
>::type* = 0)
{}

template <boost::intmax_t _N2, boost::intmax_t _D2>
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<num, den> type;
};

#if defined(BOOST_NO_CXX11_CONSTEXPR)
template <boost::intmax_t N, boost::intmax_t D>
const boost::intmax_t ratio<N, D>::num;
template <boost::intmax_t N, boost::intmax_t D>
const boost::intmax_t ratio<N, D>::den;
#endif

//----------------------------------------------------------------------------//
// //
// 20.6.2 Arithmetic on ratio types [ratio.arithmetic] //
// //
//----------------------------------------------------------------------------//

template <class R1, class R2>
struct ratio_add
: boost::ratio_detail::ratio_add<R1, R2>::type
{
};

template <class R1, class R2>
struct ratio_subtract
: boost::ratio_detail::ratio_subtract<R1, R2>::type
{
};

template <class R1, class R2>
struct ratio_multiply
: boost::ratio_detail::ratio_multiply<R1, R2>::type
{
};

template <class R1, class R2>
struct ratio_divide
: boost::ratio_detail::ratio_divide<R1, R2>::type
{
};

//----------------------------------------------------------------------------//
// //
// 20.6.3 Comparision of ratio types [ratio.comparison] //
// //
//----------------------------------------------------------------------------//

// ratio_equal

template <class R1, class R2>
struct ratio_equal
: public boost::integral_constant<bool,
(R1::num == R2::num && R1::den == R2::den)>
{};

template <class R1, class R2>
struct ratio_not_equal
: public boost::integral_constant<bool, !ratio_equal<R1, R2>::value>
{};

// ratio_less

template <class R1, class R2>
struct ratio_less
: boost::integral_constant<bool, boost::ratio_detail::ratio_less<R1, R2>::value>
{};

template <class R1, class R2>
struct ratio_less_equal
: boost::integral_constant<bool, !ratio_less<R2, R1>::value>
{};

template <class R1, class R2>
struct ratio_greater
: boost::integral_constant<bool, ratio_less<R2, R1>::value>
{};

template <class R1, class R2>
struct ratio_greater_equal
: boost::integral_constant<bool, !ratio_less<R1, R2>::value>
{};

/*
template <class R1, class R2>
struct ratio_gcd :
ratio<mpl::gcd_c<boost::intmax_t, R1::num, R2::num>::value,
mpl::lcm_c<boost::intmax_t, R1::den, R2::den>::value>::type
{
};
*/

//----------------------------------------------------------------------------//
// //
// More arithmetic on ratio types [ratio.arithmetic] //
// //
//----------------------------------------------------------------------------//

#ifdef BOOST_RATIO_EXTENSIONS
template <class R>
struct ratio_negate
: ratio<-R::num, R::den>::type
{
};
template <class R>
struct ratio_abs
: ratio<mpl::abs_c<boost::intmax_t, R::num>::value, R::den>::type
{
};
template <class R>
struct ratio_sign
: mpl::sign_c<boost::intmax_t, R::num>
{
};

template <class R>
struct ratio_inverse
: ratio<R::den, R::num>::type
{
};


template <class R1, class R2>
struct ratio_lcm :
ratio<mpl::lcm_c<boost::intmax_t, R1::num, R2::num>::value,
mpl::gcd_c<boost::intmax_t, R1::den, R2::den>::value>::type
{
};

template <class R1, class R2>
struct ratio_modulo :
ratio<(R1::num * R2::den) % (R2::num * R1::den), R1::den * R2::den>::type
{
};

namespace detail {
template <class R1, class R2, bool r1ltr2>
struct ratio_min : R1 {};
template <class R1, class R2>
struct ratio_min<R1,R2,false> : R2 {};

template <class R1, class R2, bool r1ltr2>
struct ratio_max : R2 {};
template <class R1, class R2>
struct ratio_max<R1,R2,false> : R1 {};
}

template <class R1, class R2>
struct ratio_min : detail::ratio_min<R1, R2, ratio_less<R1,R2>::value>::type
{
};

template <class R1, class R2>
struct ratio_max : detail::ratio_max<R1, R2, ratio_less<R1,R2>::value>::type
{
};

template<typename R, int p>
struct ratio_power :
ratio_multiply<
typename ratio_power<R, p%2>::type,
typename ratio_power<typename ratio_multiply<R, R>::type, p/2>::type
>::type
{};

template<typename R>
struct ratio_power<R, 0> : ratio<1>::type {};

template<typename R>
struct ratio_power<R, 1> : R {};

template<typename R>
struct ratio_power<R, -1> : ratio_divide<ratio<1>, R>::type {};

#endif
} // namespace boost


Expand Down
Loading

0 comments on commit e273d6b

Please sign in to comment.