From 6646051e65453f7425ac87a1284aa079e7d2494f Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Thu, 4 Apr 2019 11:00:40 +0200 Subject: [PATCH] Hand written concepts replaced with Casey Carter's repository --- CMakeLists.txt | 2 +- conanfile.py | 2 ++ example/example.cpp | 2 +- src/CMakeLists.txt | 4 +++ src/include/units/bits/stdconcepts.h | 48 ---------------------------- src/include/units/bits/tools.h | 4 +-- src/include/units/dimension.h | 2 +- src/include/units/quantity.h | 17 +++++----- src/include/units/si/frequency.h | 2 +- src/include/units/si/length.h | 2 +- src/include/units/si/time.h | 2 +- src/include/units/si/velocity.h | 2 +- src/include/units/unit.h | 2 +- 13 files changed, 24 insertions(+), 67 deletions(-) delete mode 100644 src/include/units/bits/stdconcepts.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 5dd89d06..1d9fe9db 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/conanfile.py b/conanfile.py index 4fa5de51..5476b79d 100644 --- a/conanfile.py +++ b/conanfile.py @@ -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) diff --git a/example/example.cpp b/example/example.cpp index cfcb101a..d5ec64d7 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -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>(distance).count() << " meters.\n"; + << quantity_cast>(distance).count() << " meters.\n"; } void foo() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 629fa2a0..388721c5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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 $ diff --git a/src/include/units/bits/stdconcepts.h b/src/include/units/bits/stdconcepts.h deleted file mode 100644 index 88596fe9..00000000 --- a/src/include/units/bits/stdconcepts.h +++ /dev/null @@ -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 -#include - -namespace mp { - - namespace std_concepts { - - template - concept bool Same = std::is_same_v; - - template - concept bool ConvertibleTo = - std::is_convertible_v && - requires(From (&f)()) { - static_cast(f()); - }; - - template - concept bool DerivedFrom = - std::is_base_of_v && - std::is_convertible_v; - - } // namespace std_concepts -} // namespace mp diff --git a/src/include/units/bits/tools.h b/src/include/units/bits/tools.h index 56524e53..42c781c3 100644 --- a/src/include/units/bits/tools.h +++ b/src/include/units/bits/tools.h @@ -22,7 +22,7 @@ #pragma once -#include "stdconcepts.h" +#include #include #include @@ -38,8 +38,6 @@ namespace std { namespace units { - using namespace mp::std_concepts; // todo Remove when std::concepts will arrive - template concept bool Number = requires(T a, T b) { { a + b } -> T; diff --git a/src/include/units/dimension.h b/src/include/units/dimension.h index 5f4d5e54..827eb39f 100644 --- a/src/include/units/dimension.h +++ b/src/include/units/dimension.h @@ -102,7 +102,7 @@ namespace units { concept bool Dimension = std::is_empty_v && detail::is_dimension && - DerivedFrom; + std::experimental::ranges::DerivedFrom; // dim_invert diff --git a/src/include/units/quantity.h b/src/include/units/quantity.h index 0280fff1..bc4e018f 100644 --- a/src/include/units/quantity.h +++ b/src/include/units/quantity.h @@ -30,7 +30,7 @@ namespace units { // is_quantity template - requires Same + requires std::experimental::ranges::Same class quantity; namespace detail { @@ -95,7 +95,7 @@ namespace units { } // namespace detail template - requires Same constexpr + requires std::experimental::ranges::Same constexpr To quantity_cast(const quantity& q) { using c_ratio = std::ratio_divide; @@ -116,7 +116,7 @@ namespace units { // quantity template - requires Same + requires std::experimental::ranges::Same class quantity { Rep value_; @@ -130,17 +130,18 @@ namespace units { quantity() = default; quantity(const quantity&) = default; - template Rep2> + template Rep2> requires treat_as_floating_point || (!treat_as_floating_point) constexpr explicit quantity(const Rep2& r) : value_{static_cast(r)} { } template - requires Same && ConvertibleTo && - (treat_as_floating_point || - (std::ratio_divide::den == 1 && - !treat_as_floating_point)) + requires std::experimental::ranges::Same && + std::experimental::ranges::ConvertibleTo && + (treat_as_floating_point || + (std::ratio_divide::den == 1 && + !treat_as_floating_point)) constexpr quantity(const Q2& q) : value_{quantity_cast(q).count()} { } diff --git a/src/include/units/si/frequency.h b/src/include/units/si/frequency.h index 20685f57..433f905f 100644 --- a/src/include/units/si/frequency.h +++ b/src/include/units/si/frequency.h @@ -52,7 +52,7 @@ namespace units { using frequency = quantity; template - concept bool Frequency = Quantity && Same; + concept bool Frequency = Quantity && std::experimental::ranges::Same; // ... diff --git a/src/include/units/si/length.h b/src/include/units/si/length.h index 10d2d90a..e879253a 100644 --- a/src/include/units/si/length.h +++ b/src/include/units/si/length.h @@ -46,7 +46,7 @@ namespace units { using length = quantity; template - concept bool Length = Quantity && Same; + concept bool Length = Quantity && std::experimental::ranges::Same; namespace literals { diff --git a/src/include/units/si/time.h b/src/include/units/si/time.h index ee8ce0cb..29605c05 100644 --- a/src/include/units/si/time.h +++ b/src/include/units/si/time.h @@ -53,7 +53,7 @@ namespace units { template - concept bool Time = Quantity && Same; + concept bool Time = Quantity && std::experimental::ranges::Same; // ... diff --git a/src/include/units/si/velocity.h b/src/include/units/si/velocity.h index 08ccd21a..579b1c5a 100644 --- a/src/include/units/si/velocity.h +++ b/src/include/units/si/velocity.h @@ -44,7 +44,7 @@ namespace units { using velocity = quantity; template - concept bool Velocity = Quantity && Same; + concept bool Velocity = Quantity && std::experimental::ranges::Same; // ... diff --git a/src/include/units/unit.h b/src/include/units/unit.h index 42e338b0..965ae609 100644 --- a/src/include/units/unit.h +++ b/src/include/units/unit.h @@ -50,6 +50,6 @@ namespace units { concept bool Unit = std::is_empty_v && detail::is_unit && - DerivedFrom; + std::experimental::ranges::DerivedFrom; } // namespace units