Skip to content

Commit

Permalink
Backport concept isInstantiation
Browse files Browse the repository at this point in the history
  • Loading branch information
gpicciuca committed Feb 10, 2025
1 parent ed2d6cf commit 1770f2c
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 32 deletions.
36 changes: 19 additions & 17 deletions benchmark/JoinAlgorithmBenchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -770,27 +770,29 @@ class GeneralInterfaceImplementation : public BenchmarkInterface {
};
};
auto generateBiggerEqualLambdaDesc =
[](const ad_utility::isInstantiation<
ad_utility::ConstConfigOptionProxy> auto& option,
const auto& minimumValue, bool canBeEqual) {
return absl::StrCat("'", option.getConfigOption().getIdentifier(),
"' must be bigger than",
canBeEqual ? ", or equal to," : "", " ",
minimumValue, ".");
};
[]<typename OptionType,
typename = std::enable_if_t<ad_utility::isInstantiation<
OptionType, ad_utility::ConstConfigOptionProxy>>>(
const OptionType& option, const auto& minimumValue,
bool canBeEqual) {
return absl::StrCat("'", option.getConfigOption().getIdentifier(),
"' must be bigger than",
canBeEqual ? ", or equal to," : "", " ", minimumValue,
".");
};

// Object with a `operator()` for the `<=` operator.
auto lessEqualLambda = std::less_equal<size_t>{};
auto generateLessEqualLambdaDesc =
[](const ad_utility::isInstantiation<
ad_utility::ConstConfigOptionProxy> auto& lhs,
const ad_utility::isInstantiation<
ad_utility::ConstConfigOptionProxy> auto& rhs) {
return absl::StrCat("'", lhs.getConfigOption().getIdentifier(),
"' must be smaller than, or equal to, "
"'",
rhs.getConfigOption().getIdentifier(), "'.");
};
[]<typename OptionType,
typename = std::enable_if_t<ad_utility::isInstantiation<
OptionType, ad_utility::ConstConfigOptionProxy>>>(
const OptionType& lhs, const OptionType& rhs) {
return absl::StrCat("'", lhs.getConfigOption().getIdentifier(),
"' must be smaller than, or equal to, "
"'",
rhs.getConfigOption().getIdentifier(), "'.");
};

// Adding the validators.

