66
77
88template <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+ */
916T a_plus_b (T a, T b) {
1017 return a + b;
1118}
1219
1320
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+ */
1429std::vector<std::vector<std::string>> sqlite (sqlite3* db, const std::string& query) {
1530 std::vector<std::vector<std::string>> results;
1631 sqlite3_stmt* stmt;
@@ -38,6 +53,17 @@ std::vector<std::vector<std::string>> sqlite(sqlite3* db, const std::string& que
3853
3954
4055template <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+ */
4167int compare (F key_map, const T& item1, const T& item2) {
4268 auto val1 = key_map (item1);
4369 auto val2 = key_map (item2);
@@ -48,6 +74,13 @@ int compare(F key_map, const T& item1, const T& item2) {
4874}
4975
5076
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+ */
5184std::string random_alphabets (int length) {
5285 static const std::string chars =
5386 " abcdefghijklmnopqrstuvwxyz"
0 commit comments