From b858daedd9c84fb1b15f13f0853b654530cffe81 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Wed, 30 Sep 2020 15:14:26 +1000 Subject: [PATCH] concepts: add initial clock concept --- CMakeLists.txt | 1 + concepts/clock.hpp | 73 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 concepts/clock.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 72a3ff41..f212562a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -281,6 +281,7 @@ list ( colour.cpp colour.hpp concepts.hpp + concepts/clock.hpp container.hpp coord.hpp coord/fwd.hpp diff --git a/concepts/clock.hpp b/concepts/clock.hpp new file mode 100644 index 00000000..143ce4fe --- /dev/null +++ b/concepts/clock.hpp @@ -0,0 +1,73 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * Copyright 2020, Danny Robson + */ + +#pragma once + +#include "../concepts.hpp" + +#include +#include + +#include + + +namespace cruft::concepts { + namespace detail { + template + struct is_ratio : public std::false_type {}; + + + template + struct is_ratio< + std::ratio + > : public std::true_type { }; + }; + + template + concept clock = + numeric && + detail::is_ratio::value && + same_as> && + //same_as> && + same_as && + requires (T t) + { + typename T::rep; + typename T::period; + typename T::time_point; + typename T::duration; + + { T::is_steady } -> convertible_to; + { t.now () } -> same_as; + }; + + namespace detail { + template + concept trivial_clock_inner_type = + equality_comparable && + is_less_than_comparable_v && + default_constructible && + copy_constructible && + copy_assignable && + destructible && + numeric && + swappable; + + template + concept trivial_clock = + trivial_clock_inner_type && + trivial_clock_inner_type && + trivial_clock_inner_type && + noexcept (std::declval ().now()); + } + + template + concept trivial_clock = + detail::trivial_clock && + detail::trivial_clock; +} \ No newline at end of file