tools.h spread to multiple files

This commit is contained in:
Mateusz Pusz
2019-05-07 08:25:18 -06:00
parent a0b09969eb
commit 0e36a6025f
9 changed files with 137 additions and 58 deletions

View File

@ -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 <experimental/ranges/concepts>
namespace units {
template<typename T>
concept bool Number = std::experimental::ranges::Regular<T> &&
std::experimental::ranges::StrictTotallyOrdered<T> &&
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

View File

@ -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<typename T>
struct type_identity { using type = T; };
template<typename T>
using type_identity_t = typename type_identity<T>::type;
}

View File

@ -22,40 +22,11 @@
#pragma once
#include <experimental/ranges/concepts>
#include <ratio>
#include <type_traits>
namespace std {
template<typename T>
struct type_identity { using type = T; };
template<typename T>
using type_identity_t = typename type_identity<T>::type;
}
namespace units {
template<typename T>
concept bool Number = std::experimental::ranges::Regular<T> &&
std::experimental::ranges::StrictTotallyOrdered<T> &&
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<std::intmax_t Pn>
@ -110,30 +81,4 @@ namespace units {
template<Ratio R1, Ratio R2>
using common_ratio_t = typename common_ratio<R1, R2>::type;
// upcasting
template<typename BaseType>
struct upcast_base {
using base_type = BaseType;
};
template<typename T>
concept bool Upcastable =
requires {
typename T::base_type;
} &&
std::experimental::ranges::DerivedFrom<T, upcast_base<typename T::base_type>>;
template<Upcastable T>
using upcast_from = typename T::base_type;
template<typename T>
using upcast_to = std::type_identity<T>;
template<typename T>
struct upcasting_traits : upcast_to<T> {};
template<typename T>
using upcasting_traits_t = typename upcasting_traits<T>::type;
} // namespace units

View File

@ -22,7 +22,6 @@
#pragma once
#include <units/bits/tools.h>
#include <type_traits>
namespace mp {

View File

@ -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 <units/bits/hacks.h>
#include <experimental/ranges/concepts>
namespace units {
template<typename BaseType>
struct upcast_base {
using base_type = BaseType;
};
template<typename T>
concept bool Upcastable =
requires {
typename T::base_type;
} &&
std::experimental::ranges::DerivedFrom<T, upcast_base<typename T::base_type>>;
template<Upcastable T>
using upcast_from = typename T::base_type;
template<Upcastable T>
using upcast_to = typename std::type_identity<T>;
template<Upcastable T>
struct upcasting_traits : upcast_to<T> {};
template<Upcastable T>
using upcasting_traits_t = typename upcasting_traits<T>::type;
} // namespace units

View File

@ -22,7 +22,7 @@
#pragma once
#include <units/bits/tools.h>
#include <units/bits/upcasting.h>
#include <units/bits/type_list.h>
namespace units {

View File

@ -23,6 +23,7 @@
#pragma once
#include <units/unit.h>
#include <units/bits/concepts.h>
#include <limits>
#include <gsl/gsl-lite.hpp>

View File

@ -23,6 +23,7 @@
#pragma once
#include <units/dimension.h>
#include <units/bits/ratio_tools.h>
namespace units {

View File

@ -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 {