From 0e36a6025fd6f8a41a18878104b9bb0b27f7b030 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Tue, 7 May 2019 08:25:18 -0600 Subject: [PATCH] tools.h spread to multiple files --- src/include/units/bits/concepts.h | 46 ++++++++++++++++ src/include/units/bits/hacks.h | 33 +++++++++++ .../units/bits/{tools.h => ratio_tools.h} | 55 ------------------- src/include/units/bits/type_list.h | 1 - src/include/units/bits/upcasting.h | 54 ++++++++++++++++++ src/include/units/dimension.h | 2 +- src/include/units/quantity.h | 1 + src/include/units/unit.h | 1 + test/test_tools.cpp | 2 +- 9 files changed, 137 insertions(+), 58 deletions(-) create mode 100644 src/include/units/bits/concepts.h create mode 100644 src/include/units/bits/hacks.h rename src/include/units/bits/{tools.h => ratio_tools.h} (66%) create mode 100644 src/include/units/bits/upcasting.h diff --git a/src/include/units/bits/concepts.h b/src/include/units/bits/concepts.h new file mode 100644 index 00000000..730d1770 --- /dev/null +++ b/src/include/units/bits/concepts.h @@ -0,0 +1,46 @@ +// The MIT License (MIT) +// +// Copyright (c) 2018 Mateusz Pusz +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#pragma once + +#include + +namespace units { + + template + concept bool Number = std::experimental::ranges::Regular && + std::experimental::ranges::StrictTotallyOrdered && + requires(T a, T b) { + { a + b } -> T; + { a - b } -> T; + { a * b } -> T; + { a / b } -> T; + { -a } -> T; + { a += b } -> T&; + { a -= b } -> T&; + { a *= b } -> T&; + { a /= b } -> T&; + { T{0} };// can construct a T from a zero + // … + } ; + +} // namespace units diff --git a/src/include/units/bits/hacks.h b/src/include/units/bits/hacks.h new file mode 100644 index 00000000..6485de28 --- /dev/null +++ b/src/include/units/bits/hacks.h @@ -0,0 +1,33 @@ +// The MIT License (MIT) +// +// Copyright (c) 2018 Mateusz Pusz +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#pragma once + +namespace std { + + template + struct type_identity { using type = T; }; + + template + using type_identity_t = typename type_identity::type; + +} diff --git a/src/include/units/bits/tools.h b/src/include/units/bits/ratio_tools.h similarity index 66% rename from src/include/units/bits/tools.h rename to src/include/units/bits/ratio_tools.h index 00094b5d..c992e35d 100644 --- a/src/include/units/bits/tools.h +++ b/src/include/units/bits/ratio_tools.h @@ -22,40 +22,11 @@ #pragma once -#include #include #include -namespace std { - - template - struct type_identity { using type = T; }; - - template - using type_identity_t = typename type_identity::type; - -} - namespace units { - template - concept bool Number = std::experimental::ranges::Regular && - std::experimental::ranges::StrictTotallyOrdered && - requires(T a, T b) { - { a + b } -> T; - { a - b } -> T; - { a * b } -> T; - { a / b } -> T; - { -a } -> T; - { a += b } -> T&; - { a -= b } -> T&; - { a *= b } -> T&; - { a /= b } -> T&; - { T{0} };// can construct a T from a zero - // … - } ; - - // static_sign template @@ -110,30 +81,4 @@ namespace units { template using common_ratio_t = typename common_ratio::type; - // upcasting - - template - struct upcast_base { - using base_type = BaseType; - }; - - template - concept bool Upcastable = - requires { - typename T::base_type; - } && - std::experimental::ranges::DerivedFrom>; - - template - using upcast_from = typename T::base_type; - - template - using upcast_to = std::type_identity; - - template - struct upcasting_traits : upcast_to {}; - - template - using upcasting_traits_t = typename upcasting_traits::type; - } // namespace units diff --git a/src/include/units/bits/type_list.h b/src/include/units/bits/type_list.h index 5a493e8a..d14969e2 100644 --- a/src/include/units/bits/type_list.h +++ b/src/include/units/bits/type_list.h @@ -22,7 +22,6 @@ #pragma once -#include #include namespace mp { diff --git a/src/include/units/bits/upcasting.h b/src/include/units/bits/upcasting.h new file mode 100644 index 00000000..1f8c687b --- /dev/null +++ b/src/include/units/bits/upcasting.h @@ -0,0 +1,54 @@ +// The MIT License (MIT) +// +// Copyright (c) 2018 Mateusz Pusz +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#pragma once + +#include +#include + +namespace units { + + template + struct upcast_base { + using base_type = BaseType; + }; + + template + concept bool Upcastable = + requires { + typename T::base_type; + } && + std::experimental::ranges::DerivedFrom>; + + template + using upcast_from = typename T::base_type; + + template + using upcast_to = typename std::type_identity; + + template + struct upcasting_traits : upcast_to {}; + + template + using upcasting_traits_t = typename upcasting_traits::type; + +} // namespace units diff --git a/src/include/units/dimension.h b/src/include/units/dimension.h index 650879ae..de432a2c 100644 --- a/src/include/units/dimension.h +++ b/src/include/units/dimension.h @@ -22,7 +22,7 @@ #pragma once -#include +#include #include namespace units { diff --git a/src/include/units/quantity.h b/src/include/units/quantity.h index 0aad7ff3..8dd98f5e 100644 --- a/src/include/units/quantity.h +++ b/src/include/units/quantity.h @@ -23,6 +23,7 @@ #pragma once #include +#include #include #include diff --git a/src/include/units/unit.h b/src/include/units/unit.h index edb68f94..3125f465 100644 --- a/src/include/units/unit.h +++ b/src/include/units/unit.h @@ -23,6 +23,7 @@ #pragma once #include +#include namespace units { diff --git a/test/test_tools.cpp b/test/test_tools.cpp index 46cefacf..d65b0270 100644 --- a/test/test_tools.cpp +++ b/test/test_tools.cpp @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "units/bits/tools.h" +#include "units/bits/ratio_tools.h" namespace {