In this SO answer there is the following line:
std::vector<int>(tSet.begin(), tSet.end()).swap(tUserNumbers);
Can someone explain the syntax of the portion before .swap
? Is there a name to it by which I could look it up?
In this SO answer there is the following line:
std::vector<int>(tSet.begin(), tSet.end()).swap(tUserNumbers);
Can someone explain the syntax of the portion before .swap
? Is there a name to it by which I could look it up?
std::vector<int>(tSet.begin(), tSet.end())
// ^ iterator to begin of data range
// tSet.end() is iterator to end of data range
creates a temporary variable which is of type std::vector<int>
by copying container named tSet
Is there a name to it by which I could look it up?
Look at this decription of vector constructors:
in particular at constructor (4):
template< class InputIt >
vector( InputIt first, InputIt last,
const Allocator& alloc = Allocator() );
which is called sometimes also a range constructor.