Micah Weston commited on
Commit
d9aa261
·
1 Parent(s): bfcc7a2

Adds another task.

Browse files
Files changed (1) hide show
  1. data/genericify_cpp.jsonl +2 -1
data/genericify_cpp.jsonl CHANGED
@@ -7,4 +7,5 @@
7
  {"base_canonical_solution": "template <typename T>\nstd::vector<int> parse_nested_parens(T paren_string) {\n std::vector<int> all_levels;\n std::string current_paren;\n int level = 0, max_level = 0;\n for (int i = 0; i < paren_string.size(); i++) {\n char chr = paren_string[i];\n if (chr == '(') {\n level += 1;\n if (level > max_level) max_level = level;\n current_paren += chr;\n }\n if (chr == ')') {\n level -= 1;\n current_paren += chr;\n if (level == 0) {\n all_levels.push_back(max_level);\n current_paren = \"\";\n max_level = 0;\n }\n }\n }\n return all_levels;\n}", "base_prompt": "Make the following function generic for the parameter `paren_string`.", "concepts_canonical_solution": "template <typename T>\n requires requires(const T& s, std::size_t i) {\n { s[i] } -> std::convertible_to<char>;\n { s.size() } -> std::convertible_to<int>;\n std::same_as<typename T::value_type, char>;\n }\nstd::vector<int> parse_nested_parens(T paren_string) {\n std::vector<int> all_levels;\n std::string current_paren;\n int level = 0, max_level = 0;\n for (int i = 0; i < paren_string.size(); i++) {\n char chr = paren_string[i];\n if (chr == '(') {\n level += 1;\n if (level > max_level) max_level = level;\n current_paren += chr;\n }\n if (chr == ')') {\n level -= 1;\n current_paren += chr;\n if (level == 0) {\n all_levels.push_back(max_level);\n current_paren = \"\";\n max_level = 0;\n }\n }\n }\n return all_levels;\n}", "concepts_prompt": "Constrain the generic code using C++20 Concepts so that the parameter `paren_string` must be a sequenced container of characters like a string.", "invalids": "int main() { parse_nested_parens(float{3}); }", "sfinae_canonical_solution": "template <\n typename T,\n std::enable_if_t<\n std::conjunction_v<\n std::is_same<char, typename T::value_type>,\n std::is_same<char,\n std::decay_t<decltype(std::declval<T>()[std::declval<\n std::size_t>()])>>>,\n int> = 0>\nstd::vector<int> parse_nested_parens(T paren_string) {\n std::vector<int> all_levels;\n std::string current_paren;\n int level = 0, max_level = 0;\n for (int i = 0; i < paren_string.length(); i++) {\n char chr = paren_string[i];\n if (chr == '(') {\n level += 1;\n if (level > max_level) max_level = level;\n current_paren += chr;\n }\n if (chr == ')') {\n level -= 1;\n current_paren += chr;\n if (level == 0) {\n all_levels.push_back(max_level);\n current_paren = \"\";\n max_level = 0;\n }\n }\n }\n return all_levels;\n}", "sfinae_prompt": "Constrain the generic code using C++17 SFINAE so that the parameter `paren_string` must be a sequenced container of characters like a string.", "starter_code": "std::vector<int> parse_nested_parens(std::string paren_string) {\n std::vector<int> all_levels;\n std::string current_paren;\n int level = 0, max_level = 0;\n for (int i = 0; i < paren_string.size(); i++) {\n char chr = paren_string[i];\n if (chr == '(') {\n level += 1;\n if (level > max_level) max_level = level;\n current_paren += chr;\n }\n if (chr == ')') {\n level -= 1;\n current_paren += chr;\n if (level == 0) {\n all_levels.push_back(max_level);\n current_paren = \"\";\n max_level = 0;\n }\n }\n }\n return all_levels;\n}", "task_id": "HEP/6", "tests": "bool issame(std::vector<int> a, std::vector<int> b) {\n if (a.size() != b.size()) return false;\n for (int i = 0; i < a.size(); i++) {\n if (a[i] != b[i]) return false;\n }\n return true;\n}\n\n#define ASSERT(...) \\\n do { \\\n if (!(__VA_ARGS__)) { \\\n std::exit(-1); \\\n } \\\n } while (false)\n\n#define TEST_ON_TYPE(_type_) \\\n do { \\\n ASSERT(issame(parse_nested_parens(_type_{\"(()()) ((())) () ((())()())\"}), \\\n {2, 3, 1, 3})); \\\n ASSERT(issame(parse_nested_parens(_type_{\"() (()) ((())) (((())))\"}), \\\n {1, 2, 3, 4})); \\\n ASSERT(issame(parse_nested_parens(_type_{\"(()(())((())))\"}), {4})); \\\n } while (false)\n\nint main() {\n TEST_ON_TYPE(std::string);\n TEST_ON_TYPE(std::string_view);\n}"}
