Skip to content

Commit 0360e98

Browse files
committed
make getNumberOfComponents a free function for functions. Update the Function concept
1 parent 8e584ab commit 0360e98

5 files changed

Lines changed: 22 additions & 4 deletions

File tree

include/MGIS/Function/FixedSizeModifier.ixx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace mgis::function {
1616
requires(N > 0) //
1717
constexpr bool FixedSizeModifier<EvaluatorType, N>::checkPreconditions(
1818
AbstractErrorHandler& eh, const EvaluatorType& values) {
19-
if (values.getNumberOfComponents() != N) {
19+
if (internals::disambiguateGetNumberOfComponents(values) != N) {
2020
return eh.registerErrorMessage("invalid number of components");
2121
}
2222
return true;

include/MGIS/Function/FixedSizeView.ixx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace mgis::function {
1616
requires(N > 0) //
1717
constexpr bool FixedSizeView<FunctionType, N>::checkPreconditions(
1818
AbstractErrorHandler& eh, const FunctionType& values) {
19-
if (values.getNumberOfComponents() != N) {
19+
if (internals::disambiguateGetNumberOfComponents(values) != N) {
2020
return eh.registerErrorMessage("invalid number of components");
2121
}
2222
return true;

include/MGIS/Function/FunctionConcept.hxx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,9 @@ namespace mgis::function {
234234
concept FunctionConcept =
235235
(SpaceConcept<
236236
std::decay_t<decltype(getSpace(std::declval<FunctionType>()))>>)&& //
237+
(requires(const FunctionType& e) {
238+
{ getNumberOfComponents(e) } -> std::same_as<mgis::size_type>;
239+
}) &&
237240
((internals::FunctionResultQuery<FunctionType>::b1) ||
238241
(internals::FunctionResultQuery<FunctionType>::b2) ||
239242
(internals::FunctionResultQuery<FunctionType>::b3) ||
@@ -341,6 +344,14 @@ namespace mgis::function {
341344
template <FunctionConcept FunctionType>
342345
constexpr decltype(auto) disambiguateGetSpace(const FunctionType&) //
343346
requires(!EvaluatorConcept<FunctionType>);
347+
/*!
348+
* This helper function allows to disambiguate the call to
349+
* the getNumberOfComponents function
350+
*/
351+
template <FunctionConcept FunctionType>
352+
constexpr mgis::size_type disambiguateGetNumberOfComponents(
353+
const FunctionType&) //
354+
requires(!EvaluatorConcept<FunctionType>);
344355

345356
/*!
346357
* \brief number of components of a type when known at compile-time,

include/MGIS/Function/FunctionConcept.ixx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,14 @@ namespace mgis::function::internals {
1717
constexpr decltype(auto) disambiguateGetSpace(const FunctionType& f) //
1818
requires(!EvaluatorConcept<FunctionType>) {
1919
return getSpace(f);
20-
}
20+
} // end of disambiguateGetSpace
21+
22+
template <FunctionConcept FunctionType>
23+
constexpr mgis::size_type disambiguateGetNumberOfComponents(
24+
const FunctionType& f) //
25+
requires(!EvaluatorConcept<FunctionType>) {
26+
return getNumberOfComponents(f);
27+
} // end of disambiguateGetNumberOfComponents
2128

2229
} // end of namespace mgis::function::internals
2330

include/MGIS/Function/Tensors/TensorView.ixx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace mgis::function {
1515
template <FunctionConcept FunctionType, TensorConcept TensorType>
1616
constexpr bool TensorView<FunctionType, TensorType>::checkPreconditions(
1717
AbstractErrorHandler& eh, const FunctionType& values) {
18-
const auto nc = values.getNumberOfComponents();
18+
const auto nc = internals::disambiguateGetNumberOfComponents(values);
1919
if (nc != compile_time_size<TensorType>) {
2020
return eh.registerErrorMessage("invalid number of components");
2121
}

0 commit comments

Comments
 (0)