operator==,!=,<,<=,>,>=,<=>(std::thread::id) - cppreference.com

From cppreference.com

Defined in header

<thread>

booloperator==(std::thread::idlhs,std::thread::idrhs)noexcept; (1) (since C++11)booloperator!=(std::thread::idlhs,std::thread::idrhs)noexcept; (2) (since C++11)
(until C++20)booloperator<(std::thread::idlhs,std::thread::idrhs)noexcept; (3) (since C++11)
(until C++20)booloperator<=(std::thread::idlhs,std::thread::idrhs)noexcept; (4) (since C++11)
(until C++20)booloperator>(std::thread::idlhs,std::thread::idrhs)noexcept; (5) (since C++11)
(until C++20)booloperator>=(std::thread::idlhs,std::thread::idrhs)noexcept; (6) (since C++11)
(until C++20)std::strong_orderingoperator<=>(std::thread::idlhs,std::thread::idrhs)noexcept; (7) (since C++20)Compares two thread identifiers.

1,2) Checks whether lhs and rhs represent either the same thread, or no thread.

3-7) Compares lhs and rhs in an unspecified total ordering.

The <, <=, >, >=, and != operators are

synthesized

from operator<=> and operator== respectively.

(since C++20)Parameters

lhs, rhs - thread identifiers to compare Return value

1-6)true if the corresponding relation holds, false otherwise.

7)std::strong_ordering::less if lhs is less than rhs in the total ordering; otherwise std::strong_ordering::greater if rhs is less than lhs in the total ordering; otherwise std::strong_ordering::equal.

Complexity

Constant.

Example

Run this code

#include<cassert>#include<chrono>#include<iostream>#include<thread>intmain(){autowork=[]{std::this_thread::sleep_for(std::chrono::seconds(1));};std::threadt1(work);std::threadt2(work);assert(t1.get_id()==t1.get_id()andt2.get_id()==t2.get_id()andt1.get_id()!=t2.get_id());if(constautocmp=t1.get_id()<=>t2.get_id();cmp<0)std::cout<<"id1 < id2\n";elsestd::cout<<"id1 > id2\n";std::cout<<"id1: "<<t1.get_id()<<"\n""id2: "<<t2.get_id()<<'\n';t1.join();t2.join();}Possible output:

id1 > id2 id1: 139741717640896 id2: 139741709248192 See also