Initial Commit
This commit is contained in:
19
examples/concepts/composed.hpp
Normal file
19
examples/concepts/composed.hpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
#include "foundation.hpp"
|
||||
namespace library = std;
|
||||
using std::copyable;
|
||||
namespace demo {
|
||||
template<class T>
|
||||
concept Sized = requires(const T value) {
|
||||
{ value.size() } -> library::integral;
|
||||
requires library::same_as<decltype(value.size()), unsigned>;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
concept Flexible = (Arithmetic<T> || Sized<T>) && requires(T value) {
|
||||
requires copyable<T>;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
concept Outer = Flexible<T> || Addable<T>;
|
||||
}
|
||||
9
examples/concepts/foundation.hpp
Normal file
9
examples/concepts/foundation.hpp
Normal file
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
#include <concepts>
|
||||
namespace demo {
|
||||
template<class T>
|
||||
concept Addable = requires(T value) { value + value; };
|
||||
|
||||
template<class T>
|
||||
concept Arithmetic = Addable<T> && (std::integral<T> || std::floating_point<T>);
|
||||
}
|
||||
13
examples/concepts/main.cpp
Normal file
13
examples/concepts/main.cpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#include "composed.hpp"
|
||||
struct Container { unsigned size() const { return 2; } };
|
||||
static_assert(demo::Flexible<int>);
|
||||
static_assert(demo::Flexible<Container>);
|
||||
static_assert(demo::Outer<double>);
|
||||
static_assert(!demo::Flexible<void>);
|
||||
template<demo::Flexible T>
|
||||
T constrained_identity(T value) { return value; }
|
||||
template<class T> auto type_use(T) -> std::bool_constant<demo::Flexible<T>> { return {}; }
|
||||
bool ordinary_use() { return demo::Flexible<int>; }
|
||||
int main() { return 0; }
|
||||
|
||||
#include "policies.hpp"
|
||||
2
examples/concepts/meson.build
Normal file
2
examples/concepts/meson.build
Normal file
@@ -0,0 +1,2 @@
|
||||
project('cex-composed-concepts', 'cpp', default_options: ['cpp_std=c++23'])
|
||||
executable('concepts', 'main.cpp')
|
||||
31
examples/concepts/policies.hpp
Normal file
31
examples/concepts/policies.hpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
#include <type_traits>
|
||||
|
||||
namespace gridfire::policy {
|
||||
struct ReactionChainPolicy {};
|
||||
struct NetworkPolicy {};
|
||||
}
|
||||
namespace py {
|
||||
template<class T, class BaseT> struct class_ {
|
||||
template<class F> class_& def(const char*, F) { return *this; }
|
||||
};
|
||||
}
|
||||
namespace bindings::detail {
|
||||
template<typename T>
|
||||
concept IsReactionChainPolicy = std::is_base_of_v<gridfire::policy::ReactionChainPolicy, T>;
|
||||
template<typename T>
|
||||
concept IsNetworkPolicy = std::is_base_of_v<gridfire::policy::NetworkPolicy, T>;
|
||||
|
||||
template<IsReactionChainPolicy T, IsReactionChainPolicy BaseT>
|
||||
void registerReactionChainPolicyDefs(py::class_<T, BaseT>& pyClass) {
|
||||
pyClass.def("name", &T::name)
|
||||
.def("hash", [](const T& self) { return self.hash(0); });
|
||||
}
|
||||
|
||||
template<IsNetworkPolicy T, IsNetworkPolicy BaseT>
|
||||
void registerNetworkPolicyDefs(py::class_<T, BaseT> pyClass) {
|
||||
pyClass.def("name", &T::name)
|
||||
.def("construct", [](const T& self) { return self.construct(); });
|
||||
}
|
||||
static_assert(IsNetworkPolicy<gridfire::policy::NetworkPolicy>);
|
||||
}
|
||||
Reference in New Issue
Block a user