std::ranges::in_out_result(3)
πΈ std::ranges::in_out_result(3) πΈ
okay so bestie, this page is from the C++ Standard Libary manual β yes, that's the spelling in the header, don't come for me π
β and it's literally all about std::ranges::in_out_result. it's giving "tiny struct with main character energy" and we're obsessed. let's get into it π«Ά
β¨ NAME β¨
std::ranges::in_out_result β std::ranges::in_out_result (yep, the name line is just the name twice, iconic)
β¨ Synopsis β¨
Defined in header <algorithm>
template< class I, class O > (since C++20)
struct in_out_result;
ranges::in_out_result is a class template that provides a way to store two iterators as a single unit.
This class template has no base classes or declared members other than those shown below. Thus it is suitable for use with structured bindings.
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, O β the types of the objects that the
ranges::in_out_resultstores.
π Data members π
inβ a value (that is supposed to be an iterator) of typeI. (public member object)outβ a value (that is supposed to be an iterator) of typeO. (public member object)
All these members are declared with [[no_unique_address]] attribute.
π Member functions π
std::ranges::in_out_result::operator in_out_result<I2, O2>
template<class I2, class O2>
requires std::convertible_to<const I&, I2> &&
std::convertible_to<const O&, O2> (1)
constexpr operator in_out_result<I2, O2>() const &;
template<class I2, class O2>
requires std::convertible_to<I, I2> && std::convertible_to<O, O2>
(2)
constexpr operator in_out_result<I2, O2>() &&;
Converts *this to the result by constructing every data member of the result from the corresponding member of *this.
- Equivalent to
return {in, out};. - Equivalent to
return {std::move(in), std::move(out)};.
π Standard library π
The following standard library functions use ranges::in_out_result as the return type:
Algorithm functions
ranges::copyβ copies a range of elements to a new location.(C++20)(niebloid)ranges::copy_ifβ copies a range of elements to a new location.(C++20)(niebloid)ranges::copy_nβ copies a number of elements to a new location.(C++20)(niebloid)ranges::copy_backwardβ copies a range of elements in backwards order.(C++20)(niebloid)ranges::moveβ moves a range of elements to a new location.(C++20)(niebloid)ranges::move_backwardβ moves a range of elements to a new location in backwards order.(C++20)(niebloid)ranges::transformβ applies a function to a range of elements.(C++20)(niebloid)ranges::replace_copyβ copies a range, replacing elements satisfying specific criteria with another value.(C++20)(niebloid)ranges::replace_copy_ifβ copies a range, replacing elements satisfying specific criteria with another value.(C++20)(niebloid)ranges::remove_copyβ copies a range of elements omitting those that satisfy specific criteria.(C++20)(niebloid)ranges::remove_copy_ifβ copies a range of elements omitting those that satisfy specific criteria.(C++20)(niebloid)ranges::unique_copyβ creates a copy of some range of elements that contains no consecutive duplicates.(C++20)(niebloid)ranges::reverse_copyβ creates a copy of a range that is reversed.(C++20)(niebloid)ranges::rotate_copyβ copies and rotate a range of elements.(C++20)(niebloid)ranges::partial_sort_copyβ copies and partially sorts a range of elements.(C++20)(niebloid)ranges::set_differenceβ computes the difference between two sets.(C++20)(niebloid)
Memory functions
ranges::uninitialized_copyβ copies a range of objects to an uninitialized area of memory.(C++20)(niebloid)ranges::uninitialized_copy_nβ copies a number of objects to an uninitialized area of memory.(C++20)(niebloid)ranges::uninitialized_moveβ moves a range of objects to an uninitialized area of memory.(C++20)(niebloid)ranges::uninitialized_move_nβ moves a number of objects to an uninitialized area of memory.(C++20)(niebloid)
π Synopsis (the full code moment) π
namespace std::ranges
{
template<class I, class O>
struct in_out_result
{
[[no_unique_address]] I in;
[[no_unique_address]] O out;
template<class I2, class O2>
requires std::convertible_to<const I&, I2> &&
std::convertible_to<const O&, O2>
constexpr operator in_out_result<I2, O2>() const &
{
return {in, out};
}
template<class I2, class O2>
requires std::convertible_to<I, I2> && std::convertible_to<O,
O2>
constexpr operator in_out_result<I2, O2>() &&
{
return {std::move(in), std::move(out)};
}
};
}
π¦ 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.
π Example π
// Run this code
#include <algorithm>
#include <array>
#include <cctype>
#include <iostream>
#include <ranges>
int main()
{
constexpr char in[] = "transform" "\n";
std::array<char, sizeof(in)> out;
const auto result = std::ranges::transform(in, out.begin(),
[](char c) { return std::toupper(c); });
auto print = [](char c) { std::cout << c; };
std::ranges::for_each(std::cbegin(in), result.in, print);
std::ranges::for_each(out.cbegin(), result.out, print);
}
Output
transform
TRANSFORM
π 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 types.(C++11)(class template)
that's the whole page, bestie π«Ά β source/version: http://cppreference.com, dated 2024.06.10. now go slay some 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