capydi
Loading...
Searching...
No Matches
Constleton.hpp
Go to the documentation of this file.
1#ifndef CONSTLETON_HPP_
2#define CONSTLETON_HPP_
3
9
12#include <tuple>
13#include <type_traits>
14#include <expected>
15
16namespace capy::di
17{
18
19template<typename T>
20struct IsConstexprReference : std::false_type {};
21
22template<typename T, const T& Ref>
23struct IsConstexprReference<meta::ConstexprRef<T, Ref>> : std::true_type {};
24
25template<typename T>
27
28// TODO: stop using ConstexprReference. Avoid tight coupling with ConstexprRef.
29template<typename T>
31
32
33// template<class Lambda, int=(Lambda{}(), 0)>
34// constexpr bool is_constexpr(Lambda) { return true; }
35// constexpr bool is_constexpr(...) { return false; }
36
37template<typename Type>
39 : public DecoratableConfig<
40 Constleton<Type>
41 >
42{
43// TODO: check for well-formness of Constleton (if it is constexpr)
44
45public:
46 using CentralType = const Type;
47 using /* meta::Pack<meta::Pack<?>> */ ResolutionKeysPack = meta::Pack<
49 >;
50
51public:
53
54public:
55 template<ConstexprReference... Dependencies>
59 const std::tuple<Dependencies...>& dependencies
60 ) const
61 {
62 static constexpr CentralType instance = std::apply(Type::create, dependencies);
63 return std::expected<meta::ConstexprRef<CentralType, instance>, Error> {
65 };
66 }
67
68 // TODO: think of simplifying this one
69 // can we replace tuple with just auto?
70 template<typename... Dependencies>
74 const std::tuple<Dependencies...>& dependencies
75 ) const
76 {
77 return std::expected<meta::RuntimeRef<CentralType>, Error> {
78 std::unexpected { Error::CONSTLETON_ERROR }
79 };
80 }
81};
82
83}
84
85#endif // !CONSTLETON_HPP_
Configuration type enumeration for the dependency injection system.
Compile-time type pack utilities and metaprogramming foundations.
Definition Constleton.hpp:30
Definition WrappedWIth.hpp:30
Definition Decorator.hpp:19
constexpr bool is_constexpr_reference_v
Definition Constleton.hpp:26
ConfigType
Categorization of configuration strategies in the DI container.
Definition ConfigType.hpp:24
@ CREATIONAL
Creational configs handle object instantiation and factory patterns. These are responsible for creati...
Definition ConfigType.hpp:27
Error
Enumeration of possible errors during dependency injection resolution.
Definition Error.hpp:26
@ CONSTLETON_ERROR
Definition Error.hpp:35
Definition Rebind.hpp:7
Definition Constleton.hpp:42
meta::Pack< meta::Pack< CentralType > > ResolutionKeysPack
Definition Constleton.hpp:47
const Type CentralType
Definition Constleton.hpp:46
static constexpr ConfigType CONFIG_TYPE
Definition Constleton.hpp:52
constexpr meta::wrapped_with< std::expected > auto do_resolve(meta::Pack< CentralType > &&keys, const std::tuple< Dependencies... > &dependencies) const
Definition Constleton.hpp:57
Definition DecoratableConfig.hpp:9
Definition Constleton.hpp:20
Definition ConstexprRef.hpp:14
A compile-time heterogeneous type list.
Definition Pack.hpp:70