{"id":18976728,"url":"https://github.com/palikar/ctgraph","last_synced_at":"2026-05-19T04:02:25.130Z","repository":{"id":93817521,"uuid":"219015267","full_name":"palikar/ctgraph","owner":"palikar","description":"A small project of a compile-time graph library in C++17 ","archived":false,"fork":false,"pushed_at":"2020-02-15T18:36:35.000Z","size":248,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-02T14:50:11.389Z","etag":null,"topics":["c","compile-time","constexpr","constexpr-context","cpp-library","cpp17","header-only"],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/palikar.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":"2019-11-01T15:45:12.000Z","updated_at":"2023-06-24T18:29:39.000Z","dependencies_parsed_at":"2023-03-13T17:10:00.054Z","dependency_job_id":null,"html_url":"https://github.com/palikar/ctgraph","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/palikar/ctgraph","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/palikar%2Fctgraph","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/palikar%2Fctgraph/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/palikar%2Fctgraph/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/palikar%2Fctgraph/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/palikar","download_url":"https://codeload.github.com/palikar/ctgraph/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/palikar%2Fctgraph/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270996980,"owners_count":24681953,"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","status":"online","status_checked_at":"2025-08-18T02:00:08.743Z","response_time":89,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["c","compile-time","constexpr","constexpr-context","cpp-library","cpp17","header-only"],"created_at":"2024-11-08T15:26:07.768Z","updated_at":"2026-05-19T04:02:20.090Z","avatar_url":"https://github.com/palikar.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"Build status: [![Build Status](https://travis-ci.org/palikar/ctgraph.svg?branch=master)](https://travis-ci.org/palikar/ctgraph)\n    [![codecov](https://codecov.io/gh/palikar/ctgraph/branch/master/graph/badge.svg)](https://codecov.io/gh/palikar/ctgraph)\n    [![CodacyBadge](https://api.codacy.com/project/badge/Grade/83223760ee624b159b1869492c6d99ed)](https://www.codacy.com/manual/palikar/ctgraph?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=palikar/ctgraph\u0026amp;utm_campaign=Badge_Grade)\n    [![CodeFactor](https://www.codefactor.io/repository/github/palikar/ctgraph/badge)](https://www.codefactor.io/repository/github/palikar/ctgraph)\n    [![ScoreMe](http://readme-score-api.herokuapp.com/score.svg?url=https%3a%2f%2fgithub.com%2fpalikar%2fctgraph%2f)](http://clayallsopp.github.io/readme-score?url=https%3a%2f%2fgithub.com%2fpalikar%2fctgraph%2f)\n    [![Licence](https://img.shields.io/github/license/palikar/ctgraph)](https://github.com/palikar/ctgraph/)\n    [![Version](https://img.shields.io/github/v/tag/palikar/ctgraph)](https://github.com/palikar/ctgraph/)\n\n\n# Compile-Time Graph (CTGraph)\n\n![img](./logo.png)\n\n\n## Abstract\n\nA small C++17 project that implements as graph structure that can be used entirely at compile time. I was mainly inspired by a part of [`cpp_box`](https://github.com/lefticus/cpp_box) \u0026#x2013; a project by [Jason Turner](https://github.com/lefticus/cpp_box). In there he has implemented a finate-state machine that can be used at compile-time in a constexpr context. This had me fascinated and made me do some experimental programming in hopes of finding out what else can be achieved at compile time. Just like that, for several hours I botched together CTGraph (Compile-Time Graph).\n\n\n### Seller features\n\n-   Header only\n-   Usable in constexpr context (mostly)\n-   Usable in const context (fully)\n\n\n## Installation\n\n\n### Prerequisites\n\nThe project can be compiled with clang7, gcc9 and gcc8.\n\n\n### Building\n\nCTGraph can easily be build from source:\n\n```sh\ngit clone https://github.com/palikar/ctgraph/\ncd ctgraph \u0026\u0026 mkdir build\ncd build\ncmake .. -DALL_WARNINGS=1 -DLIBCPP=0 -DENABLE_CLANG_TIDY=0 -DENABLE_CPPCHECK=0 -DENABLE_COVERAGE=1 -DBUILD_TESTS=1 -DCMAKE_BUILD_TYPE=Debug\nmake -j4\n```\n\nThe flags for the cmake command can be adjusted as needed.\n\n\n\nThe build generates the file `ctgraph.hpp` in the build directory. This is a single header that can be included in other projects and provides all of the functionality of CTGraph.\n\n\n### Running tests\n\nCTGraph uses [Catch2](https://github.com/catchorg/Catch2) for its testing. If the cmake command was ran with `-DBUILD_TESTS=1`, there will be an executable `graph_tests` in the build directory. Running it will result in the execution of all tests for the project. Alternatively one can also use ctest:\n\n```sh\nctest -j2\n```\n\nor invoke the `test` target\n\n```sh\nmake test\n```\n\n\n## Usage\n\nAs mentioned, including the single header file in your file is enough to get you started. To note is that CTGraph uses some C++17 features so a compile flag like `-std=c++17` is required to compile a file using CTGraph.\n\n\n\nThe nodes for a graph are given through a user-defined `enum` like:\n\n```c++\nenum class NodeTypes\n{\n    UNKNOWN = 0,\n    NODE_1 = 1,\n    NODE_2 = 2,\n    NODE_3 = 3\n};\n```\n\nWith that, we can now construct our graph in a \u0026ldquo;static and constexpr\u0026rdquo; way:\n\n```c++\n#include \u003cctgraph.hpp\u003e\nstatic constexpr auto graph = ctgraph::Graph{ctgraph::Node{NodeTypes::NODE_1, NodeTypes::NODE_2, NodeTypes::NODE_3},\n                                             ctgraph::Node{NodeTypes::NODE_2, NodeTypes::NODE_3}};\n```\n\nThe semantics of the constructor of ctgraph::Node are `\u003cstarting_vertex\u003e [\u003cfollower(s)\u003e]`. Only nodes starting node are considered vertices in the graph. IN the above example, `NODE_3` is not \u0026ldquo;in\u0026rdquo; the vertex list of the graph. For this to be the case, we have to define the graph as:\n\n```c++\nstatic constexpr auto graph = ctgraph::Graph{ctgraph::Node{NodeTypes::NODE_1, NodeTypes::NODE_2, NodeTypes::NODE_3},\n                                             ctgraph::Node{NodeTypes::NODE_2, NodeTypes::NODE_3},\n                                             ctgraph::Node{NodeTypes::NODE_3}};\n```\n\nFrom here on out, we can use the graph in all sorts of ways.\n\n\n\nGetting all of the vertices:\n\n```c++\nconstexpr auto vertices = graph.vertices(); \nfor(const auto\u0026 v: vertices ){\n    std::cout \u003c\u003c \"Vertex: \" \u003c\u003c static_cast\u003cint\u003e(v) \u003c\u003c \"\\n\";\n}\n```\n\n\n\nChecking the size of the graph:\n\n```c++\nconstexpr auto size = graph.size();\nstd::cout \u003c\u003c \"Size: \" \u003c\u003c size \u003c\u003c \"\\n\";\n```\n\nThe number of vertices is considered as \u0026ldquo;size\u0026rdquo;.\n\n\n\nChecking if Node is in the graph:\n\n```c++\nstd::cout \u003c\u003c graph.contains(NodeTypes::NODE_4) \u003c\u003c \"\\n\";\n```\n\n\n\nChecking if two nodes are adjacent in the graph:\n\n```c++\nstd::cout \u003c\u003c graph.adjacent(NodeTypes::NODE_2, NodeTypes::NODE_3) \u003c\u003c \"\\n\";\nstd::cout \u003c\u003c graph.adjacent(NodeTypes::NODE_3, NodeTypes::NODE_1) \u003c\u003c \"\\n\";\n```\n\n\n\nYou can find a compilable and commented example in the [source folder](https://github.com/palikar/ctgraph/blob/master/src/example.cpp). It demonstrates most of the current features of the library.\n\n\n## Acknowledgments\n\n-   [Jason Turner](https://github.com/lefticus/cpp_box) and [`state_machine.hpp`](https://github.com/lefticus/cpp_box/blob/master/include/cpp_box/state_machine.hpp) for inspiration.\n-   [Amalgamate](https://github.com/edlund/amalgamate) for generating a single-include header file.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpalikar%2Fctgraph","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpalikar%2Fctgraph","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpalikar%2Fctgraph/lists"}