8
  {"base_canonical_solution": "template <typename T>\nT filter_by_substring(T strings, std::string substring) {\n T out;\n for (int i = 0; i < strings.size(); i++) {\n if (strings[i].find(substring) != strings[i].npos)\n out.push_back(strings[i]);\n }\n return out;\n}", "base_prompt": "Make the following function generic for the parameter `string` and return value.", "concepts_canonical_solution": "template <typename T>\n requires std::same_as<typename T::value_type, std::string>\nT filter_by_substring(T strings, std::string substring) {\n T out;\n for (int i = 0; i < strings.size(); i++) {\n if (strings[i].find(substring) != strings[i].npos)\n out.push_back(strings[i]);\n }\n return out;\n}", "concepts_prompt": "Constrain the generic code using C++20 Concepts so that it accepts a sequenced container with value type of string.", "invalids": "int main() { filter_by_substring(std::vector<int>{}, \"hello\"); }", "sfinae_canonical_solution": "template <typename T,\n std::enable_if_t<std::is_same_v<typename T::value_type, std::string>,\n int> = 0>\nT filter_by_substring(T strings, std::string substring) {\n T out;\n for (int i = 0; i < strings.size(); i++) {\n if (strings[i].find(substring) != strings[i].npos)\n out.push_back(strings[i]);\n }\n return out;\n}", "sfinae_prompt": "Constrain the generic code using C++17 SFINAE so that it accepts a sequenced container with value type of string.", "starter_code": "std::vector<string> filter_by_substring(std::vector<string> strings,\n std::string substring) {\n std::vector<string> out;\n for (int i = 0; i < strings.size(); i++) {\n if (strings[i].find(substring) != strings[i].npos)\n out.push_back(strings[i]);\n }\n return out;\n}", "task_id": "HEP/7", "tests": "template <typename T>\nbool issame(T a, T b) {\n if (a.size() != b.size()) return false;\n for (int i = 0; i < a.size(); i++) {\n if (a[i] != b[i]) return false;\n }\n return true;\n}\n\n#define ASSERT(...) \\\n do { \\\n if (!(__VA_ARGS__)) { \\\n std::exit(-1); \\\n } \\\n } while (false)\n\n#define TEST_ON_TYPE(_type_) \\\n do { \\\n ASSERT(issame(filter_by_substring(_type_{}, \"john\"), _type_{})); \\\n ASSERT(issame( \\\n filter_by_substring( \\\n _type_{\"xxx\", \"asd\", \"xxy\", \"john doe\", \"xxxAAA\", \"xxx\"}, \"xxx\"), \\\n _type_{\"xxx\", \"xxxAAA\", \"xxx\"})); \\\n ASSERT(issame(filter_by_substring(_type_{\"xxx\", \"asd\", \"aaaxxy\", \\\n \"john doe\", \"xxxAAA\", \"xxx\"}, \\\n \"xx\"), \\\n _type_{\"xxx\", \"aaaxxy\", \"xxxAAA\", \"xxx\"})); \\\n ASSERT(issame(filter_by_substring( \\\n _type_{\"grunt\", \"trumpet\", \"prune\", \"gruesome\"}, \"run\"), \\\n _type_{\"grunt\", \"prune\"})); \\\n } while (false)\n\nint main() {\n TEST_ON_TYPE(std::vector<std::string>);\n TEST_ON_TYPE(std::deque<std::string>);\n}\n"}
