If the vector is already sorted, then constructing the set
is indeed O(N)
(but in general not!).
From cppreference:
template< class InputIt >
set( InputIt first, InputIt last,
const Compare& comp = Compare(),
const Allocator& alloc = Allocator() );
Range constructor. Constructs the container with the contents of the range [first, last). If multiple elements in the range have keys that compare equivalent, it is unspecified which element is inserted
Complexity
N log(N) where N = std::distance(first, last) in general, linear in N if the range is already sorted by value_comp().
The relevant quote from the standard is:
22.4.6.2#4 Complexity: Linear in N if the range [first, last) is already sorted using comp and otherwise NlogN, where N is last - first.
The standard only specifies what containers do, not how they accomplish that. Using a red-black tree is typical but not necessary to implement a std::set
.