Namespaces
Variants

std:: indirectly_unary_invocable, std:: indirectly_regular_unary_invocable

From cppreference.net
Iterator library
Iterator concepts
Iterator primitives
Algorithm concepts and utilities
Indirect callable concepts
indirectly_unary_invocable indirectly_regular_unary_invocable
(C++20) (C++20)
Common algorithm requirements
(C++20)
(C++20)
(C++20)
Utilities
(C++20)
Iterator adaptors
Range access
(C++11) (C++14)
(C++14) (C++14)
(C++11) (C++14)
(C++14) (C++14)
(C++17) (C++20)
(C++17)
(C++17)
헤더에 정의됨 <iterator>
std::indirectly_unary_invocable
template < class F, class I >

concept indirectly_unary_invocable =
std:: indirectly_readable < I > &&
std:: copy_constructible < F > &&
std:: invocable < F & , /*indirect-value-t*/ < I >> &&
std:: invocable < F & , std:: iter_reference_t < I >> &&
std:: common_reference_with <
std:: invoke_result_t < F & , /*indirect-value-t*/ < I >> ,

std:: invoke_result_t < F & , std:: iter_reference_t < I >>> ;
(C++20부터)
std::indirectly_regular_unary_invocable
template < class F, class I >

concept indirectly_regular_unary_invocable =
std:: indirectly_readable < I > &&
std:: copy_constructible < F > &&
std:: regular_invocable < F & , /*indirect-value-t*/ < I >> &&
std:: regular_invocable < F & , std:: iter_reference_t < I >> &&
std:: common_reference_with <
std:: invoke_result_t < F & , /*indirect-value-t*/ < I >> ,

std:: invoke_result_t < F & , std:: iter_reference_t < I >>> ;
(C++20부터)

개념들 indirectly_unary_invocable indirectly_regular_unary_invocable 는 인자로서 (정규) 단항 호출 가능 객체를 호출하는 알고리즘들의 요구사항을 명시합니다. 이러한 개념들과 std::invocable 의 주요 차이점은 이 개념들이 I 자체가 아닌, I 가 참조하는 타입에 적용된다는 점입니다.

참고 사항

indirectly_unary_invocable indirectly_regular_unary_invocable 사이의 구분은 순전히 의미론적입니다.

예제

#include <algorithm>
#include <iterator>
#include <print>
#include <ranges>
struct IntWrapper
{
    int i;
    explicit IntWrapper(int i) : i(i) {}
    IntWrapper(IntWrapper&&) = default;
    IntWrapper& operator=(IntWrapper&&) = default;
};
int main()
{
    auto ints  = std::views::iota(1, 10);
    auto print = [] (IntWrapper w) { std::print("{} ", w.i); };
    auto wrap  = [] (int i) { return IntWrapper{i}; };
    using Proj = std::projected<decltype(ints.begin()), decltype(wrap)>;
    // P2609R3 이전까지 오류 (false로 평가됨):
    // 이는 'std::iter_value_t<Proj> &'가 'IntWrapper&'와 동일하기 때문이며
    // 이는 'IntWrapper'로 변환할 수 없음 (암시적으로 삭제된 복사 생성자)
    static_assert(std::indirectly_unary_invocable<decltype(print), Proj>);
    // 위의 컴파일 타임 검사가 true로 평가되면, 다음은 올바른 형식입니다:
    std::ranges::for_each(ints, print, wrap);
}

출력:

1 2 3 4 5 6 7 8 9

결함 보고서

다음의 동작 변경 결함 보고서들은 이전에 발표된 C++ 표준에 소급 적용되었습니다.

DR 적용 대상 게시된 동작 올바른 동작
P2609R3 C++20 일부 요구사항이 std:: iter_value_t < I > &
관점에서 정의되어 프로젝션을 잘못 처리하여 F & 호출 가능과 비호환성 발생
/*indirect-value-t*/ < I > 관점에서 정의하여
이러한 프로젝션을 올바르게 처리
P2997R1 C++20 해당 개념들이 F & 가 각각 invocable
regular_invocable std:: iter_common_reference_t < I > 와 함께 만족하도록 요구
요구하지 않음