Question Details

No question body available.

Tags

c++ c++20 c++-concepts

Answers (1)

Accepted Answer Available
Accepted Answer
June 19, 2026 Score: 1 Rep: 5,357 Quality: High Completeness: 80%

This is a way to do it:

#include 

// by default, the condition is false template struct conditionimpl : std::falsetype {}; // it's always true for int and int as second parameter... template struct conditionimpl : std::truetype {}; // except for floats template struct conditionimpl : std::falsetype {};

// Just a helper actually, to match op requirement template constexpr bool condition = conditionimpl::value;

// Making the bool a concept template concept conditionconcept = condition;

// using it in order to filter input template void foo(conditionconcept auto) {}

int main() { double d{3.14}; [[maybeunused]] float f{3.14f};

// it's not OK // foo(f);

// it's not OK // foo(d);

// it's OK foo(d); }

LIVE

I think it's self explanatory.

I'm using partial specialization in order to filter the conditions.
condition boolean is a helper around the specializations.
Getting a concept from a template boolean is straigthforward.

The only "twist" is that in syntax like void foo(conditionconcept auto); or template, the first template argument is implicitly the type to which the concept is applied.

See https://cppreference.com/cpp/language/templateparameters#Typetemplate_parameter for instance.
And from the standard: https://eel.is/c++draft/temp.param#10