Skip to content

Commit 2b46374

Browse files
committed
update cpp
1 parent cbc12fb commit 2b46374

File tree

14 files changed

+683
-608
lines changed

14 files changed

+683
-608
lines changed

Bar/CMakeLists.txt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
add_library(Bar "")
2-
1+
add_library(Bar)
32
target_sources(Bar
43
PRIVATE
54
include/bar/Bar.hpp
@@ -8,11 +7,17 @@ target_include_directories(Bar
87
PUBLIC
98
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
109
$<INSTALL_INTERFACE:include>)
11-
target_compile_features(Bar PUBLIC cxx_std_17)
10+
target_compile_features(Bar PUBLIC cxx_std_20)
1211
set_target_properties(Bar PROPERTIES
1312
VERSION ${PROJECT_VERSION}
13+
POSITION_INDEPENDENT_CODE ON
1414
PUBLIC_HEADER include/bar/Bar.hpp)
15-
#target_link_libraries(Bar PUBLIC ...)
15+
if(APPLE)
16+
set_target_properties(Bar PROPERTIES INSTALL_RPATH "@loader_path")
17+
elseif(UNIX)
18+
set_target_properties(Bar PROPERTIES INSTALL_RPATH "$ORIGIN")
19+
endif()
20+
target_link_libraries(Bar PRIVATE absl::log)
1621
add_library(${PROJECT_NAMESPACE}::Bar ALIAS Bar)
1722

1823
add_subdirectory(tests)

Bar/src/Bar.cpp

Lines changed: 74 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -4,167 +4,169 @@
44
#include <string>
55
#include <utility>
66

7+
#include "absl/log/log.h"
8+
79
namespace bar {
810
std::vector<std::string> stringVectorOutput(int level) {
9-
std::cout << "[" << level << "] Enter " << __func__ << "()" << std::endl;
11+
LOG(INFO) << "[" << level << "] Enter " << __func__ << "()" << std::endl;
1012
std::vector<std::string> result(level, std::to_string(level));
11-
std::cout << "[" << level << "] Exit " << __func__ << "()" << std::endl;
13+
LOG(INFO) << "[" << level << "] Exit " << __func__ << "()" << std::endl;
1214
return result;
1315
}
1416

1517
int stringVectorInput(std::vector<std::string> data) {
16-
std::cout << "Enter " << __func__ << "()" << std::endl;
17-
std::cout << "{";
18+
LOG(INFO) << "Enter " << __func__ << "()" << std::endl;
19+
LOG(INFO) << "{";
1820
for (const auto& item : data) {
19-
std::cout << item << ", ";
21+
LOG(INFO) << item << ", ";
2022
}
21-
std::cout << "}" << std::endl;
22-
std::cout << "Exit " << __func__ << "()" << std::endl;
23+
LOG(INFO) << "}" << std::endl;
24+
LOG(INFO) << "Exit " << __func__ << "()" << std::endl;
2325
return data.size();
2426
}
2527

2628
int stringVectorRefInput(const std::vector<std::string>& data) {
27-
std::cout << "Enter " << __func__ << "()" << std::endl;
28-
std::cout << "{";
29+
LOG(INFO) << "Enter " << __func__ << "()" << std::endl;
30+
LOG(INFO) << "{";
2931
for (const auto& item : data) {
30-
std::cout << item << ", ";
32+
LOG(INFO) << item << ", ";
3133
}
32-
std::cout << "}" << std::endl;
33-
std::cout << "Exit " << __func__ << "()" << std::endl;
34+
LOG(INFO) << "}" << std::endl;
35+
LOG(INFO) << "Exit " << __func__ << "()" << std::endl;
3436
return data.size();
3537
}
3638

3739
std::vector<std::vector<std::string>> stringJaggedArrayOutput(int level) {
38-
std::cout << "[" << level << "] Enter " << __func__ << "()" << std::endl;
40+
LOG(INFO) << "[" << level << "] Enter " << __func__ << "()" << std::endl;
3941
std::vector<std::vector<std::string>> result;
4042
result.reserve(level);
4143
for (int i = 1; i <= level; ++i) {
4244
result.emplace_back(std::vector<std::string>(i, std::to_string(i)));
4345
}
44-
std::cout << "[" << level << "] Exit " << __func__ << "()" << std::endl;
46+
LOG(INFO) << "[" << level << "] Exit " << __func__ << "()" << std::endl;
4547
return result;
4648
}
4749

4850
int stringJaggedArrayInput(std::vector<std::vector<std::string>> data) {
49-
std::cout << "Enter " << __func__ << "()" << std::endl;
50-
std::cout << "{";
51+
LOG(INFO) << "Enter " << __func__ << "()" << std::endl;
52+
LOG(INFO) << "{";
5153
for (const auto& inner : data) {
52-
std::cout << "{";
54+
LOG(INFO) << "{";
5355
for (const auto& item : inner) {
54-
std::cout << item << ", ";
56+
LOG(INFO) << item << ", ";
5557
}
56-
std::cout << "}, ";
58+
LOG(INFO) << "}, ";
5759
}
58-
std::cout << "}" << std::endl;
59-
std::cout << "Exit " << __func__ << "()" << std::endl;
60+
LOG(INFO) << "}" << std::endl;
61+
LOG(INFO) << "Exit " << __func__ << "()" << std::endl;
6062
return data.size();
6163
}
6264

6365
int stringJaggedArrayRefInput(const std::vector<std::vector<std::string>>& data) {
64-
std::cout << "Enter " << __func__ << "()" << std::endl;
65-
std::cout << "{";
66+
LOG(INFO) << "Enter " << __func__ << "()" << std::endl;
67+
LOG(INFO) << "{";
6668
for (const auto& inner : data) {
67-
std::cout << "{";
69+
LOG(INFO) << "{";
6870
for (const auto& item : inner) {
69-
std::cout << item << ", ";
71+
LOG(INFO) << item << ", ";
7072
}
71-
std::cout << "}, ";
73+
LOG(INFO) << "}, ";
7274
}
73-
std::cout << "}" << std::endl;
74-
std::cout << "Exit " << __func__ << "()" << std::endl;
75+
LOG(INFO) << "}" << std::endl;
76+
LOG(INFO) << "Exit " << __func__ << "()" << std::endl;
7577
return data.size();
7678
}
7779

7880
std::vector<std::pair<int, int>> pairVectorOutput(int level) {
79-
std::cout << "[" << level << "] Enter " << __func__ << "()" << std::endl;
81+
LOG(INFO) << "[" << level << "] Enter " << __func__ << "()" << std::endl;
8082
std::vector<std::pair<int, int>> result(level, std::make_pair(level, level));
81-
std::cout << "[" << level << "] Exit " << __func__ << "()" << std::endl;
83+
LOG(INFO) << "[" << level << "] Exit " << __func__ << "()" << std::endl;
8284
return result;
8385
}
8486

8587
int pairVectorInput(std::vector<std::pair<int, int>> data) {
86-
std::cout << "Enter " << __func__ << "()" << std::endl;
87-
std::cout << "{";
88+
LOG(INFO) << "Enter " << __func__ << "()" << std::endl;
89+
LOG(INFO) << "{";
8890
for (const auto& item : data) {
89-
std::cout << "[" << item.first << "," << item.second << "], ";
91+
LOG(INFO) << "[" << item.first << "," << item.second << "], ";
9092
}
91-
std::cout << "}" << std::endl;
92-
std::cout << "Exit " << __func__ << "()" << std::endl;
93+
LOG(INFO) << "}" << std::endl;
94+
LOG(INFO) << "Exit " << __func__ << "()" << std::endl;
9395
return data.size();
9496
}
9597

9698
int pairVectorRefInput(const std::vector<std::pair<int, int>>& data) {
97-
std::cout << "Enter " << __func__ << "()" << std::endl;
98-
std::cout << "{";
99+
LOG(INFO) << "Enter " << __func__ << "()" << std::endl;
100+
LOG(INFO) << "{";
99101
for (const auto& item : data) {
100-
std::cout << "[" << item.first << "," << item.second << "], ";
102+
LOG(INFO) << "[" << item.first << "," << item.second << "], ";
101103
}
102-
std::cout << "}" << std::endl;
103-
std::cout << "Exit " << __func__ << "()" << std::endl;
104+
LOG(INFO) << "}" << std::endl;
105+
LOG(INFO) << "Exit " << __func__ << "()" << std::endl;
104106
return data.size();
105107
}
106108

107109
std::vector<std::vector<std::pair<int, int>>> pairJaggedArrayOutput(int level) {
108-
std::cout << "[" << level << "] Enter " << __func__ << "()" << std::endl;
110+
LOG(INFO) << "[" << level << "] Enter " << __func__ << "()" << std::endl;
109111
std::vector<std::vector<std::pair<int, int>>> result;
110112
result.reserve(level);
111113
for (int i = 1; i <= level; ++i) {
112114
result.emplace_back(std::vector<std::pair<int, int>>(i, std::make_pair(i, i)));
113115
}
114-
std::cout << "[" << level << "] Exit " << __func__ << "()" << std::endl;
116+
LOG(INFO) << "[" << level << "] Exit " << __func__ << "()" << std::endl;
115117
return result;
116118
}
117119

118120
int pairJaggedArrayInput(std::vector<std::vector<std::pair<int, int>>> data) {
119-
std::cout << "Enter " << __func__ << "()" << std::endl;
120-
std::cout << "{";
121+
LOG(INFO) << "Enter " << __func__ << "()" << std::endl;
122+
LOG(INFO) << "{";
121123
for (const auto& inner : data) {
122-
std::cout << "{";
124+
LOG(INFO) << "{";
123125
for (const auto& item : inner) {
124-
std::cout << "[" << item.first << "," << item.second << "], ";
126+
LOG(INFO) << "[" << item.first << "," << item.second << "], ";
125127
}
126-
std::cout << "}, ";
128+
LOG(INFO) << "}, ";
127129
}
128-
std::cout << "}" << std::endl;
129-
std::cout << "Exit " << __func__ << "()" << std::endl;
130+
LOG(INFO) << "}" << std::endl;
131+
LOG(INFO) << "Exit " << __func__ << "()" << std::endl;
130132
return data.size();
131133
}
132134

133135
int pairJaggedArrayRefInput(const std::vector<std::vector<std::pair<int, int>>>& data) {
134-
std::cout << "Enter " << __func__ << "()" << std::endl;
135-
std::cout << "{";
136+
LOG(INFO) << "Enter " << __func__ << "()" << std::endl;
137+
LOG(INFO) << "{";
136138
for (const auto& inner : data) {
137-
std::cout << "{";
139+
LOG(INFO) << "{";
138140
for (const auto& item : inner) {
139-
std::cout << "[" << item.first << "," << item.second << "], ";
141+
LOG(INFO) << "[" << item.first << "," << item.second << "], ";
140142
}
141-
std::cout << "}, ";
143+
LOG(INFO) << "}, ";
142144
}
143-
std::cout << "}" << std::endl;
144-
std::cout << "Exit " << __func__ << "()" << std::endl;
145+
LOG(INFO) << "}" << std::endl;
146+
LOG(INFO) << "Exit " << __func__ << "()" << std::endl;
145147
return data.size();
146148
}
147149

148150
void freeFunction(int level) {
149-
std::cout << "[" << level << "] Enter " << __func__ << "(int)" << std::endl;
150-
std::cout << "[" << level << "] Exit " << __func__ << "(int)" << std::endl;
151+
LOG(INFO) << "[" << level << "] Enter " << __func__ << "(int)" << std::endl;
152+
LOG(INFO) << "[" << level << "] Exit " << __func__ << "(int)" << std::endl;
151153
}
152154

153155
void freeFunction(int64_t level) {
154-
std::cout << "[" << level << "] Enter " << __func__ << "(int64_t)" << std::endl;
155-
std::cout << "[" << level << "] Exit " << __func__ << "(int64_t)" << std::endl;
156+
LOG(INFO) << "[" << level << "] Enter " << __func__ << "(int64_t)" << std::endl;
157+
LOG(INFO) << "[" << level << "] Exit " << __func__ << "(int64_t)" << std::endl;
156158
}
157159

158160
void Bar::staticFunction(int level) {
159-
std::cout << "[" << level << "] Enter " << __func__ << "(int)" << std::endl;
161+
LOG(INFO) << "[" << level << "] Enter " << __func__ << "(int)" << std::endl;
160162
freeFunction(level + 1);
161-
std::cout << "[" << level << "] Exit " << __func__ << "(int)" << std::endl;
163+
LOG(INFO) << "[" << level << "] Exit " << __func__ << "(int)" << std::endl;
162164
}
163165

164166
void Bar::staticFunction(int64_t level) {
165-
std::cout << "[" << level << "] Enter " << __func__ << "(int64_t)" << std::endl;
167+
LOG(INFO) << "[" << level << "] Enter " << __func__ << "(int64_t)" << std::endl;
166168
freeFunction(level + 1);
167-
std::cout << "[" << level << "] Exit " << __func__ << "(int64_t)" << std::endl;
169+
LOG(INFO) << "[" << level << "] Exit " << __func__ << "(int64_t)" << std::endl;
168170
}
169171

170172
int Bar::getInt() const {
@@ -187,4 +189,12 @@ std::string Bar::operator()() const {
187189
return std::string{"\"Bar\":{\"int\":"} + std::to_string(_intValue) +
188190
",\"int64\":" + std::to_string(_int64Value) + "}";
189191
}
192+
193+
namespace {
194+
void* kVar = [] {
195+
std::cerr << "kBar" << std::endl;
196+
return nullptr;
197+
}();
198+
} // namespace
199+
190200
} // namespace bar

Bar/tests/CMakeLists.txt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@ if(NOT BUILD_TESTING)
33
endif()
44

55
file(GLOB CPP_SRCS "*.cpp")
6-
foreach(TEST IN LISTS CPP_SRCS)
7-
add_cpp_test(${TEST})
6+
foreach(_TEST_FILE IN LISTS CPP_SRCS)
7+
get_filename_component(_NAME ${_TEST_FILE} NAME_WE)
8+
get_filename_component(_FILE_NAME ${_TEST_FILE} NAME)
9+
add_cxx_test(
10+
NAME
11+
${_NAME}
12+
SOURCES
13+
${_FILE_NAME}
14+
LINK_LIBRARIES
15+
${PROJECT_NAMESPACE}::Bar
16+
)
817
endforeach()

0 commit comments

Comments
 (0)