9
  {"base_canonical_solution": "template <typename T>\nstd::pair<T, T> sum_product(std::vector<T> numbers) {\n T sum = 0, product = 1;\n for (int i = 0; i < numbers.size(); i++) {\n sum += numbers[i];\n product *= numbers[i];\n }\n return {sum, product};\n}", "base_prompt": "Make the following function generic for the value types of the parameter and return pair.", "concepts_canonical_solution": "template <typename T>\n requires std::integral<T> || std::floating_point<T>\nstd::pair<T, T> sum_product(std::vector<T> numbers) {\n T sum = 0, product = 1;\n for (int i = 0; i < numbers.size(); i++) {\n sum += numbers[i];\n product *= numbers[i];\n }\n return {sum, product};\n}", "concepts_prompt": "Constrain the generic code using C++20 Concepts so that the generic parameter is a number type.", "invalids": "int main() { sum_product(std::vector<int*>{}); }", "sfinae_canonical_solution": "template <typename T,\n std::enable_if_t<std::disjunction_v<std::is_integral<T>,\n std::is_floating_point<T>>,\n int> = 0>\nstd::pair<T, T> sum_product(std::vector<T> numbers) {\n T sum = 0, product = 1;\n for (int i = 0; i < numbers.size(); i++) {\n sum += numbers[i];\n product *= numbers[i];\n }\n return {sum, product};\n}", "sfinae_prompt": "Constrain the generic code using C++17 SFINAE so that the generic parameter is a number type.", "starter_code": "std::pair<int, int> sum_product(std::vector<int> numbers) {\n int sum = 0, product = 1;\n for (int i = 0; i < numbers.size(); i++) {\n sum += numbers[i];\n product *= numbers[i];\n }\n return {sum, product};\n}", "task_id": "HEP/8", "tests": "#define ASSERT(...) \\\n do { \\\n if (!(__VA_ARGS__)) { \\\n std::exit(-1); \\\n } \\\n } while (false)\n\n#define TEST_ON_TYPE(_type_) \\\n do { \\\n ASSERT(sum_product(std::vector<_type_>{}) == \\\n std::pair<_type_, _type_>{0, 1}); \\\n ASSERT(sum_product(std::vector<_type_>{1, 1, 1}) == \\\n std::pair<_type_, _type_>{3, 1}); \\\n ASSERT(sum_product(std::vector<_type_>{100, 0}) == \\\n std::pair<_type_, _type_>{100, 0}); \\\n ASSERT(sum_product(std::vector<_type_>{3, 5, 7}) == \\\n std::pair<_type_, _type_>{3 + 5 + 7, 3 * 5 * 7}); \\\n ASSERT(sum_product(std::vector<_type_>{10}) == \\\n std::pair<_type_, _type_>{10, 10}); \\\n } while (false)\n\nint main() {\n TEST_ON_TYPE(float);\n TEST_ON_TYPE(int);\n TEST_ON_TYPE(long);\n}\n"}
