From 57fa706311e838f3a9efca468160fe67f30487a1 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 5 Apr 2020 09:34:22 -0400 Subject: [PATCH] hecl: Allow Time instances to be constexpr Some constructors accept primitive values. These can be made constexpr. --- hecl/include/hecl/hecl.hpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/hecl/include/hecl/hecl.hpp b/hecl/include/hecl/hecl.hpp index 37e43ca2e..44fd9598c 100644 --- a/hecl/include/hecl/hecl.hpp +++ b/hecl/include/hecl/hecl.hpp @@ -485,20 +485,20 @@ class Time final { time_t ts; public: - Time() : ts(time(NULL)) {} - Time(time_t ti) : ts(ti) {} - Time(const Time& other) { ts = other.ts; } - time_t getTs() const { return ts; } - Time& operator=(const Time& other) { + Time() : ts(std::time(nullptr)) {} + constexpr Time(time_t ti) noexcept : ts{ti} {} + constexpr Time(const Time& other) noexcept : ts{other.ts} {} + [[nodiscard]] constexpr time_t getTs() const { return ts; } + constexpr Time& operator=(const Time& other) noexcept { ts = other.ts; return *this; } - bool operator==(const Time& other) const { return ts == other.ts; } - bool operator!=(const Time& other) const { return ts != other.ts; } - bool operator<(const Time& other) const { return ts < other.ts; } - bool operator>(const Time& other) const { return ts > other.ts; } - bool operator<=(const Time& other) const { return ts <= other.ts; } - bool operator>=(const Time& other) const { return ts >= other.ts; } + [[nodiscard]] constexpr bool operator==(const Time& other) const noexcept { return ts == other.ts; } + [[nodiscard]] constexpr bool operator!=(const Time& other) const noexcept { return ts != other.ts; } + [[nodiscard]] constexpr bool operator<(const Time& other) const noexcept { return ts < other.ts; } + [[nodiscard]] constexpr bool operator>(const Time& other) const noexcept { return ts > other.ts; } + [[nodiscard]] constexpr bool operator<=(const Time& other) const noexcept { return ts <= other.ts; } + [[nodiscard]] constexpr bool operator>=(const Time& other) const noexcept { return ts >= other.ts; } }; /**