std::indire...y_predicate(3)
π NAME π
std::indirect_binary_predicate β literally the same thing again bestie, std::indirect_binary_predicate π«Ά
Okay so real talk, this page is from the C++ Standard Libary manual (yes that's how it's spelled on the page, don't come for me π) and it's all about one very specific little concept. Let's get into it β¨
β¨ SYNOPSIS β¨
First things first, where does it live? Defined in header <iterator> π
template< class F, class I1, class I2 >
concept indirect_binary_predicate =
std::indirectly_readable<I1> &&
std::indirectly_readable<I2> &&
std::copy_constructible<F> &&
std::predicate<F&, std::iter_value_t<I1>&,
std::iter_value_t<I2>&> &&
std::predicate<F&, std::iter_value_t<I1>&,
(since C++20)
std::iter_reference_t<I2>> &&
std::predicate<F&, std::iter_reference_t<I1>,
std::iter_value_t<I2>&> &&
std::predicate<F&, std::iter_reference_t<I1>,
std::iter_reference_t<I2>> &&
std::predicate<F&, std::iter_common_reference_t<I1>,
std::iter_common_reference_t<I2>>;
It's been around since C++20, and yes, that whole thing is one giant && chain. It's giving "concept with a lot of trust issues" π but honestly? Iconic.
So what is it actually doing? The concept indirect_binary_predicate specifies requirements for algorithms that call binary predicates as their arguments. That's the whole gig πΈ
And here's the key difference between this and std::predicate, bestie β write this down:
indirect_binary_predicateis applied to the types thatI1andI2reference, not toI1andI2themselves. π
That's it. That's the plot twist. The way it peeks through the iterator instead of looking at the iterator directly? Main character energy fr.
π Semantic requirements π
F, I1, and I2 model indirect_binary_predicate only if all the concepts it subsumes are modeled. No shortcuts, no vibes-only modeling, no cap π
π¦ the vibes, summarised π¦
std::indirectly_readable<I1>βI1has to be readable, non-negotiablestd::indirectly_readable<I2>β same energy forI2, equality slaystd::copy_constructible<F>β your predicateFmust be copy constructible, it's literally the bare minimumstd::predicate<F&, std::iter_value_t<I1>&, std::iter_value_t<I2>&>β value refs, value refs πstd::predicate<F&, std::iter_value_t<I1>&, std::iter_reference_t<I2>>β value ref meets referencestd::predicate<F&, std::iter_reference_t<I1>, std::iter_value_t<I2>&>β the other way round, we stan symmetrystd::predicate<F&, std::iter_reference_t<I1>, std::iter_reference_t<I2>>β reference meets reference β¨std::predicate<F&, std::iter_common_reference_t<I1>, std::iter_common_reference_t<I2>>β and the common reference finale, the closing number, the bows π
Every single one of those has to hold. All of them. It's an all-or-nothing concept, iykyk π
lowkey a warning bestie: if even one of thosestd::predicatechecks fails, orI1/I2aren'tstd::indirectly_readable, orFisn'tstd::copy_constructible, then the concept is simply not satisfied. There's no partial credit, no half-modeling, nada. π
π§ source & sign-off π§
This little beauty came from http://cppreference.com, dated 2024.06.10, and the manual page is std::indire...y_predicate(3) β yes the title got truncated, she's mysterious like that π
Go forth and model your concepts correctly, bestie. Slay, periodt, and may all your predicates be std::predicate βπ₯π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms