std::ranges..._out_result(3)
π NAME π
okay so this is the page for std::ranges..._out_result(3) from the C++ Standard Library β yes, the header has that C++ Standard Libary typo energy, but we're not gonna roast it, we're just here for the iterators. The NAME vibe is literally:
std::ranges::in_out_out_result β std::ranges::in_out_out_result
β¨ Synopsis β¨
Defined in header <algorithm>:
template< class I, class O1, class O2 > (since C++20)
struct in_out_out_result;
ranges::in_out_out_result is a class template that provides a way to store three iterators as a single unit. Three iterators, one little bundle β it's giving main-character convenience π
.
This class template has no base classes or declared members other than those shown below. Thus it is suitable for use with structured bindings. Bestie, that means it's literally built for cute unpacking.
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. Slay for not making us write them ourselves β¨.
πΈ Template parameters πΈ
I,O1,O2β the types of the objects thatranges::in_out_out_resultstores.
π Data members π
inβ a value (that is supposed to be an iterator) of typeI. (public member object)out1β a value (that is supposed to be an iterator) of typeO1. (public member object)out2β a value (that is supposed to be an iterator) of typeO2. (public member object)
All these members are declared with [[no_unique_address]] attribute. No cap, that attribute is doing its little optimization moment π«Ά.
π«Ά Member functions π«Ά
std::ranges::in_out_out_result::operator in_out_out_result<II, OO1, OO2>
template<class II, class OO1, class OO2>
requires std::convertible_to<const I&, II> &&
std::convertible_to<const O1&, OO1> && (1)
std::convertible_to<const O2&, OO2>
constexpr operator in_out_out_result<II, OO1, OO2>() const &;
template<class II, class OO1, class OO2>
requires std::convertible_to<I, II> &&
std::convertible_to<O1, OO1> && (2)
std::convertible_to<O2, OO2>
constexpr operator in_out_out_result<II, OO1, OO2>() &&;
Converts *this to the result by constructing every data member of the result from the corresponding member of *this. Every member gets matched up like it's a group chat invite list π.
- Equivalent to
return {in, out1, out2};. - Equivalent to
return {std::move(in), std::move(out1), std::move(out2)};.
π Standard library π
The following standard library functions use ranges::in_out_out_result as the return type:
π§ Algorithm functions π§
ranges::partition_copyβ copies a range dividing the elements into two groups(C++20)(niebloid).
π Synopsis π
namespace std::ranges
{
template<class I, class O1, class O2>
struct in_out_out_result
{
[[no_unique_address]] I in;
[[no_unique_address]] O1 out1;
[[no_unique_address]] O2 out2;
template<class II, class OO1, class OO2>
requires std::convertible_to<const I&, II> &&
std::convertible_to<const O1&, OO1> &&
std::convertible_to<const O2&, OO2>
constexpr operator in_out_out_result<II, OO1, OO2>() const &
{
return {in, out1, out2};
}
template<class II, class OO1, class OO2>
requires std::convertible_to<I, II> &&
std::convertible_to<O1, OO1> &&
std::convertible_to<O2, OO2>
constexpr operator in_out_out_result<II, OO1, OO2>() &&
{
return {std::move(in), std::move(out1), std::move(out2)};
}
};
}
π 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. iykyk, it's a whole naming convention moment β¨.
Unlike std::pair and std::tuple, this class template has data members of meaningful names. Not me being obsessed with readable member names π.
π¦ Example π¦
// Run this code
#include <algorithm>
#include <array>
#include <cctype>
#include <iostream>
#include <iterator>
#include <ranges>
#include <string_view>
void print(std::string_view rem, auto first, auto last)
{
for (std::cout << rem << ": { "; first != last; ++first)
std::cout << *first << ' ';
std::cout << "}\n";
}
int main()
{
constexpr std::string_view in {"TvEeNcStOoRr"};
std::array<char, in.size()> o1, o2;
const auto result = std::ranges::partition_copy(in, o1.begin(), o2.begin(),
[](char c) { return std::isupper(c); });
print("in", in.begin(), result.in);
print("o1", o1.begin(), result.out1);
print("o2", o2.begin(), result.out2);
}
π Output π
in: { T v E e N c S t O o R r }
o1: { T E N S O R }
o2: { v e c t o r }
β See also β
pairβ implements binary tuple, i.e. a pair of values (class template)tupleβ implements fixed size container, which holds elements of possibly different(C++11)types (class template)
kisses and iterator dust π source: http://cppreference.com β’ version/date: 2024.06.10 β’ page: std::ranges..._out_result(3) π
π¦ 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