Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
teaching
nprg041
Šmelko
CZ Cvičenia z Cpp
Commits
d77786a5
Commit
d77786a5
authored
Oct 20, 2021
by
Šmelko Adam Mgr.
Browse files
Add Cv4.
parent
42bfb08a
Changes
4
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
d77786a5
...
...
@@ -26,6 +26,7 @@ Deadliny:
| 30.09.2021 | Úvod, nároky, syntaxe, I/O |
[
CV1
](
https://gitlab.mff.cuni.cz/teaching/nprg041/Smelko/cpp-cvika/-/blob/master/prezentacie/Cv1.pdf
)
|
| 07.10.2021 | Stringy, znaky, streamy |
[
CV2
](
https://gitlab.mff.cuni.cz/teaching/nprg041/Smelko/cpp-cvika/-/blob/master/prezentacie/Cv2.pdf
)
|
| 14.10.2021 | Hlavičky, třídy, objekty |
[
CV3
](
https://gitlab.mff.cuni.cz/teaching/nprg041/Smelko/cpp-cvika/-/blob/master/prezentacie/Cv3.pdf
)
|
| 21.10.2021 | Kontejnery, iterátory |
[
CV4
](
https://gitlab.mff.cuni.cz/teaching/nprg041/Smelko/cpp-cvika/-/blob/master/prezentacie/Cv4.pdf
)
|
## Úkoly:
...
...
prezentacie/Cv4.pdf
0 → 100644
View file @
d77786a5
File added
vzorove-priklady/implicit_constructors.cpp
0 → 100644
View file @
d77786a5
#include <vector>
#include <string>
#include <memory>
struct
CopyableStructure
{
std
::
vector
<
std
::
string
>
data
;
};
struct
NotCopyableStructure
{
std
::
unique_ptr
<
int
>
data
;
};
int
main
()
{
{
CopyableStructure
original
;
CopyableStructure
copy
(
original
);
}
{
NotCopyableStructure
original
;
// does not compile because std::unique_ptr does not have copy constructor
// so copy constructor of NotCopyableStructure is not implicitly generated
NotCopyableStructure
copy
(
original
);
}
return
0
;
}
\ No newline at end of file
vzorove-priklady/iterators.cpp
0 → 100644
View file @
d77786a5
#include <vector>
#include <string>
#include <iostream>
struct
person
{
std
::
string
name
;
int
age
;
};
class
person_catalog
{
std
::
vector
<
person
>
persons_
;
public:
person_catalog
(
std
::
vector
<
person
>
persons
)
:
persons_
(
std
::
move
(
persons
))
{}
struct
iterator
{
person_catalog
&
owner
;
int
current_index
;
iterator
(
person_catalog
&
owner
,
int
starting_index
)
:
owner
(
owner
),
current_index
(
starting_index
)
{}
person
&
operator
*
()
{
return
owner
.
persons_
[
current_index
];
}
person
*
operator
->
()
{
return
&
owner
.
persons_
[
current_index
];
}
bool
operator
!=
(
const
iterator
&
oth
)
const
{
return
&
owner
!=
&
oth
.
owner
||
current_index
!=
oth
.
current_index
;
}
iterator
&
operator
++
()
{
current_index
++
;
return
*
this
;
}
};
iterator
begin
()
{
return
iterator
(
*
this
,
0
);
}
iterator
end
()
{
return
iterator
(
*
this
,
persons_
.
size
());
}
};
int
main
()
{
std
::
vector
<
person
>
persons
;
persons
.
push_back
(
person
{
"Adam"
,
24
});
persons
.
push_back
(
person
{
"Eva"
,
18
});
persons
.
push_back
(
person
{
"Michal"
,
13
});
person_catalog
catalog
(
persons
);
for
(
auto
it
=
catalog
.
begin
();
it
!=
catalog
.
end
();
++
it
)
{
std
::
cout
<<
it
->
name
<<
" "
;
}
std
::
cout
<<
std
::
endl
;
for
(
auto
person
:
catalog
)
std
::
cout
<<
person
.
name
<<
" "
;
std
::
cout
<<
std
::
endl
;
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment