[ Web Proxy ]
URL:
Viewing: https://ru.cppreference.com/cpp/algorithm/fill [Back]  [Original]

std::fill cppreference.com
cppreference.com

std::fill

cppreference.com
 
C++
(C++20)
(C++20)
(C++11)
(C++20)
/
(C++11)
(C++11)
(C++11)
(C++17)
 
(C++20)
, ranges::copy, ranges::sort, ...
(C++17)
(C++11)(C++11)(C++11)
(C++17)
(C++11)
( )
(C++11)
/
(C++11)
(C++17)

(C++17)
(C++17)
(C++17)
C
 
<tbody> </tbody>
template< class ForwardIt, class T > void fill( ForwardIt first, ForwardIt last, const T& value );

value [firstlast).

[firstlast)
value
-
ForwardIt ForwardIterator.

()

last - first .

template< class ForwardIt, class T >
void fill(ForwardIt first, ForwardIt last, const T& value)
{
    for (; first != last; ++first) {
        *first = value;
    }
}

fill(), -1:

#include <algorithm>
#include <vector>
#include <iostream>

int main()
{
    int data[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }
    std::vector<int> v1(data, data+10);

    std::fill(v1.begin(), v1.end(), -1);

    for (vector<int>::iterator it = v1.begin(); it != v1.end(); ++it) {
        std::cout << *it << " ";
    }
    std::cout << "\n";
}

:

-1 -1 -1 -1 -1 -1 -1 -1 -1 -1

.


( ) []

( ) []
,
( ) []

Web Proxy Viewer  |  New URL  |  Original Page