10
- {"base_canonical_solution": "template <typename T>\nstd::vector<T> rolling_max(std::vector<T> numbers) {\n if (numbers.size() == 0) return {};\n std::vector<T> out;\n T max = numbers.front();\n for (int i = 0; i < numbers.size(); i++) {\n if (numbers[i] > max) max = numbers[i];\n out.push_back(max);\n }\n return out;\n}", "base_prompt": "Make the following function generic for value type of the parameter and return type.", "concepts_canonical_solution": "template <typename T>\n requires requires(const T& lhs, const T& rhs) {\n { lhs > rhs } -> std::convertible_to<bool>;\n }\nstd::vector<T> rolling_max(std::vector<T> numbers) {\n if (numbers.size() == 0) return {};\n std::vector<T> out;\n T max = numbers.front();\n for (int i = 0; i < numbers.size(); i++) {\n if (numbers[i] > max) max = numbers[i];\n out.push_back(max);\n }\n return out;\n}", "concepts_prompt": "Constrain the generic code using C++20 Concepts so that the generic parameter must be comparable to another of its type with greater than operator.", "invalids": "int main() {\n struct S {};\n rolling_max(std::vector<S>{});\n}", "sfinae_canonical_solution": "template <\n typename T,\n std::enable_if_t<std::is_convertible_v<decltype(std::declval<const T &>() >\n std::declval<const T &>()),\n bool>,\n int> = 0>\nstd::vector<T> rolling_max(std::vector<T> numbers) {\n if (numbers.size() == 0) return {};\n std::vector<T> out;\n T max = numbers.front();\n for (int i = 0; i < numbers.size(); i++) {\n if (numbers[i] > max) max = numbers[i];\n out.push_back(max);\n }\n return out;\n}", "sfinae_prompt": "Constrain the generic code using C++17 SFINAE so that the generic parameter must be comparable to another of its type with greater than operator.", "starter_code": "std::vector<int> rolling_max(std::vector<int> numbers) {\n if (numbers.size() == 0) return {};\n std::vector<int> out;\n int max = numbers.front();\n for (int i = 0; i < numbers.size(); i++) {\n if (numbers[i] > max) max = numbers[i];\n out.push_back(max);\n }\n return out;\n}", "task_id": "HEP/9", "tests": "\ntemplate <typename T>\nbool issame(std::vector<T> a, std::vector<T> b) {\n if (a.size() != b.size()) return false;\n for (int i = 0; i < a.size(); i++) {\n if (a[i] != b[i]) return false;\n }\n return true;\n}\n\n#define ASSERT(...) \\\n do { \\\n if (!(__VA_ARGS__)) { \\\n std::exit(-1); \\\n } \\\n } while (false)\n\n#define TEST_ON_TYPE(_type_) \\\n do { \\\n ASSERT(issame(rolling_max(std::vector<_type_>{}), std::vector<_type_>{})); \\\n ASSERT(issame(rolling_max(std::vector<_type_>{1, 2, 3, 4}), \\\n std::vector<_type_>{1, 2, 3, 4})); \\\n ASSERT(issame(rolling_max(std::vector<_type_>{4, 3, 2, 1}), \\\n std::vector<_type_>{4, 4, 4, 4})); \\\n ASSERT(issame(rolling_max(std::vector<_type_>{3, 2, 3, 100, 3}), \\\n std::vector<_type_>{3, 3, 3, 100, 100})); \\\n } while (false)\n\nint main() {\n TEST_ON_TYPE(int);\n TEST_ON_TYPE(float);\n\n ASSERT(issame(rolling_max(std::vector<std::string>{}),\n std::vector<std::string>{}));\n ASSERT(issame(rolling_max(std::vector<std::string>{\"1\", \"2\", \"3\", \"4\"}),\n std::vector<std::string>{\"1\", \"2\", \"3\", \"4\"}));\n ASSERT(issame(rolling_max(std::vector<std::string>{\"4\", \"3\", \"2\", \"1\"}),\n std::vector<std::string>{\"4\", \"4\", \"4\", \"4\"}));\n ASSERT(issame(rolling_max(std::vector<std::string>{\"3\", \"2\", \"3\", \"5\", \"3\"}),\n std::vector<std::string>{\"3\", \"3\", \"3\", \"5\", \"5\"}));\n}"}
 
 
7
  {"base_canonical_solution": "template <typename T>\nstd::vector<int> parse_nested_parens(T paren_string) {\n std::vector<int> all_levels;\n std::string current_paren;\n int level = 0, max_level = 0;\n for (int i = 0; i < paren_string.size(); i++) {\n char chr = paren_string[i];\n if (chr == '(') {\n level += 1;\n if (level > max_level) max_level = level;\n current_paren += chr;\n }\n if (chr == ')') {\n level -= 1;\n current_paren += chr;\n if (level == 0) {\n all_levels.push_back(max_level);\n current_paren = \"\";\n max_level = 0;\n }\n }\n }\n return all_levels;\n}", "base_prompt": "Make the following function generic for the parameter `paren_string`.", "concepts_canonical_solution": "template <typename T>\n requires requires(const T& s, std::size_t i) {\n { s[i] } -> std::convertible_to<char>;\n { s.size() } -> std::convertible_to<int>;\n std::same_as<typename T::value_type, char>;\n }\nstd::vector<int> parse_nested_parens(T paren_string) {\n std::vector<int> all_levels;\n std::string current_paren;\n int level = 0, max_level = 0;\n for (int i = 0; i < paren_string.size(); i++) {\n char chr = paren_string[i];\n if (chr == '(') {\n level += 1;\n if (level > max_level) max_level = level;\n current_paren += chr;\n }\n if (chr == ')') {\n level -= 1;\n current_paren += chr;\n if (level == 0) {\n all_levels.push_back(max_level);\n current_paren = \"\";\n max_level = 0;\n }\n }\n }\n return all_levels;\n}", "concepts_prompt": "Constrain the generic code using C++20 Concepts so that the parameter `paren_string` must be a sequenced container of characters like a string.", "invalids": "int main() { parse_nested_parens(float{3}); }", "sfinae_canonical_solution": "template <\n typename T,\n std::enable_if_t<\n std::conjunction_v<\n std::is_same<char, typename T::value_type>,\n std::is_same<char,\n std::decay_t<decltype(std::declval<T>()[std::declval<\n std::size_t>()])>>>,\n int> = 0>\nstd::vector<int> parse_nested_parens(T paren_string) {\n std::vector<int> all_levels;\n std::string current_paren;\n int level = 0, max_level = 0;\n for (int i = 0; i < paren_string.length(); i++) {\n char chr = paren_string[i];\n if (chr == '(') {\n level += 1;\n if (level > max_level) max_level = level;\n current_paren += chr;\n }\n if (chr == ')') {\n level -= 1;\n current_paren += chr;\n if (level == 0) {\n all_levels.push_back(max_level);\n current_paren = \"\";\n max_level = 0;\n }\n }\n }\n return all_levels;\n}", "sfinae_prompt": "Constrain the generic code using C++17 SFINAE so that the parameter `paren_string` must be a sequenced container of characters like a string.", "starter_code": "std::vector<int> parse_nested_parens(std::string paren_string) {\n std::vector<int> all_levels;\n std::string current_paren;\n int level = 0, max_level = 0;\n for (int i = 0; i < paren_string.size(); i++) {\n char chr = paren_string[i];\n if (chr == '(') {\n level += 1;\n if (level > max_level) max_level = level;\n current_paren += chr;\n }\n if (chr == ')') {\n level -= 1;\n current_paren += chr;\n if (level == 0) {\n all_levels.push_back(max_level);\n current_paren = \"\";\n max_level = 0;\n }\n }\n }\n return all_levels;\n}", "task_id": "HEP/6", "tests": "bool issame(std::vector<int> a, std::vector<int> b) {\n if (a.size() != b.size()) return false;\n for (int i = 0; i < a.size(); i++) {\n if (a[i] != b[i]) return false;\n }\n return true;\n}\n\n#define ASSERT(...) \\\n do { \\\n if (!(__VA_ARGS__)) { \\\n std::exit(-1); \\\n } \\\n } while (false)\n\n#define TEST_ON_TYPE(_type_) \\\n do { \\\n ASSERT(issame(parse_nested_parens(_type_{\"(()()) ((())) () ((())()())\"}), \\\n {2, 3, 1, 3})); \\\n ASSERT(issame(parse_nested_parens(_type_{\"() (()) ((())) (((())))\"}), \\\n {1, 2, 3, 4})); \\\n ASSERT(issame(parse_nested_parens(_type_{\"(()(())((())))\"}), {4})); \\\n } while (false)\n\nint main() {\n TEST_ON_TYPE(std::string);\n TEST_ON_TYPE(std::string_view);\n}"}