Expand Down
4 changes: 2 additions & 2 deletions src/engine/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -730,8 +730,8 @@ auto Server::cancelAfterDeadline(
// _____________________________________________________________________________
auto Server::setupCancellationHandle(
const ad_utility::websocket::QueryId& queryId, TimeLimit timeLimit)
-> ad_utility::isInstantiation<
CancellationHandleAndTimeoutTimerCancel> auto {
-> QL_CONCEPT_OR_NOTHING(ad_utility::isInstantiation<
CancellationHandleAndTimeoutTimerCancel>) auto {
auto cancellationHandle = queryRegistry_.getCancellationHandle(queryId);
AD_CORRECTNESS_CHECK(cancellationHandle);
cancellationHandle->startWatchDog();
Expand Down
12 changes: 8 additions & 4 deletions src/engine/Server.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ class Server {

using SharedCancellationHandle = ad_utility::SharedCancellationHandle;

template <ad_utility::isInstantiation<absl::Cleanup> CancelTimeout>
template <typename CancelTimeout,
typename = std::enable_if_t<
ad_utility::isInstantiation<CancelTimeout, absl::Cleanup>>>
struct CancellationHandleAndTimeoutTimerCancel {
SharedCancellationHandle handle_;
/// Object of type `absl::Cleanup` that when destroyed cancels the timer
Expand All @@ -105,7 +107,9 @@ class Server {
// Clang doesn't seem to be able to automatically deduce the type correctly.
// and GCC 11 thinks deduction guides are not allowed within classes.
#ifdef __clang__
template <ad_utility::isInstantiation<absl::Cleanup> CancelTimeout>
template <typename CancelTimeout,
typename = std::enable_if_t<
ad_utility::isInstantiation<CancelTimeout, absl::Cleanup>>>
CancellationHandleAndTimeoutTimerCancel(SharedCancellationHandle,
CancelTimeout)
-> CancellationHandleAndTimeoutTimerCancel<CancelTimeout>;
Expand Down Expand Up @@ -262,8 +266,8 @@ class Server {
/// member can be invoked to cancel the imminent cancellation via timeout.
auto setupCancellationHandle(const ad_utility::websocket::QueryId& queryId,
TimeLimit timeLimit)
-> ad_utility::isInstantiation<
CancellationHandleAndTimeoutTimerCancel> auto;
-> QL_CONCEPT_OR_NOTHING(ad_utility::isInstantiation<
CancellationHandleAndTimeoutTimerCancel>) auto;

/// Check if the access token is valid. Return true if the access token
/// exists and is valid. Return false if there's no access token passed.
Expand Down
11 changes: 6 additions & 5 deletions src/engine/sparqlExpressions/SparqlExpressionTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -334,11 +334,12 @@ std::optional<ExpressionResult> evaluateOnSpecializedFunctionsIfPossible(
// for multiple `ValueGetters` because there can be multiple `ValueGetters` as
// well as zero or more `SpezializedFunctions`, but there can only be a single
// parameter pack in C++.
template <
size_t NumOperands,
ad_utility::isInstantiation<FunctionAndValueGetters>
FunctionAndValueGettersT,
ad_utility::isInstantiation<SpecializedFunction>... SpecializedFunctions>
template <size_t NumOperands,
QL_CONCEPT_OR_TYPENAME(
ad_utility::isInstantiation<FunctionAndValueGetters>)
FunctionAndValueGettersT,
QL_CONCEPT_OR_TYPENAME(ad_utility::isInstantiation<
SpecializedFunction>)... SpecializedFunctions>
struct Operation {
private:
using OriginalValueGetters = typename FunctionAndValueGettersT::ValueGetters;
Expand Down
8 changes: 4 additions & 4 deletions src/util/TypeTraits.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ struct FirstWrapper : public std::type_identity<T> {};
/// isInstantiation<std::vector<int>, std::vector> == true;
/// isInstantiation<const std::vector<int>&, std::vector> == false;
template <typename T, template <typename...> typename TemplatedType>
concept isInstantiation =
CPP_concept isInstantiation =
detail::IsInstantiationOf<TemplatedType>::template Instantiation<T>::value;

/// The concept is fulfilled iff `T` is `ad_utility::SimilarTo` an
Expand All @@ -94,7 +94,7 @@ concept isInstantiation =
/// similarToInstantiation<std::vector, std::vector<int>> == true;
/// similarToInstantiation<std::vector, const std::vector<int>&> == true;
template <typename T, template <typename...> typename TemplatedType>
concept similarToInstantiation =
CPP_concept similarToInstantiation =
isInstantiation<std::decay_t<T>, TemplatedType>;

/// @brief The concept is fulfilled if `T` is an instantiation of any
Expand All @@ -103,15 +103,15 @@ concept similarToInstantiation =
/// similarToAnyInstantiationOf<std::vector, std::vector<int>,
/// std::vector<char>> == true
template <typename T, template <typename...> typename... Ts>
concept similarToAnyInstantiationOf = (... || similarToInstantiation<T, Ts>);
CPP_concept similarToAnyInstantiationOf = (... || similarToInstantiation<T, Ts>);

/// isVector<T> is true if and only if T is an instantiation of std::vector
template <typename T>
constexpr static bool isVector = isInstantiation<T, std::vector>;

/// isTuple<T> is true if and only if T is an instantiation of std::tuple
template <typename T>
concept isTuple = isInstantiation<T, std::tuple>;
CPP_concept isTuple = isInstantiation<T, std::tuple>;

/// isVariant<T> is true if and only if T is an instantiation of std::variant
template <typename T>
Expand Down

0 comments on commit 1770f2c

Please sign in to comment.