赋值(assign)
语法:
1 2 |
void assign( input_iterator start, input_iterator end ); void assign( size_type num, const TYPE &val ); |
assign()函数以迭代器start和end指示的范围为list赋值或者为list赋值num个以val为值的元素。
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 29 30 31 32 33 34 35 |
源代码 /** * @brief Assigns a given value to a %list. * @param n Number of elements to be assigned. * @param val Value to be assigned. * * This function fills a %list with @a n copies of the given * value. Note that the assignment completely changes the %list * and that the resulting %list's size is the same as the number * of elements assigned. Old data may be lost. */ void assign(size_type __n, const value_type& __val) { _M_fill_assign(__n, __val); } /** * @brief Assigns a range to a %list. * @param first An input iterator. * @param last An input iterator. * * This function fills a %list with copies of the elements in the * range [@a first,@a last). * * Note that the assignment completely changes the %list and * that the resulting %list's size is the same as the number of * elements assigned. Old data may be lost. */ template<typename _InputIterator> void assign(_InputIterator __first, _InputIterator __last) { // Check whether it's an integral type. If so, it's not an iterator. typedef typename _Is_integer<_InputIterator>::_Integral _Integral; _M_assign_dispatch(__first, __last, _Integral()); } |
测试代码
测试结果
10 10 10
5 5 5 5 5 5 5 5 5 5
8 8 8 8
《List链表assign()函数运用实例》上有1条评论
评论已关闭。