#include <iostream>
#include <algorithm>
#include <list>
#include <vector>
#include <deque>
#include <string>
#include <utility>
using namespace std;
// create empty deque of strings
deque<string> coll;
// insert several elements
coll.assign(3, "string");
coll.push_back("last string");
coll.push_front("first string");
coll
{ "first string", "string", "string", "string", "last string" }
template<typename T>
void print_deque(const deque<T> & coll) {
// print elements separated by newlines
copy(coll.begin(), coll.end(), ostream_iterator<string>(cout, "\n"));
}
print_deque(coll);
first string string string string last string
// remove first and last element
coll.pop_front();
coll.pop_back();
print_deque(coll);
string string string
// insert ``another'' into every element but the first
for (unsigned i = 1; i < coll.size(); ++i)
{
coll[i] = "another " + coll[i];
}
print_deque(coll);
string another string another string
// change size to four elements
coll.resize(4, "resized string");
print_deque(coll);
string another string another string resized string
vector<char> v; // list container for characters
// append elements from 'a' to 'z';
for (char c = 'a'; c <= 'z'; ++c) v.push_back(c);
// shuffle them
random_shuffle(v.begin(), v.end());
auto collection = list<char>(v.begin(), v.end());
collection
{ 'w', 'e', 'g', 'a', 'z', 'j', 'r', 'u', 'n', 'p', 'i', 'f', 's', 'q', 'y', 'x', 'd', 'c', 'b', 'm', 'o', 'k', 'h', 'v', 'l', 't' }
// printing
void print_list(list<char> collection) {
for (auto elem : collection) // range - based FOR loop
cout << elem << " ";
cout << endl;
}
print_list(collection)
w e g a z j r u n p i f s q y x d c b m o k h v l t
sort(collection.begin(), collection.end());
In file included from input_line_5:1: In file included from /home/dakoop/.conda/envs/cling-new/include/xeus/xinterpreter.hpp:13: In file included from /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/functional:65: /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_algo.h:1974:22: error: invalid operands to binary expression ('std::_List_iterator<char>' and 'std::_List_iterator<char>') std::__lg(__last - __first) * 2, ~~~~~~ ^ ~~~~~~~ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_algo.h:4873:12: note: in instantiation of function template specialization 'std::__sort<std::_List_iterator<char>, __gnu_cxx::__ops::_Iter_less_iter>' requested here std::__sort(__first, __last, __gnu_cxx::__ops::__iter_less_iter()); ^ input_line_31:2:2: note: in instantiation of function template specialization 'std::sort<std::_List_iterator<char> >' requested here sort(collection.begin(), collection.end()); ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_bvector.h:214:3: note: candidate function not viable: no known conversion from 'std::_List_iterator<char>' to 'const std::_Bit_iterator_base' for 1st argument operator-(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_iterator.h:415:5: note: candidate template ignored: could not match 'reverse_iterator' against '_List_iterator' operator-(const reverse_iterator<_IteratorL>& __x, ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_iterator.h:1209:5: note: candidate template ignored: could not match 'move_iterator' against '_List_iterator' operator-(const move_iterator<_IteratorL>& __x, ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/valarray_after.h:406:5: note: candidate template ignored: could not match '_Expr' against '_List_iterator' _DEFINE_EXPR_BINARY_OPERATOR(-, __minus) ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/valarray_after.h:344:5: note: expanded from macro '_DEFINE_EXPR_BINARY_OPERATOR' operator _Op(const _Expr<_Dom1, typename _Dom1::value_type>& __v, \ ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/valarray_after.h:406:5: note: candidate template ignored: could not match '_Expr' against '_List_iterator' /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/valarray_after.h:357:5: note: expanded from macro '_DEFINE_EXPR_BINARY_OPERATOR' operator _Op(const _Expr<_Dom, typename _Dom::value_type>& __v, \ ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/valarray_after.h:406:5: note: candidate template ignored: could not match '_Expr' against '_List_iterator' /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/valarray_after.h:370:5: note: expanded from macro '_DEFINE_EXPR_BINARY_OPERATOR' operator _Op(const typename _Dom::value_type& __t, \ ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/valarray_after.h:406:5: note: candidate template ignored: could not match '_Expr' against '_List_iterator' /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/valarray_after.h:383:5: note: expanded from macro '_DEFINE_EXPR_BINARY_OPERATOR' operator _Op(const _Expr<_Dom,typename _Dom::value_type>& __e, \ ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/valarray_after.h:406:5: note: candidate template ignored: could not match '_Expr' against '_List_iterator' /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/valarray_after.h:396:5: note: expanded from macro '_DEFINE_EXPR_BINARY_OPERATOR' operator _Op(const valarray<typename _Dom::value_type>& __v, \ ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/valarray:1186:1: note: candidate template ignored: could not match 'valarray' against '_List_iterator' _DEFINE_BINARY_OPERATOR(-, __minus) ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/valarray:1155:5: note: expanded from macro '_DEFINE_BINARY_OPERATOR' operator _Op(const valarray<_Tp>& __v, const valarray<_Tp>& __w) \ ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/valarray:1186:1: note: candidate template ignored: could not match 'valarray' against '_List_iterator' /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/valarray:1166:5: note: expanded from macro '_DEFINE_BINARY_OPERATOR' operator _Op(const valarray<_Tp>& __v, \ ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/valarray:1186:1: note: candidate template ignored: could not match 'valarray' against '_List_iterator' /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/valarray:1177:5: note: expanded from macro '_DEFINE_BINARY_OPERATOR' operator _Op(const typename valarray<_Tp>::value_type& __t, \ ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_deque.h:370:5: note: candidate template ignored: could not match '_Deque_iterator' against '_List_iterator' operator-(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x, ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_deque.h:382:5: note: candidate template ignored: could not match '_Deque_iterator' against '_List_iterator' operator-(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x, ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/complex:361:5: note: candidate template ignored: could not match 'complex' against '_List_iterator' operator-(const complex<_Tp>& __x, const complex<_Tp>& __y) ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/complex:370:5: note: candidate template ignored: could not match 'complex' against '_List_iterator' operator-(const complex<_Tp>& __x, const _Tp& __y) ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/complex:379:5: note: candidate template ignored: could not match 'complex' against '_List_iterator' operator-(const _Tp& __x, const complex<_Tp>& __y) ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/complex:456:5: note: candidate function template not viable: requires single argument '__x', but 2 arguments were provided operator-(const complex<_Tp>& __x) ^ In file included from input_line_5:1: In file included from /home/dakoop/.conda/envs/cling-new/include/xeus/xinterpreter.hpp:13: In file included from /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/functional:65: /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_algo.h:1888:18: error: invalid operands to binary expression ('std::_List_iterator<char>' and 'std::_List_iterator<char>') if (__last - __first > int(_S_threshold)) ~~~~~~ ^ ~~~~~~~ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_algo.h:1976:9: note: in instantiation of function template specialization 'std::__final_insertion_sort<std::_List_iterator<char>, __gnu_cxx::__ops::_Iter_less_iter>' requested here std::__final_insertion_sort(__first, __last, __comp); ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_algo.h:4873:12: note: in instantiation of function template specialization 'std::__sort<std::_List_iterator<char>, __gnu_cxx::__ops::_Iter_less_iter>' requested here std::__sort(__first, __last, __gnu_cxx::__ops::__iter_less_iter()); ^ input_line_31:2:2: note: in instantiation of function template specialization 'std::sort<std::_List_iterator<char> >' requested here sort(collection.begin(), collection.end()); ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_bvector.h:214:3: note: candidate function not viable: no known conversion from 'std::_List_iterator<char>' to 'const std::_Bit_iterator_base' for 1st argument operator-(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_iterator.h:415:5: note: candidate template ignored: could not match 'reverse_iterator' against '_List_iterator' operator-(const reverse_iterator<_IteratorL>& __x, ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_iterator.h:1209:5: note: candidate template ignored: could not match 'move_iterator' against '_List_iterator' operator-(const move_iterator<_IteratorL>& __x, ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/valarray_after.h:406:5: note: candidate template ignored: could not match '_Expr' against '_List_iterator' _DEFINE_EXPR_BINARY_OPERATOR(-, __minus) ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/valarray_after.h:344:5: note: expanded from macro '_DEFINE_EXPR_BINARY_OPERATOR' operator _Op(const _Expr<_Dom1, typename _Dom1::value_type>& __v, \ ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/valarray_after.h:406:5: note: candidate template ignored: could not match '_Expr' against '_List_iterator' /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/valarray_after.h:357:5: note: expanded from macro '_DEFINE_EXPR_BINARY_OPERATOR' operator _Op(const _Expr<_Dom, typename _Dom::value_type>& __v, \ ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/valarray_after.h:406:5: note: candidate template ignored: could not match '_Expr' against '_List_iterator' /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/valarray_after.h:370:5: note: expanded from macro '_DEFINE_EXPR_BINARY_OPERATOR' operator _Op(const typename _Dom::value_type& __t, \ ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/valarray_after.h:406:5: note: candidate template ignored: could not match '_Expr' against '_List_iterator' /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/valarray_after.h:383:5: note: expanded from macro '_DEFINE_EXPR_BINARY_OPERATOR' operator _Op(const _Expr<_Dom,typename _Dom::value_type>& __e, \ ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/valarray_after.h:406:5: note: candidate template ignored: could not match '_Expr' against '_List_iterator' /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/valarray_after.h:396:5: note: expanded from macro '_DEFINE_EXPR_BINARY_OPERATOR' operator _Op(const valarray<typename _Dom::value_type>& __v, \ ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/valarray:1186:1: note: candidate template ignored: could not match 'valarray' against '_List_iterator' _DEFINE_BINARY_OPERATOR(-, __minus) ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/valarray:1155:5: note: expanded from macro '_DEFINE_BINARY_OPERATOR' operator _Op(const valarray<_Tp>& __v, const valarray<_Tp>& __w) \ ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/valarray:1186:1: note: candidate template ignored: could not match 'valarray' against '_List_iterator' /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/valarray:1166:5: note: expanded from macro '_DEFINE_BINARY_OPERATOR' operator _Op(const valarray<_Tp>& __v, \ ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/valarray:1186:1: note: candidate template ignored: could not match 'valarray' against '_List_iterator' /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/valarray:1177:5: note: expanded from macro '_DEFINE_BINARY_OPERATOR' operator _Op(const typename valarray<_Tp>::value_type& __t, \ ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_deque.h:370:5: note: candidate template ignored: could not match '_Deque_iterator' against '_List_iterator' operator-(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x, ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_deque.h:382:5: note: candidate template ignored: could not match '_Deque_iterator' against '_List_iterator' operator-(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x, ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/complex:361:5: note: candidate template ignored: could not match 'complex' against '_List_iterator' operator-(const complex<_Tp>& __x, const complex<_Tp>& __y) ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/complex:370:5: note: candidate template ignored: could not match 'complex' against '_List_iterator' operator-(const complex<_Tp>& __x, const _Tp& __y) ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/complex:379:5: note: candidate template ignored: could not match 'complex' against '_List_iterator' operator-(const _Tp& __x, const complex<_Tp>& __y) ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/complex:456:5: note: candidate function template not viable: requires single argument '__x', but 2 arguments were provided operator-(const complex<_Tp>& __x) ^
Interpreter Error:
collection.sort();
print_list(collection);
a b c d e f g h i j k l m n o p q r s t u v w x y z
collection.sort(std::greater<char>());
print_list(collection);
z y x w v u t s r q p o n m l k j i h g f e d c b a
random_shuffle(collection.begin(), collection.end());
print_list(collection);
In file included from input_line_5:1: In file included from /home/dakoop/.conda/envs/cling-new/include/xeus/xinterpreter.hpp:13: In file included from /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/functional:65: /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_algo.h:4613:43: error: invalid operands to binary expression ('std::_List_iterator<char>' and 'int') for (_RandomAccessIterator __i = __first + 1; __i != __last; ++__i) ~~~~~~~ ^ ~ input_line_34:2:2: note: in instantiation of function template specialization 'std::random_shuffle<std::_List_iterator<char> >' requested here random_shuffle(collection.begin(), collection.end()); ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_bvector.h:303:3: note: candidate function not viable: no known conversion from 'std::_List_iterator<char>' to 'std::ptrdiff_t' (aka 'long') for 1st argument operator+(ptrdiff_t __n, const _Bit_iterator& __x) ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_bvector.h:393:3: note: candidate function not viable: no known conversion from 'std::_List_iterator<char>' to 'std::ptrdiff_t' (aka 'long') for 1st argument operator+(ptrdiff_t __n, const _Bit_const_iterator& __x) ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_iterator.h:423:5: note: candidate template ignored: could not match 'reverse_iterator<type-parameter-0-0>' against 'int' operator+(typename reverse_iterator<_Iterator>::difference_type __n, ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_iterator.h:1216:5: note: candidate template ignored: could not match 'move_iterator<type-parameter-0-0>' against 'int' operator+(typename move_iterator<_Iterator>::difference_type __n, ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/basic_string.h:6023:5: note: candidate template ignored: could not match 'basic_string' against '_List_iterator' operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/basic_string.h:6060:5: note: candidate template ignored: could not match 'basic_string' against '_List_iterator' operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/basic_string.h:6076:5: note: candidate template ignored: could not match 'basic_string' against '_List_iterator' operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, _CharT __rhs) ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/basic_string.h:6088:5: note: candidate template ignored: could not match 'basic_string' against '_List_iterator' operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs, ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/basic_string.h:6094:5: note: candidate template ignored: could not match 'basic_string' against '_List_iterator' operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/basic_string.h:6100:5: note: candidate template ignored: could not match 'basic_string' against '_List_iterator' operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs, ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/basic_string.h:6112:5: note: candidate template ignored: could not match 'const _CharT *' against 'std::_List_iterator<char>' operator+(const _CharT* __lhs, ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/basic_string.h:6118:5: note: candidate template ignored: could not match 'basic_string<type-parameter-0-0, type-parameter-0-1, type-parameter-0-2>' against 'int' operator+(_CharT __lhs, ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/basic_string.h:6124:5: note: candidate template ignored: could not match 'basic_string' against '_List_iterator' operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs, ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/basic_string.h:6130:5: note: candidate template ignored: could not match 'basic_string' against '_List_iterator' operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs, ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/basic_string.tcc:1158:5: note: candidate template ignored: could not match 'const _CharT *' against 'std::_List_iterator<char>' operator+(const _CharT* __lhs, ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/basic_string.tcc:1174:5: note: candidate template ignored: could not match 'basic_string<type-parameter-0-0, type-parameter-0-1, type-parameter-0-2>' against 'int' operator+(_CharT __lhs, const basic_string<_CharT, _Traits, _Alloc>& __rhs) ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/valarray_after.h:405:5: note: candidate template ignored: could not match '_Expr' against '_List_iterator' _DEFINE_EXPR_BINARY_OPERATOR(+, __plus) ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/valarray_after.h:344:5: note: expanded from macro '_DEFINE_EXPR_BINARY_OPERATOR' operator _Op(const _Expr<_Dom1, typename _Dom1::value_type>& __v, \ ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/valarray_after.h:405:5: note: candidate template ignored: could not match '_Expr' against '_List_iterator' /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/valarray_after.h:357:5: note: expanded from macro '_DEFINE_EXPR_BINARY_OPERATOR' operator _Op(const _Expr<_Dom, typename _Dom::value_type>& __v, \ ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/valarray_after.h:405:5: note: candidate template ignored: could not match '_Expr<type-parameter-0-0, typename type-parameter-0-0::value_type>' against 'int' /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/valarray_after.h:370:5: note: expanded from macro '_DEFINE_EXPR_BINARY_OPERATOR' operator _Op(const typename _Dom::value_type& __t, \ ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/valarray_after.h:405:5: note: candidate template ignored: could not match '_Expr' against '_List_iterator' /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/valarray_after.h:383:5: note: expanded from macro '_DEFINE_EXPR_BINARY_OPERATOR' operator _Op(const _Expr<_Dom,typename _Dom::value_type>& __e, \ ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/valarray_after.h:405:5: note: candidate template ignored: could not match '_Expr<type-parameter-0-0, typename type-parameter-0-0::value_type>' against 'int' /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/valarray_after.h:396:5: note: expanded from macro '_DEFINE_EXPR_BINARY_OPERATOR' operator _Op(const valarray<typename _Dom::value_type>& __v, \ ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/valarray:1185:1: note: candidate template ignored: could not match 'valarray' against '_List_iterator' _DEFINE_BINARY_OPERATOR(+, __plus) ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/valarray:1155:5: note: expanded from macro '_DEFINE_BINARY_OPERATOR' operator _Op(const valarray<_Tp>& __v, const valarray<_Tp>& __w) \ ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/valarray:1185:1: note: candidate template ignored: could not match 'valarray' against '_List_iterator' /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/valarray:1166:5: note: expanded from macro '_DEFINE_BINARY_OPERATOR' operator _Op(const valarray<_Tp>& __v, \ ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/valarray:1185:1: note: candidate template ignored: could not match 'valarray<type-parameter-0-0>' against 'int' /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/valarray:1177:5: note: expanded from macro '_DEFINE_BINARY_OPERATOR' operator _Op(const typename valarray<_Tp>::value_type& __t, \ ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_deque.h:393:5: note: candidate template ignored: could not match '_Deque_iterator<type-parameter-0-0, type-parameter-0-1, type-parameter-0-2>' against 'int' operator+(ptrdiff_t __n, const _Deque_iterator<_Tp, _Ref, _Ptr>& __x) ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/complex:331:5: note: candidate template ignored: could not match 'complex' against '_List_iterator' operator+(const complex<_Tp>& __x, const complex<_Tp>& __y) ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/complex:340:5: note: candidate template ignored: could not match 'complex' against '_List_iterator' operator+(const complex<_Tp>& __x, const _Tp& __y) ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/complex:349:5: note: candidate template ignored: could not match 'complex<type-parameter-0-0>' against 'int' operator+(const _Tp& __x, const complex<_Tp>& __y) ^ /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/complex:450:5: note: candidate function template not viable: requires single argument '__x', but 2 arguments were provided operator+(const complex<_Tp>& __x) ^
Interpreter Error:
string s = "Hello", s2 = ", World", s3 = ", DeKalb";
s.size()
5
s + s2
"Hello, World"
s2 == s3
input_line_17:2:5: note: use '=' to turn this equality comparison into an assignment s2 == s3 ^~ =
false
s2 = s3;
s + s2
"Hello, DeKalb"
int arr[] = { 1,2,3 };
vector <int> v(arr, arr + sizeof(arr) / sizeof(arr[0]));
vector <int> v1(3); // 3 elements, {0,0,0}
copy(v.begin(), v.end(), v1.begin()+1);
v1
{ 0, 1, 2 }
pair <string, double> p1, p2("tomatoes", 2.30), p3(p2);
p1 = make_pair("lightbulbs", 0.99);
p2.first = "shoes";
p2.second = 39.90;
cout << "The price of " << p1.first << " is $" << p1.second << endl;
cout << "The price of " << p2.first << " is $" << p2.second << endl;
cout << "The price of " << p3.first << " is $" << p3.second << endl;
The price of lightbulbs is $0.99 The price of shoes is $39.9 The price of tomatoes is $2.3
vector<int> v1{1,2,3,4,5}, v2{1,2,5,4,5};
auto mypair = mismatch(v1.begin(), v1.end(), v2.begin());
cout << "Mismatching elements: " << *mypair.first
<< " and " << *mypair.second << endl;
Mismatching elements: 3 and 5
vector<int> v{ 10,20,30,30,20,10,10,20 };
sort(v.begin(), v.end());
v
{ 10, 10, 10, 20, 20, 20, 30, 30 }
auto bounds = equal_range(v.begin(), v.end(), 20);
cout << "bounds at positions " << (bounds.first - v.begin())
<< " and " << (bounds.second - v.begin()) << endl;
bounds at positions 3 and 6
vector<int> v2{ 10,20,30,30,20,10,10,20 };
auto bounds = equal_range(v2.begin(), v2.end(), 20);
cout << "bounds at positions " << (bounds.first - v2.begin())
<< " and " << (bounds.second - v2.begin()) << endl;
bounds at positions 1 and 8
// replace
vector<int> v{ 10,20,30,30,20,10,10,20 };
replace(v.begin(), v.end(), 20, 99);
v
{ 10, 99, 30, 30, 99, 10, 10, 99 }
string s = "thim im a temt mtring.";
replace(s.begin(), s.end(), 'm' , 's');
s
"this is a test string."
string s2 = "this is a test string.";
s2.replace(s2.begin(), s2.end(), "magic")
"magic"
string s3 = "this is a test string.";
s3.replace(s3.end() - 12, s3.end() - 8, "magic")
"this is a magic string."
string str = "The brick walls are not there to keep us out. The brick walls are there to give us a chance to show how badly we want something.";
str.substr(4, 5)
"brick"
vector <int> myvector(8);
fill(myvector.begin(), myvector.begin()+4, 5);
fill(myvector.begin()+3, myvector.end()-2, 8);
myvector
{ 5, 5, 5, 8, 8, 8, 0, 0 }
list <int> mylist(8, 2);
fill_n(mylist.begin(), 4, 5);
fill_n(++(++(++mylist.begin())), 3, 7);
// fill_n(mylist.begin() + 3, 3, 7);
mylist
{ 5, 5, 5, 7, 7, 7, 2, 2 }
int current = 0;
vector <int> myvector(8);
generate(myvector.begin(), myvector.end(), [¤t] () { return ++current; });
myvector
int myints[] = { 20,40,60,80,100 };
int otherints[] = { 20,40,50,70,90 };
deque<int> mydeque(myints, myints+3);
cout << std::boolalpha << equal(mydeque.begin(), mydeque.end(), myints) << endl
<< std::boolalpha << equal(mydeque.begin(), mydeque.end(), otherints) << endl;
vector <int> v{2,4,2,5};
auto it2 = remove(v.begin(), v.end(), 2);
for(auto it = v.begin(); it != v.end(); ++it)
cout << * it << " ";
4 5 2 5
for(auto it = v.begin(); it != it2; ++it)
cout << * it << " ";
4 5
vector<int> v{2,3,4,5,6,7,8};
auto it2 = remove_if(v.begin(), v.end(), [] (int i) { return i % 2 == 1; });
vector<int> v2(v.begin(), it2);
v2
{ 2, 4, 6, 8 }
// bool fun1(int value) { return value > 9; }
// void fun2(int value) { cout << value*value << ' '; }
// int fun3(int value) { return ++value; }
ostream_iterator <int> output(cout, " ");
vector <int> v{ 10, 2, 8, 1, 9, 3, 8, 8, 9, 12 };
cout << count(v.begin (), v.end(), 8) << endl; // 3
cout << count_if(v.begin (), v.end(), [] (int val) { return val > 9; }) << endl; // 2
cout << *(min_element(v.begin(), v.end())) << endl; // 1
cout << *(max_element(v.begin(), v.end())) << endl; // 12
for_each (v.begin(), v.end(), [] (int val) { cout << val*val << ' '; });
cout << endl; //100 4 64 1 81 9 64 64 81 144
transform(v.begin(), v.end(), v.begin(), [] (int val) { return val + 1; });
copy(v.begin(), v.end(), output);
3 2 1 12 100 4 64 1 81 9 64 64 81 144 11 3 9 2 10 4 9 9 10 13
int init = 100;
int numbers[] = { 10,20,30,40 };
accumulate(numbers, numbers + 4, init)
200