{"id":13713423,"url":"https://github.com/xyproto/go2cpp","last_synced_at":"2025-09-17T21:33:08.002Z","repository":{"id":136548223,"uuid":"135707795","full_name":"xyproto/go2cpp","owner":"xyproto","description":"Go to C++20 transpiler","archived":false,"fork":false,"pushed_at":"2024-07-02T22:50:50.000Z","size":122,"stargazers_count":119,"open_issues_count":0,"forks_count":7,"subscribers_count":7,"default_branch":"main","last_synced_at":"2024-12-30T04:16:12.604Z","etag":null,"topics":["compiler","cxx","cxx20","go","transpiler"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xyproto.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-06-01T11:08:26.000Z","updated_at":"2024-12-28T23:17:39.000Z","dependencies_parsed_at":"2024-01-18T12:52:09.277Z","dependency_job_id":"b212c943-e928-4f5a-b29a-1b9b47c48f8b","html_url":"https://github.com/xyproto/go2cpp","commit_stats":{"total_commits":151,"total_committers":2,"mean_commits":75.5,"dds":0.07284768211920534,"last_synced_commit":"e6cc1db810387bc652f14d03b61f4da571988748"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xyproto%2Fgo2cpp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xyproto%2Fgo2cpp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xyproto%2Fgo2cpp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xyproto%2Fgo2cpp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xyproto","download_url":"https://codeload.github.com/xyproto/go2cpp/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233426261,"owners_count":18674554,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["compiler","cxx","cxx20","go","transpiler"],"created_at":"2024-08-02T23:01:35.806Z","updated_at":"2025-09-17T21:33:02.670Z","avatar_url":"https://github.com/xyproto.png","language":"Go","funding_links":[],"categories":["Repositories"],"sub_categories":[],"readme":"# go2cpp\n\nCompiles Go to native executables via C++20.\n\nOne of the goals is for the compiler to be able to compile itself.\n\nThe intended use is not to convert entire existing Go programs to C++, but to help port parts of it to C++, or perhaps write programs from scratch and continually check that the program can be converted and compiled as C++.\n\n## Known issues\n\n* Only works with simple code samples, for now.\n* Very few functions from the Go standard library are implemented. The ideal would be to be able to compile the official Go standard library.\n* A good plan for how to implement `import` is needed.\n\n## Features and limitations\n\n* Pretty fast.\n* Simple to use.\n* Few dependencies (for compiling `go2cpp`, only the go compiler is needed).\n* Low complexity.\n* Short source code.\n\n## Required dependencies\n\n* `g++` with support for C++20 is used for compiling the generated C++ code.\n* `clang-format` is used for formatting the generated C++ code.\n\n## Installation\n\n    go install github.com/xyproto/go2cpp@latest\n\nThen `~/go/bin/go2cpp` should be available (unless GOPATH points somewhere else).\n\n## Usage\n\nCompile to executable:\n\n    go2cpp main.go -o main\n\nOutput what the intermediate C++20 code looks like:\n\n    go2cpp main.go\n\n## Example transformations\n\n**Go input:**\n\n```go\n// Multiple return\npackage main\n\nimport (\n    \"fmt\"\n)\n\nfunc addsub(x int) (a, b int) {\n    return x + 2, x - 2\n}\n\nfunc main() {\n    y, z := addsub(4)\n    fmt.Println(\"y =\", y)\n    fmt.Println(\"z =\", z)\n}\n```\n\n**C++ output:**\n\n```c++\n#include \u003ciostream\u003e\n#include \u003ctuple\u003e\n\n// Multiple return\n\nauto addsub(int x) -\u003e std::tuple\u003cint, int\u003e\n{\n    return std::tuple\u003cint, int\u003e{ x + 2, x - 2 };\n}\n\nauto main() -\u003e int\n{\n    auto [y, z] = addsub(4);\n    std::cout \u003c\u003c \"y =\"\n              \u003c\u003c \" \" \u003c\u003c y \u003c\u003c std::endl;\n    std::cout \u003c\u003c \"z =\"\n              \u003c\u003c \" \" \u003c\u003c z \u003c\u003c std::endl;\n    return 0;\n}\n```\n\n**Go input:**\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n)\n\nfunc main() {\n    m := map[string]string{\"first\": \"hi\", \"second\": \"you\", \"third\": \"there\"}\n    first := true\n    for k, v := range m {\n        if first {\n            first = false\n        } else {\n            fmt.Print(\" \")\n        }\n        fmt.Print(k + v)\n    }\n    fmt.Println()\n}\n```\n\n**C++ output:**\n\n```c++\n#include \u003ciostream\u003e\n#include \u003cstring\u003e\n#include \u003cunordered_map\u003e\n\ntemplate \u003ctypename T\u003e void _format_output(std::ostream\u0026 out, T x)\n{\n    if constexpr (std::is_same\u003cT, bool\u003e::value) {\n        out \u003c\u003c std::boolalpha \u003c\u003c x \u003c\u003c std::noboolalpha;\n    } else if constexpr (std::is_integral\u003cT\u003e::value) {\n        out \u003c\u003c static_cast\u003cint\u003e(x);\n    } else {\n        out \u003c\u003c x;\n    }\n}\n\nauto main() -\u003e int\n{\n    std::unordered_map\u003cstd::string, std::string\u003e m{ { \"first\", \"hi\" }, { \"second\", \"you\" },\n        { \"third\", \"there\" } };\n    auto first = true;\n    for (const auto\u0026 [k, v] : m) {\n        if (first) {\n            first = false;\n        } else {\n            std::cout \u003c\u003c \" \";\n        }\n\n        _format_output(std::cout, k + v);\n    }\n\n    std::cout \u003c\u003c std::endl;\n    return 0;\n}\n```\n\n# General info\n\n* Version: 0.4.0\n* License: MIT\n\n# TODO\n\n## Syntactic elements\n\n- [x] backtick quoted strings: \u003ccode\u003e`\u003c/code\u003e (one level deep only)\n- [ ] `iota`\n\n## Keywords\n\n- [x] `break`\n- [x] `case`\n- [ ] `chan`\n- [x] `const`\n- [x] `continue`\n- [x] `default`\n- [x] `defer`\n- [x] `else`\n- [x] `fallthrough`\n- [x] `for`\n- [x] `func`\n- [ ] `go`\n- [x] `goto`\n- [x] `if`\n- [x] `import` (partially)\n- [ ] `interface`\n- [x] `map` (needs more testing)\n- [x] `package` (partially)\n- [x] `range`\n- [x] `return`\n- [ ] `select`\n- [x] `struct` (needs more testing)\n- [x] `switch`\n- [x] `type` (needs more testing)\n- [x] `var`\n\n## Standard library\n\n- [x] `fmt.Println`\n- [x] `fmt.Print`\n- [ ] `fmt.Printf` (partially)\n- [ ] `fmt.Sprintf`\n- [x] `strings.Contains`\n- [x] `strings.HasPrefix`\n- [ ] `strings.HasSuffix`\n- [ ] `strings.Index`\n- [ ] `strings.Join`\n- [ ] `strings.NewReader`\n- [ ] `strings.Replace`\n- [ ] `strings.Split`\n- [ ] `strings.SplitN`\n- [x] `strings.TrimSpace`\n- [ ] All the rest\n\nOne goal is that all code in the standard library should transpile correctly to C++20.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxyproto%2Fgo2cpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxyproto%2Fgo2cpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxyproto%2Fgo2cpp/lists"}