Namespaces
Variants

std::shared_future<T>:: valid

From cppreference.net

Concurrency support library
Threads
(C++11)
(C++20)
this_thread namespace
(C++11)
(C++11)
Cooperative cancellation
Mutual exclusion
Generic lock management
Condition variables
(C++11)
Semaphores
Latches and Barriers
(C++20)
(C++20)
Futures
(C++11)
(C++11)
(C++11)
Safe reclamation
Hazard pointers
Atomic types
(C++11)
(C++20)
Initialization of atomic types
(C++11) (deprecated in C++20)
(C++11) (deprecated in C++20)
Memory ordering
(C++11) (deprecated in C++26)
Free functions for atomic operations
Free functions for atomic flags
bool valid ( ) const noexcept ;
(C++11부터)

future가 공유 상태를 참조하는지 확인합니다.

이는 기본 생성되거나 이동된 퓨처가 아닌 경우에만 해당됩니다. std::future 와 달리, std::shared_future get() 가 호출될 때 공유 상태가 무효화되지 않습니다.

소멸자, 복사 할당 연산자, 이동 할당 연산자 또는 valid 이외의 멤버 함수가 공유 상태를 참조하지 않는 shared_future 에서 호출될 경우 동작은 정의되지 않습니다(단, 구현체는 이 경우 std::future_error 를 던져 no_state 를 표시하도록 권장됩니다). valid() false 인 shared_future 객체로부터 이동하거나 복사하는 것은 유효합니다.

목차

매개변수

(없음)

반환값

true 만약 * this 가 공유 상태를 참조하는 경우, 그렇지 않으면 false .

예제

#include <future>
#include <iostream>
int main()
{
    std::promise<void> p;
    std::shared_future<void> f = p.get_future();
    std::cout << std::boolalpha;
    std::cout << f.valid() << '\n';
    p.set_value();
    std::cout << f.valid() << '\n';
    f.get();
    std::cout << f.valid() << '\n';
}

출력:

true
true
true

참고 항목

결과가 사용 가능해질 때까지 대기
(public member function)