6
6
7
7
8
8
template <typename T>
9
+ /* *
10
+ * Adds two values of the same type.
11
+ *
12
+ * @param a The first value to be added.
13
+ * @param b The second value to be added.
14
+ * @return The result of adding a and b.
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 a SQL query on the given SQLite database and returns the results.
23
+ *
24
+ * @param db A pointer to the SQLite database object.
25
+ * @param query A string containing the SQL query to be executed.
26
+ * @return A vector of vectors of strings where each sub-vector represents a row from the query result,
27
+ * with each string in the sub-vector corresponding to a column value. Returns an empty vector
28
+ * if the query fails to prepare.
29
+ */
30
+
14
31
std::vector<std::vector<std::string>> sqlite (sqlite3* db, const std::string& query) {
15
32
std::vector<std::vector<std::string>> results;
16
33
sqlite3_stmt* stmt;
@@ -38,6 +55,15 @@ std::vector<std::vector<std::string>> sqlite(sqlite3* db, const std::string& que
38
55
39
56
40
57
template <typename T, typename F>
58
+ /* *
59
+ * Compares two items based on a key mapping function and returns an integer indicating their order.
60
+ *
61
+ * @param key_map A function that extracts a comparison key from an item.
62
+ * @param item1 The first item to be compared.
63
+ * @param item2 The second item to be compared.
64
+ * @return -1 if the first item is less than the second, 1 if the first item is greater than the second,
65
+ * and 0 if they are equal based on the mapping function.
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,12 @@ int compare(F key_map, const T& item1, const T& item2) {
48
74
}
49
75
50
76
77
+ /* *
78
+ * Generates a random string composed of lowercase and uppercase alphabets.
79
+ *
80
+ * @param length The length of the random string to be generated.
81
+ * @return A random string containing only alphabetic characters with the specified length.
82
+ */
51
83
std::string random_alphabets (int length) {
52
84
static const std::string chars =
53
85
" abcdefghijklmnopqrstuvwxyz"
0 commit comments