Skip to content

chore: C++20 RoutingAlgorithm concept#7529

Open
DennisOSRM wants to merge 2 commits intomasterfrom
poc/concepts-routing-algorithm
Open

chore: C++20 RoutingAlgorithm concept#7529
DennisOSRM wants to merge 2 commits intomasterfrom
poc/concepts-routing-algorithm

Conversation

@DennisOSRM
Copy link
Copy Markdown
Collaborator

This draft PR introduces a C++20 RoutingAlgorithm concept and constrains core templates (RoutingAlgorithms, SearchEngineData, Engine) to it.

Motivation:

  • Make compile-time requirements explicit
  • Begin migrating away from TMP to C++20 concepts

Changes:

  • include/engine/concepts.hpp (new)
  • include/engine/routing_algorithms.hpp (updated)
  • include/engine/search_engine_data.hpp (updated)
  • include/engine/engine.hpp (updated)

Testing:

  • Project builds with C++20 (verified locally with Debug build)

Notes:

  • This PR is a PoC; it preserves runtime polymorphism via existing interfaces. Future work: constrain DataFacade and convert SFINAE utilities to concepts.

Add include/engine/concepts.hpp and constrain templates (RoutingAlgorithms, SearchEngineData, Engine) using the RoutingAlgorithm concept.

This is a proof-of-concept to document and enforce the compile-time interface required by algorithm marker types and to enable incremental migration from TMP to C++20 concepts.

Build/test: cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug && cmake --build build -j4

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@DennisOSRM DennisOSRM marked this pull request as ready for review May 6, 2026 21:21
Copilot AI review requested due to automatic review settings May 6, 2026 21:21
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Introduces a C++20 RoutingAlgorithm concept and applies it to constrain key engine templates, with the goal of making compile-time expectations explicit and starting a migration away from TMP/SFINAE-style constraints.

Changes:

  • Added include/engine/concepts.hpp defining routing_algorithms::RoutingAlgorithm.
  • Constrained SearchEngineData, RoutingAlgorithms, and Engine templates to RoutingAlgorithm.
  • Updated relevant headers to include the new concepts header where needed.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
include/engine/concepts.hpp Adds the new RoutingAlgorithm concept describing/validating the expected algorithm marker-type interface.
include/engine/routing_algorithms.hpp Constrains RoutingAlgorithms and its out-of-class definitions to the concept.
include/engine/search_engine_data.hpp Constrains SearchEngineData primary template to the concept.
include/engine/engine.hpp Constrains Engine to the concept.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +32 to +37
template <typename T>
concept RoutingAlgorithm = requires {
/* name() and identifier() are callable and return C strings */
{ name<T>() } -> std::convertible_to<const char *>;
{ identifier<T>() } -> std::convertible_to<const char *>;


#include "engine/algorithm.hpp"
#include <concepts>
#include <type_traits>
Comment thread include/engine/engine.hpp
Comment on lines 40 to +42

template <typename Algorithm> class Engine final : public EngineInterface
template <routing_algorithms::RoutingAlgorithm Algorithm>
class Engine final : public EngineInterface
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants