6
6
7
7
8
8
template <typename T>
9
+ /* *
10
+ * Computes the sum of two values of the same type.
11
+ *
12
+ * @param a The first addend of type T.
13
+ * @param b The second addend of type T.
14
+ * @return The sum of a and b, which will be of the same type T.
15
+ */
9
16
T a_plus_b (T a, T b) {
10
17
return a + b;
11
18
}
12
19
13
20
21
+ /* *
22
+ * Executes an SQL query on a provided SQLite database and returns the result as a vector of string vectors.
23
+ *
24
+ * @param db Pointer to the SQLite database object to execute the query on.
25
+ * @param query SQL query string to be executed.
26
+ * @return A vector of vectors of strings, where each inner vector represents a row from the query result.
27
+ * If the query execution fails, an empty vector is returned.
28
+ */
14
29
std::vector<std::vector<std::string>> sqlite (sqlite3* db, const std::string& query) {
15
30
std::vector<std::vector<std::string>> results;
16
31
sqlite3_stmt* stmt;
@@ -38,6 +53,17 @@ std::vector<std::vector<std::string>> sqlite(sqlite3* db, const std::string& que
38
53
39
54
40
55
template <typename T, typename F>
56
+ /* *
57
+ * Compares two items using a key mapping function and returns an integer
58
+ * indicating their order based on the key values.
59
+ *
60
+ * @param key_map A function object that extracts the key from each item to be compared.
61
+ * @param item1 The first item to compare.
62
+ * @param item2 The second item to compare.
63
+ * @return -1 if the key of item1 is less than the key of item2,
64
+ * 1 if the key of item1 is greater than the key of item2,
65
+ * 0 if the keys are equal.
66
+ */
41
67
int compare (F key_map, const T& item1, const T& item2) {
42
68
auto val1 = key_map (item1);
43
69
auto val2 = key_map (item2);
@@ -48,6 +74,13 @@ int compare(F key_map, const T& item1, const T& item2) {
48
74
}
49
75
50
76
77
+ /* *
78
+ * Generates a random string of alphabets with the specified length.
79
+ * The string contains a mix of uppercase and lowercase English letters.
80
+ *
81
+ * @param length The length of the random alphabet string to generate.
82
+ * @return A randomly generated string of alphabets of the specified length.
83
+ */
51
84
std::string random_alphabets (int length) {
52
85
static const std::string chars =
53
86
" abcdefghijklmnopqrstuvwxyz"
0 commit comments