Difference between revisions of "cpp/iterator/indirect result t"
From cppreference.com
(add example) |
(adjust example) |
||
Line 23: | Line 23: | ||
struct Fn { | struct Fn { | ||
− | |||
long operator()(const int&); | long operator()(const int&); | ||
int operator()(int&&); | int operator()(int&&); | ||
+ | short operator()(int, int) const; | ||
}; | }; | ||
− | |||
static_assert(std::is_same_v<std::indirect_result_t<Fn, const int*>, long>); | static_assert(std::is_same_v<std::indirect_result_t<Fn, const int*>, long>); | ||
static_assert(std::is_same_v<std::indirect_result_t<Fn, std::move_iterator<int*>>, int>); | static_assert(std::is_same_v<std::indirect_result_t<Fn, std::move_iterator<int*>>, int>); | ||
+ | static_assert(std::is_same_v<std::indirect_result_t<const Fn, int*, int*>, short>); | ||
int main() {} | int main() {} |
Revision as of 09:40, 17 September 2023
Defined in header <iterator>
|
||
template< class F, class... Is > requires (std::indirectly_readable<Is> && ...) && |
(since C++20) | |
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...
.
Template parameters
F | - | an invocable type |
Is | - | indirectly readable types that are dereferenced to arguments |
Example
Run this code
#include <iterator> #include <type_traits> struct Fn { long operator()(const int&); int operator()(int&&); short operator()(int, int) const; }; static_assert(std::is_same_v<std::indirect_result_t<Fn, const int*>, long>); static_assert(std::is_same_v<std::indirect_result_t<Fn, std::move_iterator<int*>>, int>); static_assert(std::is_same_v<std::indirect_result_t<const Fn, int*, int*>, short>); int main() {}
See also
(C++11)(removed in C++20)(C++17) |
deduces the result type of invoking a callable object with a set of arguments (class template) |