1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
#include <iostream>
#include <vector>
#include <algorithm>
#include <list>
int main()
{
{
std::vector<int> seq = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 } ;
seq.reserve(1000) ;
auto pointer = &*std::find( seq.begin(), seq.end(), 7 ) ;
std::cout << *pointer << '\n' ; // 7
seq.erase( std::find( seq.begin(), seq.end(), 3 ) ) ;
std::cout << *pointer << '\n' ; // 8
seq.insert( std::find( seq.begin(), seq.end(), 2 ), 6, -3 ) ;
std::cout << *pointer << '\n' ; // -3
}
{
std::list<int> seq = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 } ;
auto pointer = &*std::find( seq.begin(), seq.end(), 7 ) ;
std::cout << *pointer << '\n' ; // 7
seq.erase( std::find( seq.begin(), seq.end(), 3 ) ) ;
std::cout << *pointer << '\n' ; // 7
seq.insert( std::find( seq.begin(), seq.end(), 2 ), 6, -3 ) ;
std::cout << *pointer << '\n' ; // 7
}
}
|