8
  {"base_canonical_solution": "template <typename T>\nT filter_by_substring(T strings, std::string substring) {\n T out;\n for (int i = 0; i < strings.size(); i++) {\n if (strings[i].find(substring) != strings[i].npos)\n out.push_back(strings[i]);\n }\n return out;\n}", "base_prompt": "Make the following function generic for the parameter `string` and return value.", "concepts_canonical_solution": "template <typename T>\n requires std::same_as<typename T::value_type, std::string>\nT filter_by_substring(T strings, std::string substring) {\n T out;\n for (int i = 0; i < strings.size(); i++) {\n if (strings[i].find(substring) != strings[i].npos)\n out.push_back(strings[i]);\n }\n return out;\n}", "concepts_prompt": "Constrain the generic code using C++20 Concepts so that it accepts a sequenced container with value type of string.", "invalids": "int main() { filter_by_substring(std::vector<int>{}, \"hello\"); }", "sfinae_canonical_solution": "template <typename T,\n std::enable_if_t<std::is_same_v<typename T::value_type, std::string>,\n int> = 0>\nT filter_by_substring(T strings, std::string substring) {\n T out;\n for (int i = 0; i < strings.size(); i++) {\n if (strings[i].find(substring) != strings[i].npos)\n out.push_back(strings[i]);\n }\n return out;\n}", "sfinae_prompt": "Constrain the generic code using C++17 SFINAE so that it accepts a sequenced container with value type of string.", "starter_code": "std::vector<string> filter_by_substring(std::vector<string> strings,\n std::string substring) {\n std::vector<string> out;\n for (int i = 0; i < strings.size(); i++) {\n if (strings[i].find(substring) != strings[i].npos)\n out.push_back(strings[i]);\n }\n return out;\n}", "task_id": "HEP/7", "tests": "template <typename T>\nbool issame(T a, T b) {\n if (a.size() != b.size()) return false;\n for (int i = 0; i < a.size(); i++) {\n if (a[i] != b[i]) return false;\n }\n return true;\n}\n\n#define ASSERT(...) \\\n do { \\\n if (!(__VA_ARGS__)) { \\\n std::exit(-1); \\\n } \\\n } while (false)\n\n#define TEST_ON_TYPE(_type_) \\\n do { \\\n ASSERT(issame(filter_by_substring(_type_{}, \"john\"), _type_{})); \\\n ASSERT(issame( \\\n filter_by_substring( \\\n _type_{\"xxx\", \"asd\", \"xxy\", \"john doe\", \"xxxAAA\", \"xxx\"}, \"xxx\"), \\\n _type_{\"xxx\", \"xxxAAA\", \"xxx\"})); \\\n ASSERT(issame(filter_by_substring(_type_{\"xxx\", \"asd\", \"aaaxxy\", \\\n \"john doe\", \"xxxAAA\", \"xxx\"}, \\\n \"xx\"), \\\n _type_{\"xxx\", \"aaaxxy\", \"xxxAAA\", \"xxx\"})); \\\n ASSERT(issame(filter_by_substring( \\\n _type_{\"grunt\", \"trumpet\", \"prune\", \"gruesome\"}, \"run\"), \\\n _type_{\"grunt\", \"prune\"})); \\\n } while (false)\n\nint main() {\n TEST_ON_TYPE(std::vector<std::string>);\n TEST_ON_TYPE(std::deque<std::string>);\n}\n"}
