From 39f17a94b8ddf79f4b713955be5a3bb99bd4dbf2 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 28 Apr 2025 19:58:39 +0100 Subject: [PATCH] Added floating point duration types --- include/etl/private/chrono/duration.h | 48 +++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/include/etl/private/chrono/duration.h b/include/etl/private/chrono/duration.h index 1b929709..409a2486 100644 --- a/include/etl/private/chrono/duration.h +++ b/include/etl/private/chrono/duration.h @@ -628,6 +628,14 @@ namespace etl return etl::chrono::hours(static_cast(h)); } + //*********************************************************************** + /// Literal for floating point hours duration + //*********************************************************************** + inline ETL_CONSTEXPR etl::chrono::duration> operator""_h(long double h) noexcept + { + return etl::chrono::duration>(h); + } + //*********************************************************************** /// Literal for minutes duration //*********************************************************************** @@ -636,6 +644,14 @@ namespace etl return etl::chrono::minutes(static_cast(m)); } + //*********************************************************************** + /// Literal for floating point minutes duration + //*********************************************************************** + inline ETL_CONSTEXPR etl::chrono::duration> operator ""_minutes(long double m) noexcept + { + return etl::chrono::duration>(m); + } + //*********************************************************************** /// Literal for seconds duration //*********************************************************************** @@ -644,6 +660,14 @@ namespace etl return etl::chrono::seconds(static_cast(s)); } + //*********************************************************************** + /// Literal for floating point seconds duration + //*********************************************************************** + inline ETL_CONSTEXPR etl::chrono::duration operator ""_seconds(long double s) noexcept + { + return etl::chrono::duration(s); + } + //*********************************************************************** /// Literal for milliseconds duration //*********************************************************************** @@ -652,6 +676,14 @@ namespace etl return etl::chrono::milliseconds(static_cast(s)); } + //*********************************************************************** + /// Literal for floating point milliseconds duration + //*********************************************************************** + inline ETL_CONSTEXPR etl::chrono::duration operator ""_milliseconds(long double s) noexcept + { + return etl::chrono::duration(s); + } + //*********************************************************************** /// Literal for microseconds duration //*********************************************************************** @@ -660,6 +692,14 @@ namespace etl return etl::chrono::microseconds(static_cast(s)); } + //*********************************************************************** + /// Literal for floating point microseconds duration + //*********************************************************************** + inline ETL_CONSTEXPR etl::chrono::duration operator ""_microseconds(long double s) noexcept + { + return etl::chrono::duration(s); + } + //*********************************************************************** /// Literal for nanoseconds duration //*********************************************************************** @@ -667,6 +707,14 @@ namespace etl { return etl::chrono::nanoseconds(static_cast(s)); } + + //*********************************************************************** + /// Literal for floating point microseconds duration + //*********************************************************************** + inline ETL_CONSTEXPR etl::chrono::duration operator ""_nanoseconds(long double s) noexcept + { + return etl::chrono::duration(s); + } } } }