66
77
88template <typename T>
9+ /* *
10+ * Adds two numbers of the same type together.
11+ *
12+ * @param a The first number to add.
13+ * @param b The second number to add.
14+ * @return The sum of the two numbers.
15+ */
916T a_plus_b (T a, T b) {
1017 return a + b;
1118}
1219
1320
21+ /* *
22+ * Executes a SQL query on the given SQLite database and retrieves the results.
23+ *
24+ * @param db A pointer to the SQLite database connection.
25+ * @param query The SQL query string to be executed.
26+ * @return A vector of vectors of strings, where each inner vector represents a row of
27+ * query results, and each string within the inner vector represents a column in that row.
28+ * If an error occurs while preparing the query, an empty vector is returned.
29+ */
1430std::vector<std::vector<std::string>> sqlite (sqlite3* db, const std::string& query) {
1531 std::vector<std::vector<std::string>> results;
1632 sqlite3_stmt* stmt;
@@ -38,6 +54,15 @@ std::vector<std::vector<std::string>> sqlite(sqlite3* db, const std::string& que
3854
3955
4056template <typename T, typename F>
57+ /* *
58+ * Compares two items based on a key mapping function and returns an integer indicating their relative order.
59+ *
60+ * @param key_map A function object or lambda that accepts an item of type T and returns a comparable value.
61+ * @param item1 The first item to compare using the key mapping function.
62+ * @param item2 The second item to compare using the key mapping function.
63+ * @return An integer: -1 if item1 is less than item2, 1 if item1 is greater than item2, 0 if they are equal.
64+ */
65+
4166int compare (F key_map, const T& item1, const T& item2) {
4267 auto val1 = key_map (item1);
4368 auto val2 = key_map (item2);
@@ -48,6 +73,12 @@ int compare(F key_map, const T& item1, const T& item2) {
4873}
4974
5075
76+ /* *
77+ * Generates a random string composed of alphabetic characters (both uppercase and lowercase).
78+ *
79+ * @param length The desired length of the generated random string.
80+ * @return A random string of the specified length containing only alphabetic characters.
81+ */
5182std::string random_alphabets (int length) {
5283 static const std::string chars =
5384 " abcdefghijklmnopqrstuvwxyz"
0 commit comments