Micah Weston
commited on
Commit
·
5b49644
1
Parent(s):
1d6c540
Fix error.
Browse files
data/genericify_cpp.jsonl
CHANGED
|
@@ -12,4 +12,4 @@
|
|
| 12 |
{"base_canonical_solution": "template <typename T>\nstd::string longest(T strings) {\n std::string out;\n for (int i = 0; i < strings.size(); i++) {\n if (strings[i].length() > out.length()) out = strings[i];\n }\n return out;\n}", "base_prompt": "Make the following function generic for the container parameter `strings`.", "concepts_canonical_solution": "template <typename T>\n requires std::same_as<typename T::value_type, std::string>\nstd::string longest(T strings) {\n std::string out;\n for (int i = 0; i < strings.size(); i++) {\n if (strings[i].length() > out.length()) out = strings[i];\n }\n return out;\n}", "concepts_prompt": "Constrain the generic code using C++20 Concepts so that the generic parameter is a sequenced container of value type string.", "invalids": "int main() { longest(std::vector<int>{}) }", "sfinae_canonical_solution": "template <typename T,\n std::enable_if_t<std::is_same_v<typename T::value_type, std::string>,\n int> = 0>\nstd::string longest(T strings) {\n std::string out;\n for (int i = 0; i < strings.size(); i++) {\n if (strings[i].length() > out.length()) out = strings[i];\n }\n return out;\n}", "sfinae_prompt": "Constrain the generic code using C++17 SFINAE so that the generic parameter is a sequenced container of value type string.", "starter_code": "std::string longest(std::vector<std::string> strings) {\n std::string out;\n for (int i = 0; i < strings.size(); i++) {\n if (strings[i].length() > out.length()) out = strings[i];\n }\n return out;\n}", "task_id": "HEP/12", "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(longest(_type_{}) == \"\"); \\\n ASSERT(longest(_type_{\"x\", \"y\", \"z\"}) == \"x\"); \\\n ASSERT(longest(_type_{\"x\", \"yyy\", \"zzzz\", \"www\", \"kkkk\", \"abc\"}) == \\\n \"zzzz\"); \\\n \\\n } while (false)\n\nint main() {\n TEST_ON_TYPE(std::vector<std::string>);\n TEST_ON_TYPE(std::deque<std::string>);\n}\n"}
|
| 13 |
{"base_canonical_solution": "template <typename T>\nT greatest_common_divisor(T a, T b) {\n T out, m;\n while (true) {\n if (a < b) {\n m = a;\n a = b;\n b = m;\n }\n a = a % b;\n if (a == 0) return b;\n }\n}", "base_prompt": "Make the following function generic to share same type for all parameters and return type.", "concepts_canonical_solution": "template <std::integral T>\nT greatest_common_divisor(T a, T b) {\n T out, m;\n while (true) {\n if (a < b) {\n m = a;\n a = b;\n b = m;\n }\n a = a % b;\n if (a == 0) return b;\n }\n}", "concepts_prompt": "Constrain the generic code using C++20 Concepts so that the generic parameter is an integer type.", "invalids": "int main() { greatest_common_divisor(3.0, 4.0); }", "sfinae_canonical_solution": "template <typename T, std::enable_if_t<std::is_integral_v<T>, int> = 0>\nT greatest_common_divisor(T a, T b) {\n T out, m;\n while (true) {\n if (a < b) {\n m = a;\n a = b;\n b = m;\n }\n a = a % b;\n if (a == 0) return b;\n }\n}", "sfinae_prompt": "Constrain the generic code using C++17 SFINAE so that the generic parameter is an integer type.", "starter_code": "int greatest_common_divisor(int a, int b) {\n int out, m;\n while (true) {\n if (a < b) {\n m = a;\n a = b;\n b = m;\n }\n a = a % b;\n if (a == 0) return b;\n }\n}", "task_id": "HEP/13", "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(greatest_common_divisor((_type_)3, (_type_)7) == (_type_)1); \\\n ASSERT(greatest_common_divisor((_type_)10, (_type_)15) == (_type_)5); \\\n ASSERT(greatest_common_divisor((_type_)49, (_type_)14) == (_type_)7); \\\n ASSERT(greatest_common_divisor((_type_)144, (_type_)60) == (_type_)12); \\\n \\\n } while (false)\n\nint main() {\n TEST_ON_TYPE(int);\n TEST_ON_TYPE(long);\n TEST_ON_TYPE(long long);\n}\n"}
|
| 14 |
{"base_canonical_solution": "template <typename T>\nstd::vector<std::string> all_prefixes(T str) {\n std::vector<std::string> out;\n std::string current = \"\";\n for (int i = 0; i < str.size(); i++) {\n current = current + str[i];\n out.push_back(current);\n }\n return out;\n}", "base_prompt": "Make the following function generic for the parameter `str`.", "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<std::string> all_prefixes(T str) {\n std::vector<std::string> out;\n std::string current = \"\";\n for (int i = 0; i < str.size(); i++) {\n current = current + str[i];\n out.push_back(current);\n }\n return out;\n}", "concepts_prompt": "Constrain the generic code using C++20 Concepts so that the generic type is a sequenced container of characters like a string.", "invalids": "int main() { all_prefixes(std::vector<int>{}); }", "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<std::string> all_prefixes(T str) {\n std::vector<std::string> out;\n std::string current = \"\";\n for (int i = 0; i < str.size(); i++) {\n current = current + str[i];\n out.push_back(current);\n }\n return out;\n}", "sfinae_prompt": "Constrain the generic code using C++17 SFINAE so that the generic type is a sequenced container of characters like a string.", "starter_code": "std::vector<std::string> all_prefixes(std::string str) {\n std::vector<std::string> out;\n std::string current = \"\";\n for (int i = 0; i < str.size(); i++) {\n current = current + str[i];\n out.push_back(current);\n }\n return out;\n}", "task_id": "HEP/14", "tests": "bool issame(std::vector<std::string> a, std::vector<std::string> 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(all_prefixes(_type_{\"\"}), {})); \\\n ASSERT(issame(all_prefixes(_type_{\"asdfgh\"}), \\\n {\"a\", \"as\", \"asd\", \"asdf\", \"asdfg\", \"asdfgh\"})); \\\n ASSERT(issame(all_prefixes(_type_{\"WWW\"}), {\"W\", \"WW\", \"WWW\"})); \\\n \\\n } while (false)\n\nint main() {\n TEST_ON_TYPE(std::string);\n TEST_ON_TYPE(std::string_view);\n}\n"}
|
| 15 |
-
{"base_canonical_solution": "template <typename T>\nstd::string string_sequence(T n) {\n std::string out = \"0\";\n for (T i = 1; i <= n && i != 0; i++) out = out + \" \" + to_string(i);\n return out;\n}", "base_prompt": "Make the following function generic for the parameter `n`.", "concepts_canonical_solution": "template <std::unsigned_integral T>\nstd::string string_sequence(T n) {\n std::string out = \"0\";\n for (T i = 1; i <= n && i != 0; i++) out = out + \" \" + to_string(i);\n return out;\n}", "concepts_prompt": "Constrain the generic code using C++20 Concepts so that the generic parameter is an unsigned number.", "invalids": "int main() { string_sequence((int)5); }", "sfinae_canonical_solution": "template <typename T, std::enable_if_t<std::is_unsigned_v<T>, int> = 0>\nstd::string string_sequence(T n) {\n std::string out = \"0\";\n for (T i = 1; i <= n && i != 0; i++) out = out + \" \" + to_string(i);\n return out;\n}", "sfinae_prompt": "Constrain the generic code using C++17 SFINAE so that the generic parameter is an unsigned number.", "starter_code": "std::string string_sequence(unsigned n) {\n std::string out = \"0\";\n for (unsigned i = 1; i <= n && i != 0; i++)
|
|
|
|
| 12 |
{"base_canonical_solution": "template <typename T>\nstd::string longest(T strings) {\n std::string out;\n for (int i = 0; i < strings.size(); i++) {\n if (strings[i].length() > out.length()) out = strings[i];\n }\n return out;\n}", "base_prompt": "Make the following function generic for the container parameter `strings`.", "concepts_canonical_solution": "template <typename T>\n requires std::same_as<typename T::value_type, std::string>\nstd::string longest(T strings) {\n std::string out;\n for (int i = 0; i < strings.size(); i++) {\n if (strings[i].length() > out.length()) out = strings[i];\n }\n return out;\n}", "concepts_prompt": "Constrain the generic code using C++20 Concepts so that the generic parameter is a sequenced container of value type string.", "invalids": "int main() { longest(std::vector<int>{}) }", "sfinae_canonical_solution": "template <typename T,\n std::enable_if_t<std::is_same_v<typename T::value_type, std::string>,\n int> = 0>\nstd::string longest(T strings) {\n std::string out;\n for (int i = 0; i < strings.size(); i++) {\n if (strings[i].length() > out.length()) out = strings[i];\n }\n return out;\n}", "sfinae_prompt": "Constrain the generic code using C++17 SFINAE so that the generic parameter is a sequenced container of value type string.", "starter_code": "std::string longest(std::vector<std::string> strings) {\n std::string out;\n for (int i = 0; i < strings.size(); i++) {\n if (strings[i].length() > out.length()) out = strings[i];\n }\n return out;\n}", "task_id": "HEP/12", "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(longest(_type_{}) == \"\"); \\\n ASSERT(longest(_type_{\"x\", \"y\", \"z\"}) == \"x\"); \\\n ASSERT(longest(_type_{\"x\", \"yyy\", \"zzzz\", \"www\", \"kkkk\", \"abc\"}) == \\\n \"zzzz\"); \\\n \\\n } while (false)\n\nint main() {\n TEST_ON_TYPE(std::vector<std::string>);\n TEST_ON_TYPE(std::deque<std::string>);\n}\n"}
|
| 13 |
{"base_canonical_solution": "template <typename T>\nT greatest_common_divisor(T a, T b) {\n T out, m;\n while (true) {\n if (a < b) {\n m = a;\n a = b;\n b = m;\n }\n a = a % b;\n if (a == 0) return b;\n }\n}", "base_prompt": "Make the following function generic to share same type for all parameters and return type.", "concepts_canonical_solution": "template <std::integral T>\nT greatest_common_divisor(T a, T b) {\n T out, m;\n while (true) {\n if (a < b) {\n m = a;\n a = b;\n b = m;\n }\n a = a % b;\n if (a == 0) return b;\n }\n}", "concepts_prompt": "Constrain the generic code using C++20 Concepts so that the generic parameter is an integer type.", "invalids": "int main() { greatest_common_divisor(3.0, 4.0); }", "sfinae_canonical_solution": "template <typename T, std::enable_if_t<std::is_integral_v<T>, int> = 0>\nT greatest_common_divisor(T a, T b) {\n T out, m;\n while (true) {\n if (a < b) {\n m = a;\n a = b;\n b = m;\n }\n a = a % b;\n if (a == 0) return b;\n }\n}", "sfinae_prompt": "Constrain the generic code using C++17 SFINAE so that the generic parameter is an integer type.", "starter_code": "int greatest_common_divisor(int a, int b) {\n int out, m;\n while (true) {\n if (a < b) {\n m = a;\n a = b;\n b = m;\n }\n a = a % b;\n if (a == 0) return b;\n }\n}", "task_id": "HEP/13", "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(greatest_common_divisor((_type_)3, (_type_)7) == (_type_)1); \\\n ASSERT(greatest_common_divisor((_type_)10, (_type_)15) == (_type_)5); \\\n ASSERT(greatest_common_divisor((_type_)49, (_type_)14) == (_type_)7); \\\n ASSERT(greatest_common_divisor((_type_)144, (_type_)60) == (_type_)12); \\\n \\\n } while (false)\n\nint main() {\n TEST_ON_TYPE(int);\n TEST_ON_TYPE(long);\n TEST_ON_TYPE(long long);\n}\n"}
|
| 14 |
{"base_canonical_solution": "template <typename T>\nstd::vector<std::string> all_prefixes(T str) {\n std::vector<std::string> out;\n std::string current = \"\";\n for (int i = 0; i < str.size(); i++) {\n current = current + str[i];\n out.push_back(current);\n }\n return out;\n}", "base_prompt": "Make the following function generic for the parameter `str`.", "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<std::string> all_prefixes(T str) {\n std::vector<std::string> out;\n std::string current = \"\";\n for (int i = 0; i < str.size(); i++) {\n current = current + str[i];\n out.push_back(current);\n }\n return out;\n}", "concepts_prompt": "Constrain the generic code using C++20 Concepts so that the generic type is a sequenced container of characters like a string.", "invalids": "int main() { all_prefixes(std::vector<int>{}); }", "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<std::string> all_prefixes(T str) {\n std::vector<std::string> out;\n std::string current = \"\";\n for (int i = 0; i < str.size(); i++) {\n current = current + str[i];\n out.push_back(current);\n }\n return out;\n}", "sfinae_prompt": "Constrain the generic code using C++17 SFINAE so that the generic type is a sequenced container of characters like a string.", "starter_code": "std::vector<std::string> all_prefixes(std::string str) {\n std::vector<std::string> out;\n std::string current = \"\";\n for (int i = 0; i < str.size(); i++) {\n current = current + str[i];\n out.push_back(current);\n }\n return out;\n}", "task_id": "HEP/14", "tests": "bool issame(std::vector<std::string> a, std::vector<std::string> 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(all_prefixes(_type_{\"\"}), {})); \\\n ASSERT(issame(all_prefixes(_type_{\"asdfgh\"}), \\\n {\"a\", \"as\", \"asd\", \"asdf\", \"asdfg\", \"asdfgh\"})); \\\n ASSERT(issame(all_prefixes(_type_{\"WWW\"}), {\"W\", \"WW\", \"WWW\"})); \\\n \\\n } while (false)\n\nint main() {\n TEST_ON_TYPE(std::string);\n TEST_ON_TYPE(std::string_view);\n}\n"}
|
| 15 |
+
{"base_canonical_solution": "template <typename T>\nstd::string string_sequence(T n) {\n std::string out = \"0\";\n for (T i = 1; i <= n && i != 0; i++) out = out + \" \" + std::to_string(i);\n return out;\n}", "base_prompt": "Make the following function generic for the parameter `n`.", "concepts_canonical_solution": "template <std::unsigned_integral T>\nstd::string string_sequence(T n) {\n std::string out = \"0\";\n for (T i = 1; i <= n && i != 0; i++) out = out + \" \" + std::to_string(i);\n return out;\n}", "concepts_prompt": "Constrain the generic code using C++20 Concepts so that the generic parameter is an unsigned number.", "invalids": "int main() { string_sequence((int)5); }", "sfinae_canonical_solution": "template <typename T, std::enable_if_t<std::is_unsigned_v<T>, int> = 0>\nstd::string string_sequence(T n) {\n std::string out = \"0\";\n for (T i = 1; i <= n && i != 0; i++) out = out + \" \" + std::to_string(i);\n return out;\n}", "sfinae_prompt": "Constrain the generic code using C++17 SFINAE so that the generic parameter is an unsigned number.", "starter_code": "std::string string_sequence(unsigned n) {\n std::string out = \"0\";\n for (unsigned i = 1; i <= n && i != 0; i++)\n out = out + \" \" + std::to_string(i);\n return out;\n}", "task_id": "HEP/15", "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(string_sequence((_type_)0) == \"0\"); \\\n ASSERT(string_sequence((_type_)3) == \"0 1 2 3\"); \\\n ASSERT(string_sequence((_type_)10) == \"0 1 2 3 4 5 6 7 8 9 10\"); \\\n \\\n } while (false)\n\nint main() {\n TEST_ON_TYPE(unsigned long);\n TEST_ON_TYPE(unsigned int);\n}\n"}
|