Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix chrono operator/(duration, duration) #556

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions include/EASTL/chrono.h
Original file line number Diff line number Diff line change
Expand Up @@ -327,23 +327,33 @@ namespace chrono
}

template <typename Rep1, typename Period1, typename Rep2>
duration<typename eastl::common_type<Rep1, Rep2>::type, Period1> EASTL_FORCE_INLINE
duration<
typename eastl::common_type<
Rep1,
typename eastl::enable_if<!Internal::IsDuration<Rep2>::value, Rep2>::type
>::type,
Period1> EASTL_FORCE_INLINE
operator/(const duration<Rep1, Period1>& lhs, const Rep2& rhs)
{
typedef duration<typename eastl::common_type<Rep1, Rep2>::type, Period1> common_duration_t;
return common_duration_t(common_duration_t(lhs).count() / rhs);
}

template <typename Rep1, typename Period1, typename Rep2, typename Period2>
typename eastl::common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type EASTL_FORCE_INLINE
typename eastl::common_type<Rep1, Rep2>::type EASTL_FORCE_INLINE
operator/(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs)
{
typedef typename eastl::common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type common_duration_t;
return common_duration_t(common_duration_t(lhs).count() / common_duration_t(rhs).count());
return common_duration_t(lhs).count() / common_duration_t(rhs).count();
}

template <typename Rep1, typename Period1, typename Rep2>
duration<typename eastl::common_type<Rep1, Rep2>::type, Period1> EASTL_FORCE_INLINE
duration<
typename eastl::common_type<
Rep1,
typename eastl::enable_if<!Internal::IsDuration<Rep2>::value, Rep2>::type
>::type,
Period1> EASTL_FORCE_INLINE
operator%(const duration<Rep1, Period1>& lhs, const Rep2& rhs)
{
typedef duration<typename eastl::common_type<Rep1, Rep2>::type, Period1> common_duration_t;
Expand Down
7 changes: 7 additions & 0 deletions test/source/TestChrono.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ int TestDuration()
}
}

{
seconds s(5);
milliseconds ms(10);
VERIFY(s / ms == 500);
VERIFY(ms / s.count() == milliseconds(2));
}

return nErrorCount;
}

Expand Down
Loading