mirror of
https://github.com/mpusz/mp-units.git
synced 2025-07-31 10:57:16 +02:00
Hand written concepts replaced with Casey Carter's repository
This commit is contained in:
@ -30,7 +30,7 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/common/cmake")
|
||||
include(tools)
|
||||
|
||||
# use Conan configuration if available
|
||||
conan_init(cmake_paths)
|
||||
conan_init(cmake)
|
||||
|
||||
# project-specific compilation flags
|
||||
include(compile_flags)
|
||||
|
@ -30,6 +30,8 @@ class UnitsConan(ConanFile):
|
||||
url = "https://github.com/mpusz/units"
|
||||
description = "Physical Units library for C++"
|
||||
settings = "os", "compiler", "build_type", "arch"
|
||||
requires = ( "cmcstl2/2019.03.18@mpusz/stable" )
|
||||
generators = "cmake"
|
||||
|
||||
def build(self):
|
||||
cmake = CMake(self)
|
||||
|
@ -30,7 +30,7 @@ void foo(V v, T t)
|
||||
{
|
||||
const Length distance = v * t;
|
||||
std::cout << "A car driving " << v.count() << " km/h in a time of " << t.count() << " minutes will pass "
|
||||
<< quantity_cast<length<meter, int>>(distance).count() << " meters.\n";
|
||||
<< quantity_cast<length<meter, double>>(distance).count() << " meters.\n";
|
||||
}
|
||||
|
||||
void foo()
|
||||
|
@ -48,6 +48,10 @@ add_library(units INTERFACE)
|
||||
# include/units/bits/tools.h
|
||||
#)
|
||||
target_compile_features(units INTERFACE cxx_std_20)
|
||||
target_link_libraries(units
|
||||
INTERFACE
|
||||
CONAN_PKG::cmcstl2
|
||||
)
|
||||
target_include_directories(units
|
||||
INTERFACE
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
|
@ -1,48 +0,0 @@
|
||||
// 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 <ratio>
|
||||
#include <type_traits>
|
||||
|
||||
namespace mp {
|
||||
|
||||
namespace std_concepts {
|
||||
|
||||
template<typename T, typename U>
|
||||
concept bool Same = std::is_same_v<T, U>;
|
||||
|
||||
template<typename From, typename To>
|
||||
concept bool ConvertibleTo =
|
||||
std::is_convertible_v<From, To> &&
|
||||
requires(From (&f)()) {
|
||||
static_cast<To>(f());
|
||||
};
|
||||
|
||||
template<class Derived, class Base>
|
||||
concept bool DerivedFrom =
|
||||
std::is_base_of_v<Base, Derived> &&
|
||||
std::is_convertible_v<const volatile Derived*, const volatile Base*>;
|
||||
|
||||
} // namespace std_concepts
|
||||
} // namespace mp
|
@ -22,7 +22,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "stdconcepts.h"
|
||||
#include <experimental/ranges/concepts>
|
||||
#include <ratio>
|
||||
#include <type_traits>
|
||||
|
||||
@ -38,8 +38,6 @@ namespace std {
|
||||
|
||||
namespace units {
|
||||
|
||||
using namespace mp::std_concepts; // todo Remove when std::concepts will arrive
|
||||
|
||||
template<typename T>
|
||||
concept bool Number = requires(T a, T b) {
|
||||
{ a + b } -> T;
|
||||
|
@ -102,7 +102,7 @@ namespace units {
|
||||
concept bool Dimension =
|
||||
std::is_empty_v<T> &&
|
||||
detail::is_dimension<typename T::base_type> &&
|
||||
DerivedFrom<T, typename T::base_type>;
|
||||
std::experimental::ranges::DerivedFrom<T, typename T::base_type>;
|
||||
|
||||
|
||||
// dim_invert
|
||||
|
@ -30,7 +30,7 @@ namespace units {
|
||||
// is_quantity
|
||||
|
||||
template<Dimension D, Unit U, Number Rep>
|
||||
requires Same<D, typename U::dimension>
|
||||
requires std::experimental::ranges::Same<D, typename U::dimension>
|
||||
class quantity;
|
||||
|
||||
namespace detail {
|
||||
@ -95,7 +95,7 @@ namespace units {
|
||||
} // namespace detail
|
||||
|
||||
template<Quantity To, Dimension D, Unit U, Number Rep>
|
||||
requires Same<typename To::dimension, D> constexpr
|
||||
requires std::experimental::ranges::Same<typename To::dimension, D> constexpr
|
||||
To quantity_cast(const quantity<D, U, Rep>& q)
|
||||
{
|
||||
using c_ratio = std::ratio_divide<typename U::ratio, typename To::unit::ratio>;
|
||||
@ -116,7 +116,7 @@ namespace units {
|
||||
// quantity
|
||||
|
||||
template<Dimension D, Unit U, Number Rep>
|
||||
requires Same<D, typename U::dimension>
|
||||
requires std::experimental::ranges::Same<D, typename U::dimension>
|
||||
class quantity {
|
||||
Rep value_;
|
||||
|
||||
@ -130,14 +130,15 @@ namespace units {
|
||||
quantity() = default;
|
||||
quantity(const quantity&) = default;
|
||||
|
||||
template<ConvertibleTo<rep> Rep2>
|
||||
template<std::experimental::ranges::ConvertibleTo<rep> Rep2>
|
||||
requires treat_as_floating_point<rep> || (!treat_as_floating_point<Rep2>)
|
||||
constexpr explicit quantity(const Rep2& r) : value_{static_cast<rep>(r)}
|
||||
{
|
||||
}
|
||||
|
||||
template<Quantity Q2>
|
||||
requires Same<dimension, typename Q2::dimension> && ConvertibleTo<typename Q2::rep, rep> &&
|
||||
requires std::experimental::ranges::Same<dimension, typename Q2::dimension> &&
|
||||
std::experimental::ranges::ConvertibleTo<typename Q2::rep, rep> &&
|
||||
(treat_as_floating_point<rep> ||
|
||||
(std::ratio_divide<typename Q2::unit::ratio, typename unit::ratio>::den == 1 &&
|
||||
!treat_as_floating_point<typename Q2::rep>))
|
||||
|
@ -52,7 +52,7 @@ namespace units {
|
||||
using frequency = quantity<dimension_frequency, U, Rep>;
|
||||
|
||||
template<typename T>
|
||||
concept bool Frequency = Quantity<T> && Same<typename T::dimension, dimension_frequency>;
|
||||
concept bool Frequency = Quantity<T> && std::experimental::ranges::Same<typename T::dimension, dimension_frequency>;
|
||||
|
||||
// ...
|
||||
|
||||
|
@ -46,7 +46,7 @@ namespace units {
|
||||
using length = quantity<dimension_length, U, Rep>;
|
||||
|
||||
template<typename T>
|
||||
concept bool Length = Quantity<T> && Same<typename T::dimension, dimension_length>;
|
||||
concept bool Length = Quantity<T> && std::experimental::ranges::Same<typename T::dimension, dimension_length>;
|
||||
|
||||
namespace literals {
|
||||
|
||||
|
@ -53,7 +53,7 @@ namespace units {
|
||||
|
||||
|
||||
template<typename T>
|
||||
concept bool Time = Quantity<T> && Same<typename T::dimension, dimension_time>;
|
||||
concept bool Time = Quantity<T> && std::experimental::ranges::Same<typename T::dimension, dimension_time>;
|
||||
|
||||
// ...
|
||||
|
||||
|
@ -44,7 +44,7 @@ namespace units {
|
||||
using velocity = quantity<dimension_velocity, U, Rep>;
|
||||
|
||||
template<typename T>
|
||||
concept bool Velocity = Quantity<T> && Same<typename T::dimension, dimension_velocity>;
|
||||
concept bool Velocity = Quantity<T> && std::experimental::ranges::Same<typename T::dimension, dimension_velocity>;
|
||||
|
||||
// ...
|
||||
|
||||
|
@ -50,6 +50,6 @@ namespace units {
|
||||
concept bool Unit =
|
||||
std::is_empty_v<T> &&
|
||||
detail::is_unit<typename T::base_type> &&
|
||||
DerivedFrom<T, typename T::base_type>;
|
||||
std::experimental::ranges::DerivedFrom<T, typename T::base_type>;
|
||||
|
||||
} // namespace units
|
||||
|
Reference in New Issue
Block a user