Repository: j178/leetgo (language: python)

Issue:
fix: don't include <bits/stdc++.h> is not using cc
Closes #138 

[Feature] No "bits/stdc++.h" in macOS/clang
### Verify steps

- [X]  我已经在 [Issue Tracker](https://github.com/j178/leetgo/issues) 中找过我要提出的请求 I have searched on the [Issue Tracker](https://github.com/j178/leetgo/issues) for a related feature request. 
- [X]  我已经仔细看过 [Documentation](https://github.com/j178/leetgo/blob/master/README.md) 并无法自行解决问题 I have read the [Documentation](https://github.com/j178/leetgo/blob/master/README.md) and was unable to solve the issue. 

### Description

`bits/stdc++.h` is a gnu/gcc extension, which is not present in macOS/clang. 

https://stackoverflow.com/questions/28994148/how-can-i-include-bits-stdc-in-xcode

Should we fix this rather than letting the users fix this for themselves?

### Possible Solution

```cpp
#ifndef __APPLE__
    #include <bits/stdc++.h>
#else
    // insert #include directives here, or make a copy of gcc's bits/stdc++.h
#endif
```



Discussion / hints:

Since we are emulating the LeetCode OJ, I think we should ship the `bits/stdc++.h` for macOS version. Like this one: https://github.com/tekfyl/bits-stdc-.h-for-mac/blob/master/stdc%2B%2B.h
I agree. Should I make a separate PR or should I include it in #137 ?
It's better to create a separate PR.
We can use this command to fetch the latest `stdc++.h` directly from gcc's source repo:
`git archive --remote=git://gcc.gnu.org/git/gcc.git HEAD libstdc++-v3/include/precompiled/stdc++.h | tar -xO`
One question, if we include this file in our repo, do we have to change our license to GPL…
What if we run this command on the user's machine?
> What if we run this command on the user's machine?

I don't think we should do this automatically. Instead, we should add some instructions to our manual and let the users handle it themselves. Alternatively, we can simply have Mac users run `brew install gcc` :)

Fix patch:
diff --git a/lang/cpp.go b/lang/cpp.go
index 2a3f8ce3..58ddefe8 100644
--- a/lang/cpp.go
+++ b/lang/cpp.go
@@ -242,16 +242,6 @@ func (c cpp) generateTestContent(q *leetcode.QuestionData) (string, error) {
 	), nil
 }
 
-func usingGCC() bool {
-	cxx := config.Get().Code.Cpp.CXX
-	cmd := exec.Command(cxx, "--version")
-	output, err := cmd.CombinedOutput()
-	if err != nil {
-		return true
-	}
-	return strings.Contains(string(output), "gcc")
-}
-
 func (c cpp) generateCodeFile(
 	q *leetcode.QuestionData,
 	filename string,
@@ -262,20 +252,12 @@ func (c cpp) generateCodeFile(
 	FileOutput,
 	error,
 ) {
-	var stdCppHeader string
-	if usingGCC() {
-		stdCppHeader = "#include <bits/stdc++.h>\n"
-	}
-
 	codeHeader := fmt.Sprintf(
-		`%s#include "%s"
+		`#include "%s"
 using namespace std;
 
-`,
-		stdCppHeader,
-		cppUtils.HeaderName,
+`, cppUtils.HeaderName,
 	)
-
 	testContent, err := c.generateTestContent(q)
 	if err != nil {
 		return FileOutput{}, err


Test patch:
diff --git a/testutils/cpp/LC_IO.h b/testutils/cpp/LC_IO.h
index 8d36f9d1..21077a50 100644
--- a/testutils/cpp/LC_IO.h
+++ b/testutils/cpp/LC_IO.h
@@ -1,6 +1,11 @@
 #ifndef LC_IO_H
 #define LC_IO_H
 
+#define GCC_COMPILER (defined(__GNUC__) && !defined(__clang__))
+#if GCC_COMPILER
+    #include <bits/stdc++.h>
+#endif
+
 #include <iomanip>
 #include <queue>