feat: Apply C++20 Concepts for Improved API#194
Merged
Conversation
Add comprehensive C++20 concept definitions for compile-time type validation across the common_system library: - core.h: Result/Optional concepts (Resultable, Unwrappable, Mappable) - callable.h: Callable concepts (Invocable, VoidCallable, JobLike) - event.h: Event bus concepts (EventType, EventHandler, EventFilter) - service.h: DI concepts (ServiceInterface, ServiceFactory) - container.h: Container concepts (Container, SequenceContainer) - concepts.h: Unified header for all concepts These concepts provide: - Clearer compile-time error messages - Self-documenting type requirements - Simplified template constraints (replacing SFINAE) - Better IDE support for auto-completion Refs #192
- Add value_type and error_type aliases to Result<T> for concept compatibility - Add value_type alias to Optional<T> for concept compatibility - Apply concepts::EventType constraint to event_bus publish() - Apply concepts::EventHandler constraint to event_bus subscribe() - Apply concepts::EventFilter constraint to event_bus subscribe_filtered() These changes enable compile-time type validation with clear error messages when using the event bus with invalid types. Refs #192
- Apply ServiceInterface concept to register_type TInterface parameter - Apply ServiceImplementation concept to register_type TImpl parameter - Apply ServiceFactory concept to register_factory TFactory parameter - Apply SimpleServiceFactory concept to register_simple_factory TFactory These changes enable clearer compile-time error messages when registering services with invalid types, replacing verbose SFINAE errors with concise concept violation messages. Refs #192
- Add Unreleased section to CHANGELOG.md with concepts feature (#192) - Add CONCEPTS_GUIDE.md with comprehensive usage documentation - Add CONCEPTS_GUIDE_KO.md Korean translation - Include available concepts reference tables - Add usage examples and migration guide from SFINAE - Document error message improvements Refs #192
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #194 +/- ##
======================================
Coverage 0.00% 0.00%
======================================
Files 13 17 +4
Lines 1582 2244 +662
======================================
- Misses 1582 2244 +662
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
8 tasks
kcenon
added a commit
that referenced
this pull request
Apr 13, 2026
* feat(concepts): add C++20 concepts for type validation Add comprehensive C++20 concept definitions for compile-time type validation across the common_system library: - core.h: Result/Optional concepts (Resultable, Unwrappable, Mappable) - callable.h: Callable concepts (Invocable, VoidCallable, JobLike) - event.h: Event bus concepts (EventType, EventHandler, EventFilter) - service.h: DI concepts (ServiceInterface, ServiceFactory) - container.h: Container concepts (Container, SequenceContainer) - concepts.h: Unified header for all concepts These concepts provide: - Clearer compile-time error messages - Self-documenting type requirements - Simplified template constraints (replacing SFINAE) - Better IDE support for auto-completion Refs #192 * refactor(patterns): apply C++20 concepts to Result and event_bus - Add value_type and error_type aliases to Result<T> for concept compatibility - Add value_type alias to Optional<T> for concept compatibility - Apply concepts::EventType constraint to event_bus publish() - Apply concepts::EventHandler constraint to event_bus subscribe() - Apply concepts::EventFilter constraint to event_bus subscribe_filtered() These changes enable compile-time type validation with clear error messages when using the event bus with invalid types. Refs #192 * refactor(di): apply C++20 concepts to service container interface - Apply ServiceInterface concept to register_type TInterface parameter - Apply ServiceImplementation concept to register_type TImpl parameter - Apply ServiceFactory concept to register_factory TFactory parameter - Apply SimpleServiceFactory concept to register_simple_factory TFactory These changes enable clearer compile-time error messages when registering services with invalid types, replacing verbose SFINAE errors with concise concept violation messages. Refs #192 * docs: add C++20 concepts documentation - Add Unreleased section to CHANGELOG.md with concepts feature (#192) - Add CONCEPTS_GUIDE.md with comprehensive usage documentation - Add CONCEPTS_GUIDE_KO.md Korean translation - Include available concepts reference tables - Add usage examples and migration guide from SFINAE - Document error message improvements Refs #192
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR implements Issue #192 to apply C++20 Concepts to common_system for improved compile-time type validation and clearer error messages.
Changes
Phase 1: Define Base Concepts
concepts/core.h: Result/Optional concepts (Resultable, Unwrappable, Mappable, Chainable)concepts/callable.h: Callable concepts (Invocable, VoidCallable, JobLike, ExecutorLike)concepts/event.h: Event bus concepts (EventType, EventHandler, EventFilter)concepts/service.h: DI concepts (ServiceInterface, ServiceImplementation, ServiceFactory)concepts/container.h: Container concepts (Container, SequenceContainer, CircularBuffer)concepts/concepts.h: Unified header for all conceptsPhase 2: Refactor Existing Code
value_typeanderror_typetype aliases toResult<T>value_typetype alias toOptional<T>simple_event_buspublish(), subscribe(), subscribe_filtered()Phase 3: Service Container
ServiceInterfaceconcept to register_type TInterface parameterServiceImplementationconcept to register_type TImpl parameterServiceFactoryconcept to register_factorySimpleServiceFactoryconcept to register_simple_factoryPhase 4: Documentation
CONCEPTS_GUIDE.mdwith usage examplesCONCEPTS_GUIDE_KO.mdBenefits
Error Message Comparison
Before (SFINAE)
After (Concepts)
Test plan
Closes #192