{"id":21515700,"url":"https://github.com/goblinhack/c-plus-plus-nested-template-example","last_synced_at":"2026-03-19T20:41:38.352Z","repository":{"id":138350358,"uuid":"263462425","full_name":"goblinhack/c-plus-plus-nested-template-example","owner":"goblinhack","description":"c++ template nested","archived":false,"fork":false,"pushed_at":"2020-05-12T22:12:38.000Z","size":1,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-22T21:58:18.737Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/goblinhack.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"zenodo":null}},"created_at":"2020-05-12T22:04:49.000Z","updated_at":"2025-09-04T13:21:00.000Z","dependencies_parsed_at":null,"dependency_job_id":"16dc1025-641e-46df-a393-4a0ea19879aa","html_url":"https://github.com/goblinhack/c-plus-plus-nested-template-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/goblinhack/c-plus-plus-nested-template-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goblinhack%2Fc-plus-plus-nested-template-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goblinhack%2Fc-plus-plus-nested-template-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goblinhack%2Fc-plus-plus-nested-template-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goblinhack%2Fc-plus-plus-nested-template-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/goblinhack","download_url":"https://codeload.github.com/goblinhack/c-plus-plus-nested-template-example/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goblinhack%2Fc-plus-plus-nested-template-example/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29580636,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-18T08:38:15.585Z","status":"ssl_error","status_checked_at":"2026-02-18T08:38:14.917Z","response_time":162,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":[],"created_at":"2024-11-23T23:56:26.940Z","updated_at":"2026-02-18T13:01:44.804Z","avatar_url":"https://github.com/goblinhack.png","language":null,"readme":"# c-plus-plus-nested-template-example\nPlace holder for a useful snippet, I invariably always struggle to\nget this syntax correct. Hope it helps someone else.\n\n```C++\n#include \u003ciostream\u003e\n#include \u003clist\u003e\n\ntemplate \u003ctypename T, template \u003ctypename, typename\u003e class C\u003e\nclass C2 {\n  private:\n    typedef C\u003cT, std::allocator\u003cT\u003e \u003e C1;\n    C1 container;\n  public:\n    void push(T\u0026 item) {\n        container.push_back(item);\n    }\n\n    T pop (void) {\n        T item = container.front();\n        container.pop_front();\n        return item;\n    }\n};\n\nint main() {\n    int i = 1;\n    C2\u003cint, std::list \u003e c;\n    c.push(i);\n    std::cout \u003c\u003c c.pop() \u003c\u003c std::endl;\n}\n```\n\nAnd the equivalent to the above, but using value_type\n\n```C++\n#include \u003ciostream\u003e\n#include \u003clist\u003e\n\ntemplate \u003ctypename T\u003e\nclass C1 {\n  private:\n    T container;\n    typedef typename T::value_type CT;\n  public:\n    void push(CT\u0026 item) {\n        container.push_back(item);\n    }\n\n    CT pop (void) {\n        CT item = container.front();\n        container.pop_front();\n        return item;\n    }\n};\n\nint main() {\n    int i = 1;\n    C1\u003cstd::list\u003cint\u003e \u003e c;\n    c.push(i);\n    std::cout \u003c\u003c c.pop() \u003c\u003c std::endl;\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoblinhack%2Fc-plus-plus-nested-template-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgoblinhack%2Fc-plus-plus-nested-template-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoblinhack%2Fc-plus-plus-nested-template-example/lists"}