9
  {"base_canonical_solution": "template <typename T>\nstd::pair<T, T> sum_product(std::vector<T> numbers) {\n T sum = 0, product = 1;\n for (int i = 0; i < numbers.size(); i++) {\n sum += numbers[i];\n product *= numbers[i];\n }\n return {sum, product};\n}", "base_prompt": "Make the following function generic for the value types of the parameter and return pair.", "concepts_canonical_solution": "template <typename T>\n requires std::integral<T> || std::floating_point<T>\nstd::pair<T, T> sum_product(std::vector<T> numbers) {\n T sum = 0, product = 1;\n for (int i = 0; i < numbers.size(); i++) {\n sum += numbers[i];\n product *= numbers[i];\n }\n return {sum, product};\n}", "concepts_prompt": "Constrain the generic code using C++20 Concepts so that the generic parameter is a number type.", "invalids": "int main() { sum_product(std::vector<int*>{}); }", "sfinae_canonical_solution": "template <typename T,\n std::enable_if_t<std::disjunction_v<std::is_integral<T>,\n std::is_floating_point<T>>,\n int> = 0>\nstd::pair<T, T> sum_product(std::vector<T> numbers) {\n T sum = 0, product = 1;\n for (int i = 0; i < numbers.size(); i++) {\n sum += numbers[i];\n product *= numbers[i];\n }\n return {sum, product};\n}", "sfinae_prompt": "Constrain the generic code using C++17 SFINAE so that the generic parameter is a number type.", "starter_code": "std::pair<int, int> sum_product(std::vector<int> numbers) {\n int sum = 0, product = 1;\n for (int i = 0; i < numbers.size(); i++) {\n sum += numbers[i];\n product *= numbers[i];\n }\n return {sum, product};\n}", "task_id": "HEP/8", "tests": "#define ASSERT(...) \\\n do { \\\n if (!(__VA_ARGS__)) { \\\n std::exit(-1); \\\n } \\\n } while (false)\n\n#define TEST_ON_TYPE(_type_) \\\n do { \\\n ASSERT(sum_product(std::vector<_type_>{}) == \\\n std::pair<_type_, _type_>{0, 1}); \\\n ASSERT(sum_product(std::vector<_type_>{1, 1, 1}) == \\\n std::pair<_type_, _type_>{3, 1}); \\\n ASSERT(sum_product(std::vector<_type_>{100, 0}) == \\\n std::pair<_type_, _type_>{100, 0}); \\\n ASSERT(sum_product(std::vector<_type_>{3, 5, 7}) == \\\n std::pair<_type_, _type_>{3 + 5 + 7, 3 * 5 * 7}); \\\n ASSERT(sum_product(std::vector<_type_>{10}) == \\\n std::pair<_type_, _type_>{10, 10}); \\\n } while (false)\n\nint main() {\n TEST_ON_TYPE(float);\n TEST_ON_TYPE(int);\n TEST_ON_TYPE(long);\n}\n"}
