Skip to content

Commit a670f4f

Browse files
authored
Update 009_initializer_list_empty.cpp
1 parent c8f0c3b commit a670f4f

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed
Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,32 @@
1-
1
1+
#include <iostream>
2+
#include <vector>
3+
4+
template <class T>
5+
void print(const T& container)
6+
{
7+
if ( std::empty(container) )
8+
{
9+
std::cout << "Empty\n";
10+
}
11+
else
12+
{
13+
std::cout << "Elements:";
14+
for ( const auto& element : container )
15+
std::cout << ' ' << element;
16+
std::cout << '\n';
17+
}
18+
}
19+
20+
int main()
21+
{
22+
std::vector<int> c = { 1, 2, 3 };
23+
print(c);
24+
c.clear();
25+
print(c);
26+
27+
int array[] = { 4, 5, 6 };
28+
print(array);
29+
30+
auto il = { 7, 8, 9 };
31+
print(il);
32+
}

0 commit comments

Comments
 (0)