Initial Commit
This commit is contained in:
11
examples/cmake/CMakeLists.txt
Normal file
11
examples/cmake/CMakeLists.txt
Normal file
@@ -0,0 +1,11 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
project(cex_cmake_demo LANGUAGES CXX)
|
||||
set(CMAKE_CXX_STANDARD 23)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
set(DEMO_INCREMENT 1)
|
||||
configure_file(config.hpp.in generated/config.hpp @ONLY)
|
||||
add_library(numbers src/numbers.cpp)
|
||||
target_include_directories(numbers PUBLIC src PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/generated")
|
||||
add_executable(cmake-demo main.cpp)
|
||||
target_link_libraries(cmake-demo PRIVATE numbers)
|
||||
2
examples/cmake/config.hpp.in
Normal file
2
examples/cmake/config.hpp.in
Normal file
@@ -0,0 +1,2 @@
|
||||
#pragma once
|
||||
#define DEMO_INCREMENT @DEMO_INCREMENT@
|
||||
7
examples/cmake/main.cpp
Normal file
7
examples/cmake/main.cpp
Normal file
@@ -0,0 +1,7 @@
|
||||
#include "numbers.hpp"
|
||||
template<Addable T>
|
||||
T twice(T value) { return value + value; }
|
||||
constexpr int evaluation_mode() {
|
||||
if consteval { return 1; } else { return 2; }
|
||||
}
|
||||
int main() { return increment(twice(20)) + evaluation_mode(); }
|
||||
3
examples/cmake/src/numbers.cpp
Normal file
3
examples/cmake/src/numbers.cpp
Normal file
@@ -0,0 +1,3 @@
|
||||
#include "numbers.hpp"
|
||||
#include "config.hpp"
|
||||
int increment(int value) { return value + DEMO_INCREMENT; }
|
||||
4
examples/cmake/src/numbers.hpp
Normal file
4
examples/cmake/src/numbers.hpp
Normal file
@@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
template<class T>
|
||||
concept Addable = requires(T value) { value + value; };
|
||||
int increment(int value);
|
||||
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>);
|
||||
}
|
||||
2
examples/navigation/docs/notes.md
Normal file
2
examples/navigation/docs/notes.md
Normal file
@@ -0,0 +1,2 @@
|
||||
Search for increment, then exclude docs/ to remove this documentation result.
|
||||
Code navigation still indexes the entire active build configuration.
|
||||
19
examples/navigation/main.cpp
Normal file
19
examples/navigation/main.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#include "numbers.hpp"
|
||||
|
||||
template <Addable T>
|
||||
T twice(T value) {
|
||||
return value + value;
|
||||
}
|
||||
|
||||
// This branch syntax requires C++23.
|
||||
constexpr int evaluation_mode() {
|
||||
if consteval {
|
||||
return 1;
|
||||
} else {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
return increment(twice(20)) + evaluation_mode();
|
||||
}
|
||||
2
examples/navigation/meson.build
Normal file
2
examples/navigation/meson.build
Normal file
@@ -0,0 +1,2 @@
|
||||
project('cex-navigation-demo', 'cpp', default_options: ['cpp_std=c++23'])
|
||||
executable('navigation-demo', 'main.cpp', 'numbers.cpp')
|
||||
5
examples/navigation/numbers.cpp
Normal file
5
examples/navigation/numbers.cpp
Normal file
@@ -0,0 +1,5 @@
|
||||
#include "numbers.hpp"
|
||||
|
||||
int increment(int value) {
|
||||
return value + 1;
|
||||
}
|
||||
10
examples/navigation/numbers.hpp
Normal file
10
examples/navigation/numbers.hpp
Normal file
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
// Try References on Addable: its constraint is used in main.cpp.
|
||||
template <typename T>
|
||||
concept Addable = requires(T value) {
|
||||
value + value;
|
||||
};
|
||||
|
||||
// Try Definition or Callers on increment.
|
||||
int increment(int value);
|
||||
Reference in New Issue
Block a user