std::indirect_result_t(3)
π NAME
std::indirect_result_t β std::indirect_result_t (yes bestie, sheβs self-titled π
). okay so this is the alias template that gets the result type of invoking an invocable F on the dereferenced results of indirectly_readable types Is.... Itβs giving type-level matchmaking, no cap.
πΈ Synopsis πΈ
Defined in header <iterator> π
template< class F, class... Is >
requires (std::indirectly_readable<Is> && ...) &&
std::invocable<F, std::iter_reference_t<Is>...>
(since C++20) β¨
using indirect_result_t = std::invoke_result_t<F,
std::iter_reference_t<Is>...>;
The alias template indirect_result_t obtains the result type of invoking an invocable type F on the result of dereferencing indirectly_readable types Is.... literally thatβs the whole vibe.
π Template parameters π
Fβ an invocable type (the callable bestie doing the invoking)Isβ indirectly readable types that are dereferenced to arguments (the derefβd cuties handed over as arguments)
β¨ Example β¨
run this code, bestie:
// Run this code
#include <iterator>
#include <type_traits>
struct Fn
{
long operator()(const int&);
int operator()(int&&);
short operator()(int, int) const;
auto operator()(const float) -> int&;
void operator()(int[8]);
};
static_assert(
std::is_same_v<std::indirect_result_t<Fn, const int*>, long> and
std::is_same_v<std::indirect_result_t<Fn,
std::move_iterator<int*>>, int> and
std::is_same_v<std::indirect_result_t<const Fn, int*, int*>, short>
and
std::is_same_v<std::indirect_result_t<Fn, float*>, int&> and
std::is_same_v<std::indirect_result_t<Fn, int**>, void>
);
int main() {}
π See also π
result_ofβ deduces the result type of invoking a callable object with a set of arguments;(C++11)(removed in C++20)(class template)invoke_resultβ deduces the result type of invoking a callable object with a set of arguments;(C++17)
π source/version: http://cppreference.com Β· date: 2024.06.10 β footer folded into a cute sign-off, mwah! π«Άβ¨
π¦ 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