From a1f3114ccc1e90b4748ec2b9e1eb9ddc3e3a325c Mon Sep 17 00:00:00 2001 From: Klas Marcks Date: Sat, 17 Feb 2024 18:11:45 +0100 Subject: [PATCH] Use concepts instead of std::void_t when detecting to_child functions. --- CMakeLists.txt | 2 +- TSConfigVersion.cmake | 48 +++++++++++++++++++++--- include/ts/typesafe_coordinate_systems.h | 30 ++++----------- 3 files changed, 50 insertions(+), 30 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 534764d..dbf40dd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.18 FATAL_ERROR) set(CMAKE_CXX_STANDARD 20) -project(TS VERSION 0.2.0 LANGUAGES CXX) +project(TS VERSION 0.2.1 LANGUAGES CXX) enable_testing() diff --git a/TSConfigVersion.cmake b/TSConfigVersion.cmake index a0d2d7b..684e1ab 100644 --- a/TSConfigVersion.cmake +++ b/TSConfigVersion.cmake @@ -9,16 +9,52 @@ # The variable CVF_VERSION must be set before calling configure_file(). -set(PACKAGE_VERSION "0.2.0") +if (PACKAGE_FIND_VERSION_RANGE) + message(AUTHOR_WARNING + "`find_package()` specify a version range but the version strategy " + "(ExactVersion) of the module `${PACKAGE_FIND_NAME}` is incompatible " + "with this request. Only the lower endpoint of the range will be used.") +endif() + +set(PACKAGE_VERSION "0.2.1") + +if("0.2.1" MATCHES "^([0-9]+)\\.([0-9]+)\\.([0-9]+)") # strip the tweak version + set(CVF_VERSION_MAJOR "${CMAKE_MATCH_1}") + set(CVF_VERSION_MINOR "${CMAKE_MATCH_2}") + set(CVF_VERSION_PATCH "${CMAKE_MATCH_3}") -if("0.2.0" MATCHES "^([0-9]+\\.[0-9]+\\.[0-9]+)\\.") # strip the tweak version - set(CVF_VERSION_NO_TWEAK "${CMAKE_MATCH_1}") + if(NOT CVF_VERSION_MAJOR VERSION_EQUAL 0) + string(REGEX REPLACE "^0+" "" CVF_VERSION_MAJOR "${CVF_VERSION_MAJOR}") + endif() + if(NOT CVF_VERSION_MINOR VERSION_EQUAL 0) + string(REGEX REPLACE "^0+" "" CVF_VERSION_MINOR "${CVF_VERSION_MINOR}") + endif() + if(NOT CVF_VERSION_PATCH VERSION_EQUAL 0) + string(REGEX REPLACE "^0+" "" CVF_VERSION_PATCH "${CVF_VERSION_PATCH}") + endif() + + set(CVF_VERSION_NO_TWEAK "${CVF_VERSION_MAJOR}.${CVF_VERSION_MINOR}.${CVF_VERSION_PATCH}") else() - set(CVF_VERSION_NO_TWEAK "0.2.0") + set(CVF_VERSION_NO_TWEAK "0.2.1") endif() -if(PACKAGE_FIND_VERSION MATCHES "^([0-9]+\\.[0-9]+\\.[0-9]+)\\.") # strip the tweak version - set(REQUESTED_VERSION_NO_TWEAK "${CMAKE_MATCH_1}") +if(PACKAGE_FIND_VERSION MATCHES "^([0-9]+)\\.([0-9]+)\\.([0-9]+)") # strip the tweak version + set(REQUESTED_VERSION_MAJOR "${CMAKE_MATCH_1}") + set(REQUESTED_VERSION_MINOR "${CMAKE_MATCH_2}") + set(REQUESTED_VERSION_PATCH "${CMAKE_MATCH_3}") + + if(NOT REQUESTED_VERSION_MAJOR VERSION_EQUAL 0) + string(REGEX REPLACE "^0+" "" REQUESTED_VERSION_MAJOR "${REQUESTED_VERSION_MAJOR}") + endif() + if(NOT REQUESTED_VERSION_MINOR VERSION_EQUAL 0) + string(REGEX REPLACE "^0+" "" REQUESTED_VERSION_MINOR "${REQUESTED_VERSION_MINOR}") + endif() + if(NOT REQUESTED_VERSION_PATCH VERSION_EQUAL 0) + string(REGEX REPLACE "^0+" "" REQUESTED_VERSION_PATCH "${REQUESTED_VERSION_PATCH}") + endif() + + set(REQUESTED_VERSION_NO_TWEAK + "${REQUESTED_VERSION_MAJOR}.${REQUESTED_VERSION_MINOR}.${REQUESTED_VERSION_PATCH}") else() set(REQUESTED_VERSION_NO_TWEAK "${PACKAGE_FIND_VERSION}") endif() diff --git a/include/ts/typesafe_coordinate_systems.h b/include/ts/typesafe_coordinate_systems.h index a8956ff..2be79fa 100644 --- a/include/ts/typesafe_coordinate_systems.h +++ b/include/ts/typesafe_coordinate_systems.h @@ -1,6 +1,7 @@ #pragma once #include +#include // This file implements type-safe coordinate transformations. // @@ -91,34 +92,17 @@ // This is more complicated than finding all 'to_parent' functions as under 1. This is because // the parent systems are not aware of their children. // This a recursive procedure and the responsible function is 'down'. -// To detect existing to_child functions we use SFINAE (Substitution Failure Is Not An Error). -// The responsible functions are the overoaded find_function::to_child functions. +// To detect existing to_child functions we use 'concepts' namespace ts{ namespace find_function { -// Compile time check if a to_child function with specific arguments exists. -namespace internal { +template +concept to_child = requires(Args ... args) +{ + transform::to_child(args...); +}; -// Define template variable to_child that defaults to false. -template -constexpr bool to_child = false; - -// Specialization of templateVariable to_child. -// The template argument std::void_t(), std::declval(), std::declval()...))> -// has the 'type' ´void´ if the decltype expression is valid after substitution. -template -constexpr bool to_child(), std::declval(), std::declval()...))>, - GeometryState...> = true; -} // namespace internal - -// Interface variable to internal::to_child. -// template arguments, Arg1, Arg2, void, GeometryState..., will match the specialization above if the decltype expression can be evaluated and -// find_function::to_child will evaluate to true. Else find_function::to_child will be false. -template -constexpr bool to_child = internal::to_child; } // namespace find_function // Compile time detection of the common ancestor type of S1 and S2.