Common System 0.2.0
Common interfaces and patterns for system integration
Loading...
Searching...
No Matches
concepts.h File Reference

Unified header for all C++20 concepts in common_system. More...

#include "core.h"
#include "callable.h"
#include "event.h"
#include "service.h"
#include "container.h"
#include "logger.h"
#include "monitoring.h"
#include "transport.h"
Include dependency graph for concepts.h:

Go to the source code of this file.

Namespaces

namespace  kcenon::common::concepts
 C++20 concepts for compile-time type validation.
 
namespace  kcenon
 
namespace  kcenon::common
 Core interfaces.
 

Detailed Description

Unified header for all C++20 concepts in common_system.

This header provides a single include point for all concepts defined in the common_system library. Including this header gives access to all concept definitions for compile-time type validation.

Available concept categories:

  • Core concepts: Result/Optional type constraints (core.h)
  • Callable concepts: Function and executor constraints (callable.h)
  • Event concepts: Event bus type constraints (event.h)
  • Service concepts: DI container constraints (service.h)
  • Container concepts: Collection type constraints (container.h)
  • Logger concepts: Logging interface constraints (logger.h)
  • Monitoring concepts: Metric collection constraints (monitoring.h)
  • Transport concepts: HTTP/UDP client constraints (transport.h)

Requirements:

  • C++20 compiler with concepts support
  • GCC 10+, Clang 10+, MSVC 2022+

Example usage:

using namespace kcenon::common::concepts;
template<Resultable R>
void process(const R& result) {
if (result.is_ok()) {
// Handle success
}
}
template<EventHandler<MyEvent> H>
uint64_t subscribe(H&& handler) {
return bus.subscribe<MyEvent>(std::forward<H>(handler));
}
Unified header for all C++20 concepts in common_system.
void process(const T &value)
C++20 concepts for compile-time type validation.
Definition callable.h:44
See also
core.h for Result/Optional concepts
callable.h for callable and executor concepts
event.h for event bus concepts
service.h for dependency injection concepts
container.h for container type concepts
logger.h for logging interface concepts
monitoring.h for metric collection concepts
transport.h for HTTP/UDP client concepts

Benefits of using concepts:

  • Clearer error messages: Template errors are displayed as concept violations instead of hundreds of lines of SFINAE failures
  • Self-documenting code: Concepts express type requirements explicitly
  • Better IDE support: More accurate auto-completion and type hints
  • Code simplification: Eliminates std::enable_if boilerplate

Migration from SFINAE:

// Before (SFINAE)
template<typename F,
typename = std::enable_if_t<
std::is_invocable_v<F> &&
std::is_void_v<std::invoke_result_t<F>>>>
void execute_async(F&& func);
// After (Concepts)
template<VoidCallable F>
void execute_async(F&& func);

Definition in file concepts.h.