std::ranges...ound_result(3)
okay bestie, welcome to the std::ranges...ound_result(3) page from the C++ Standard Libary manual π
. The class in question is std::ranges::in_found_result, and it's literally the "iterator + found flag" combo meal, no cap.
π NAME π
std::ranges::in_found_result β std::ranges::in_found_result
β¨ Synopsis β¨
The header/declaration tea is:
Defined in header <algorithm>
template< class I > (since C++20)
struct in_found_result;
ranges::in_found_result is a class template that provides a way to store an iterator and a boolean flag as a single unit. One little package, two data members, very demure π
This class template has no base classes or declared members other than those shown below. Thus it is suitable for use with structured bindings. iykyk β¨
All special member functions of this class template are implicitly declared, which makes specializations be aggregate classes, and propagate triviality, potentially-throwing-ness, and constexpr-ness of corresponding operations on data members.
π§ Template parameters π§
Iβ the type of the iterator that theranges::in_found_resultstores.
π Data members π
The member-name / definition situation is:
inβ a value (that is supposed to be an iterator) of typeI. It is declared with[[no_unique_address]]attribute. (public member object)foundβ a boolean flag (that may show whether an appropriate range can be found) of typebool. (public member object)
π Member functions π
std::ranges::in_found_result::operator in_found_result<I2>
template<class I2>
requires std::convertible_to<const I&, I2> (1)
constexpr operator in_found_result<I2>() const &;
template<class I2>
requires std::convertible_to<I, I2> (2)
constexpr operator in_found_result<I2>() &&;
Converts *this to the result by constructing every data member of the result from the corresponding member of *this.
- Equivalent to
return {in, found};. - Equivalent to
return {std::move(in), found};.
π Standard library π
The following standard library functions use ranges::in_found_result as the return type:
Algorithm functions
ranges::next_permutation(C++20) β generates the next greater lexicographic permutation of a range of elements (niebloid)ranges::prev_permutation(C++20) β generates the next smaller lexicographic permutation of a range of elements (niebloid)
πΈ Synopsis πΈ (the code one)
namespace std::ranges
{
template<class I>
struct in_found_result
{
[[no_unique_address]] I in;
bool found;
template<class I2>
requires std::convertible_to<const I&, I2>
constexpr operator in_found_result<I2>() const &
{
return {in, found};
}
template<class I2>
requires std::convertible_to<I, I2>
constexpr operator in_found_result<I2>() &&
{
return {std::move(in), found};
}
};
}
π¦ Notes π¦
Each standard library algorithm that uses this family of return types declares a new alias type, e.g. using merge_result = in_in_out_result<I1, I2, O>;.
The names for such aliases are formed by adding the suffix "_result" to the algorithm's name. So, the return type of std::ranges::merge can be named as std::ranges::merge_result.
Unlike std::pair and std::tuple, this class template has data members of meaningful names. not the mysterious first / second situation, we love to see it π
π₯ Example π₯
// Run this code
#include <algorithm>
#include <iostream>
#include <iterator>
#include <ranges>
int main()
{
int v[] {1, 2, 3};
const auto result = std::ranges::next_permutation(v);
std::ranges::for_each(std::cbegin(v), result.in, [](int e)
{std::cout << e << ' ';});
std::cout << std::boolalpha << "\n" "result.found: " <<
result.found << '\n';
}
π Output π
1 3 2
result.found = true
π See also π
pairβ implements binary tuple, i.e. a pair of values (class template)tuple(C++11) β implements fixed size container, which holds elements of possibly different types (class template)
mwah π β source: http://cppreference.com, version/date: 2024.06.10. bye bestie, go slay those ranges π«Ά
π¦ 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