Skip to content

Commit

Permalink
Merge pull request #6 from KlasMvW/use_concepts_nottype_traits
Browse files Browse the repository at this point in the history
Use concepts not type traits
  • Loading branch information
KlasMvW authored Feb 17, 2024
2 parents e4560d2 + 3118228 commit 8af6f86
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 31 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
48 changes: 42 additions & 6 deletions TSConfigVersion.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
31 changes: 7 additions & 24 deletions include/ts/typesafe_coordinate_systems.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <type_traits>
#include <concepts>

// This file implements type-safe coordinate transformations.
//
Expand Down Expand Up @@ -91,34 +91,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 <typename... Args>
concept to_child = requires(Args ... args)
{
transform::to_child(args...);
};

// Define template variable to_child that defaults to false.
template <typename, typename, typename = void, typename...>
constexpr bool to_child = false;

// Specialization of templateVariable to_child.
// The template argument std::void_t<decltype(transform::to_child(std::declval<Arg1>(), std::declval<Arg2>(), std::declval<GeometryState>()...))>
// has the 'type' ´void´ if the decltype expression is valid after substitution.
template <typename Arg1, typename Arg2, typename... GeometryState>
constexpr bool to_child<Arg1,
Arg2,
std::void_t<decltype(transform::to_child(std::declval<Arg1>(), std::declval<Arg2>(), std::declval<GeometryState>()...))>,
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 <typename Arg1, typename Arg2, typename... GeometryState>
constexpr bool to_child = internal::to_child<Arg1, Arg2, void, GeometryState...>;
} // namespace find_function

// Compile time detection of the common ancestor type of S1 and S2.
Expand Down

0 comments on commit 8af6f86

Please sign in to comment.