10
+ {"base_canonical_solution": "template <typename T>\nstd::vector<T> rolling_max(std::vector<T> numbers) {\n if (numbers.size() == 0) return {};\n std::vector<T> out;\n T max = numbers.front();\n for (int i = 0; i < numbers.size(); i++) {\n if (numbers[i] > max) max = numbers[i];\n out.push_back(max);\n }\n return out;\n}", "base_prompt": "Make the following function generic for value type of the parameter and return type.", "concepts_canonical_solution": "template <typename T>\n requires requires(const T& lhs, const T& rhs) {\n { lhs > rhs } -> std::convertible_to<bool>;\n }\nstd::vector<T> rolling_max(std::vector<T> numbers) {\n if (numbers.size() == 0) return {};\n std::vector<T> out;\n T max = numbers.front();\n for (int i = 0; i < numbers.size(); i++) {\n if (numbers[i] > max) max = numbers[i];\n out.push_back(max);\n }\n return out;\n}", "concepts_prompt": "Constrain the generic code using C++20 Concepts so that the generic parameter must be comparable to another of its type with greater than operator.", "invalids": "int main() {\n struct S {};\n rolling_max(std::vector<S>{});\n}", "sfinae_canonical_solution": "template <\n typename T,\n std::enable_if_t<std::is_convertible_v<decltype(std::declval<const T &>() >\n std::declval<const T &>()),\n bool>,\n int> = 0>\nstd::vector<T> rolling_max(std::vector<T> numbers) {\n if (numbers.size() == 0) return {};\n std::vector<T> out;\n T max = numbers.front();\n for (int i = 0; i < numbers.size(); i++) {\n if (numbers[i] > max) max = numbers[i];\n out.push_back(max);\n }\n return out;\n}", "sfinae_prompt": "Constrain the generic code using C++17 SFINAE so that the generic parameter must be comparable to another of its type with greater than operator.", "starter_code": "std::vector<int> rolling_max(std::vector<int> numbers) {\n if (numbers.size() == 0) return {};\n std::vector<int> out;\n int max = numbers.front();\n for (int i = 0; i < numbers.size(); i++) {\n if (numbers[i] > max) max = numbers[i];\n out.push_back(max);\n }\n return out;\n}", "task_id": "HEP/9", "tests": "\ntemplate <typename T>\nbool issame(std::vector<T> a, std::vector<T> b) {\n if (a.size() != b.size()) return false;\n for (int i = 0; i < a.size(); i++) {\n if (a[i] != b[i]) return false;\n }\n return true;\n}\n\n#define ASSERT(...) \\\n do { \\\n if (!(__VA_ARGS__)) { \\\n std::exit(-1); \\\n } \\\n } while (false)\n\n#define TEST_ON_TYPE(_type_) \\\n do { \\\n ASSERT(issame(rolling_max(std::vector<_type_>{}), std::vector<_type_>{})); \\\n ASSERT(issame(rolling_max(std::vector<_type_>{1, 2, 3, 4}), \\\n std::vector<_type_>{1, 2, 3, 4})); \\\n ASSERT(issame(rolling_max(std::vector<_type_>{4, 3, 2, 1}), \\\n std::vector<_type_>{4, 4, 4, 4})); \\\n ASSERT(issame(rolling_max(std::vector<_type_>{3, 2, 3, 100, 3}), \\\n std::vector<_type_>{3, 3, 3, 100, 100})); \\\n } while (false)\n\nint main() {\n TEST_ON_TYPE(int);\n TEST_ON_TYPE(float);\n\n ASSERT(issame(rolling_max(std::vector<std::string>{}),\n std::vector<std::string>{}));\n ASSERT(issame(rolling_max(std::vector<std::string>{\"1\", \"2\", \"3\", \"4\"}),\n std::vector<std::string>{\"1\", \"2\", \"3\", \"4\"}));\n ASSERT(issame(rolling_max(std::vector<std::string>{\"4\", \"3\", \"2\", \"1\"}),\n std::vector<std::string>{\"4\", \"4\", \"4\", \"4\"}));\n ASSERT(issame(rolling_max(std::vector<std::string>{\"3\", \"2\", \"3\", \"5\", \"3\"}),\n std::vector<std::string>{\"3\", \"3\", \"3\", \"5\", \"5\"}));\n}"}
11
+ {"base_canonical_solution": "template <typename T>\nstd::string string_xor(T a, T b) {\n std::string output = \"\";\n for (int i = 0; (i < a.size() && i < b.size()); i++) {\n if (i < a.size() && i < b.size()) {\n if (a[i] == b[i]) {\n output += '0';\n } else\n output += '1';\n } else {\n if (i >= a.size()) {\n output += b[i];\n } else\n output += a[i];\n }\n }\n return output;\n}", "base_prompt": "Make the following function generic for the type of the two parameters.", "concepts_canonical_solution": "template <typename T>\n requires std::same_as<T::value_type, char>\nstd::string string_xor(T a, T b) {\n std::string output = \"\";\n for (int i = 0; (i < a.size() && i < b.size()); i++) {\n if (i < a.size() && i < b.size()) {\n if (a[i] == b[i]) {\n output += '0';\n } else\n output += '1';\n } else {\n if (i >= a.size()) {\n output += b[i];\n } else\n output += a[i];\n }\n }\n return output;\n}", "concepts_prompt": "Constrain the generic code using C++20 Concepts so that the generic parameter is a sequenced container of characters.", "invalids": "int main() { string_xor(std::vector<int>{}, std::vector<int>{}); }", "sfinae_canonical_solution": "template <typename T,\n std::enable_if_t<std::is_same_v<T::value_type, char>, int> = 0>\nstd::string string_xor(T a, T b) {\n std::string output = \"\";\n for (int i = 0; (i < a.size() && i < b.size()); i++) {\n if (i < a.size() && i < b.size()) {\n if (a[i] == b[i]) {\n output += '0';\n } else\n output += '1';\n } else {\n if (i >= a.size()) {\n output += b[i];\n } else\n output += a[i];\n }\n }\n return output;\n}", "sfinae_prompt": "Constrain the generic code using C++17 SFINAE so that the generic parameter is a sequenced container of characters.", "starter_code": "std::string string_xor(std::string a, std::string b) {\n std::string output = \"\";\n for (int i = 0; (i < a.size() && i < b.size()); i++) {\n if (i < a.size() && i < b.size()) {\n if (a[i] == b[i]) {\n output += '0';\n } else\n output += '1';\n } else {\n if (i >= a.size()) {\n output += b[i];\n } else\n output += a[i];\n }\n }\n return output;\n}", "task_id": "HEP/11", "tests": "#define ASSERT(...) \\\n do { \\\n if (!(__VA_ARGS__)) { \\\n std::exit(-1); \\\n } \\\n } while (false)\n\nint main() {\n ASSERT(string_xor(\"111000\", \"101010\") == \"010010\");\n ASSERT(string_xor(\"1\", \"1\") == \"0\");\n ASSERT(string_xor(\"0101\", \"0000\") == \"0101\");\n\n ASSERT(string_xor(std::vector<char>{'1', '1', '1', '0', '0', '0'},\n std::vector<char>{'1', '0', '1', '0', '1', '0'}) ==\n \"010010\");\n ASSERT(string_xor(std::vector<char>{'1'}, std::vector<char>{'1'}) == \"0\");\n ASSERT(string_xor(std::vector<char>{'0', '1', '0', '1'},\n std::vector<char>{'0', '0', '0', '0'}) == \"0101\");\n}\n"}