Question Details

No question body available.

Tags

c++ c++-concepts

Answers (2)

July 18, 2026 Score: 0 Rep: 606 Quality: Low Completeness: 50%

The fold expression is hiding which type failed. If you split the check into a per-type concept, most compilers will report the specific instantiation that doesn't satisfy the constraint.

For example:

template
concept hasupdate =
    requires(updatefunct& cb) {
        { cb = &UpdateTraits::update };
    };

template concept updatetraits = (hasupdate && ...);

Then if double is missing, the compiler is much more likely to point at hasupdate instead of just saying the whole fold expression evaluated to false.

July 18, 2026 Score: 0 Rep: 6,323 Quality: Low Completeness: 60%

Here is one solution. The idea is keep an alias of the type that failed, and try to use a function that is deleted for everything except a sentinel (in this case void):

#include 
#include 
#include 

template using updatefunct = UpdateResultType ()(Sink&, T);

template struct has_applicable_update { using result = void; };

template struct has_applicable_update { static constexpr auto current_value = requires(update_func_t& cb) { { cb = &UpdateTraits::update }; };

using result = std::conditional_t< current_value, typename has_applicable_update::result, T >; };

template consteval bool concept_satisfied_for_type() = delete;

template consteval bool concept_satisfied_for_type() { return true; }

template concept update_traits = concept_satisfied_for_type();

template void do_stuff();

struct my_traits{ static int update(std::vector&, int); //static double* update(std::vector&, double); };

int main() { dostuff(); }

If the concept is satisfied, typename hasapplicableupdate::result is void, and conceptsatisfiedfortype returns true. Otherwise, it tried to call the deleted specialization, and substitution fails:

: In function 'int main()':
:53:24: error: no matching function for call to 'dostuff()'
   53 |     dostuff();
      |     ~~~~~~~~~~~~~~~~~~~^~
:53:24: note: there is 1 candidate
:39:6: note: candidate 1: 'template  requires  updatetraits void dostuff()'
   39 | void dostuff();
      |      ^~~~~~~~
:39:6: note: template argument deduction/substitution failed:
:39:6: note: constraints not satisfied
: In substitution of 'template  requires  updatetraits void dostuff() [with UpdateTraits = mytraits]':
:53:24:   required from here
   53 |     dostuff();
      |     ~~~~~~~~~~~~~~~~~~~^~
:36:9:   required for the satisfaction of 'updatetraits' [with UpdateTraits = mytraits]
:36:139: error: use of deleted function 'consteval bool conceptsatisfiedfortype() [with T = double]'
   36 | concept updatetraits = conceptsatisfiedfortype();

GCC 16 emits a god error message when using std::issamev. This one works also for GCC 15.