struct graph

This commit is contained in:
2026-09-07 15:52:46 -04:00
parent 30ed3351b5
commit 93521c53fb
15 changed files with 1061 additions and 30 deletions

View File

@@ -0,0 +1,5 @@
cmake_minimum_required(VERSION 3.20)
project(cex_type_demo LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_executable(type-demo main.cpp)

2
examples/types/main.cpp Normal file
View File

@@ -0,0 +1,2 @@
#include "types.hpp"
int main() { demo::Box<int> box(1); box.run(2); }

View File

@@ -0,0 +1,2 @@
project('cex-type-demo', 'cpp', default_options: ['cpp_std=c++23'])
executable('type-demo', 'main.cpp')

25
examples/types/types.hpp Normal file
View File

@@ -0,0 +1,25 @@
#pragma once
#include <concepts>
#include <vector>
namespace demo {
template<class T> concept Addable = requires(T a) { a + a; };
template<class T> concept Sized = requires(T a) { a.size(); };
struct Base { int id; };
struct Helper { int work() { return 1; } };
template<Addable T>
requires std::copyable<T> && (Addable<T> || Sized<T>)
struct Box : Base {
T value;
std::vector<T> entries;
Helper helper;
using value_type = T;
Box(Addable auto x) requires std::constructible_from<T, decltype(x)> : value(x) { helper.work(); }
template<Sized U> requires requires(U u) { u.size(); }
void set(const U& u) requires Addable<T> { helper.work(); }
void run(std::integral auto n) { helper.work(); }
template<class U> requires std::convertible_to<U, T>
void assign(U u) { value = u; }
};
using IntBox = Box<int>;
enum class State { idle, ready };
}