Skip to content

Commit f1501ef

Browse files
committed
pair and const: comment style
1 parent aa28e1a commit f1501ef

3 files changed

Lines changed: 45 additions & 59 deletions

File tree

‎cpp/const.cpp‎

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
/*
2-
# const
3-
4-
There are differences between the `const` keyword in C and C++.
5-
6-
Also, in C++ const can be used to qualify methods.
7-
8-
http://stackoverflow.com/questions/8908071/const-correctness-in-c-vs-c
9-
*/
1+
// # const
2+
//
3+
// There are differences between the `const` keyword in C and C++.
4+
//
5+
// Also, in C++ const can be used to qualify methods.
6+
//
7+
// http://stackoverflow.com/questions/8908071/const-correctness-in-c-vs-c
108

119
#include "common.hpp"
1210

@@ -18,11 +16,9 @@ class Class {
1816
};
1917

2018
int main() {
21-
/*
22-
In C++, consts cannot be changed not even through pointers.
23-
24-
C this is only a warning, and allows us to change ic.
25-
*/
19+
// In C++, consts cannot be changed not even through pointers.
20+
//
21+
// In C this is only a warning, and allows us to change ic.
2622
{
2723
const int i = 2;
2824
//int* ip = i;
@@ -52,37 +48,31 @@ int main() {
5248
//*icp = 1;
5349
}
5450

55-
// C is initialized by the constructor
56-
// so it is OK to do this unlike for base types
51+
// C is initialized by the constructor so it is OK to do this
52+
// without an assignment unlike for base types
5753
const Class c;
5854
}
5955

6056
// Const for classes.
6157
{
6258
const Class c;
6359

64-
// Cannot reassign:
65-
66-
//cc = Class();
67-
68-
// Cannot assign members:
69-
70-
//cc.i = 1;
71-
72-
// Can create const refs to:
73-
74-
const int& cia = c.i;
60+
// Cannot reassign.
61+
//cc = Class();
7562

76-
// Cannot create non const refs:
63+
// Cannot assign members.
64+
//cc.i = 1;
7765

78-
//int& ia = cc.i;
66+
// Can create const refs to.
67+
const int& cia = c.i;
7968

80-
/*
81-
Can only call const methods,
82-
because a non const method could change the object.
69+
// Cannot create non const refs.
70+
//int& ia = cc.i;
8371

84-
Therefore, *BE CONST OBSESSIVE!* mark as const every method that does not change the object!
85-
*/
72+
// Can only call const methods,
73+
// because a non const method could change the object.
74+
//
75+
// Therefore, *BE CONST OBSESSIVE!* mark as const every method that does not change the object!
8676
{
8777
//c.method();
8878
c.constMethod();

‎cpp/map.cpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ int main() {
116116

117117
auto found = m.find(0);
118118
assert(found != m.end());
119+
assert(found->first == 0);
119120
assert(found->second == "zero");
120121

121122
assert(m.find(2) == m.end());

‎cpp/pair.cpp‎

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
/*
2-
# pair
3-
4-
Particular case of tuple for two elements (TODO inheritance based?).
5-
6-
Methods which also exist for tuple will not be discussed.
7-
8-
Specially important because of `map`.
9-
*/
1+
// # pair
2+
//
3+
// Particular case of tuple for two elements (TODO inheritance based?).
4+
//
5+
// Methods which also exist for tuple will not be discussed.
6+
//
7+
// Specially important because of `map`, for which find() for example
8+
// returns key value tuples.
109

1110
#include "common.hpp"
1211

@@ -23,30 +22,26 @@ int main() {
2322
assert(std::get<1>(p) == p.second);
2423
}
2524

26-
/*
27-
make_pair
28-
29-
Saves re-typing the types on the constructor.
30-
31-
http://stackoverflow.com/questions/9270563/what-is-the-purpose-of-stdmake-pair-vs-the-constructor-of-stdpair/41521422#41521422
32-
*/
25+
// # make_pair
26+
//
27+
// Saves re-typing the types on the constructor.
28+
//
29+
// http://stackoverflow.com/questions/9270563/what-is-the-purpose-of-stdmake-pair-vs-the-constructor-of-stdpair/41521422#41521422
3330
{
3431
auto p = my_make_pair(1, std::string("one"));
3532
assert(p.first == 1);
3633
assert(p.second == "one");
3734
p = std::make_pair(1, "asdf");
3835
}
3936

40-
/*
41-
# Relational operators
42-
43-
Lexicographical.
44-
45-
http://stackoverflow.com/questions/2819245/is-stdpairint-stdstring-ordering-well-defined
46-
*/
37+
// # Relational operators
38+
//
39+
// Lexicographical.
40+
//
41+
// http://stackoverflow.com/questions/2819245/is-stdpairint-stdstring-ordering-well-defined
4742
{
4843
assert(std::make_pair(1, 1) == std::make_pair(1, 1));
49-
assert(std::make_pair(1, 2) < std::make_pair(2, 1));
50-
assert(std::make_pair(2, 1) > std::make_pair(1, 2));
44+
assert(std::make_pair(1, 2) < std::make_pair(2, 1));
45+
assert(std::make_pair(2, 1) > std::make_pair(1, 2));
5146
}
5247
}

0 commit comments

Comments
 (0)