Skip to content

Commit c30d80f

Browse files
committed
Rename containers, cleanup macros
1 parent fda6fd4 commit c30d80f

File tree

12 files changed

+652
-56
lines changed

12 files changed

+652
-56
lines changed

include/kangaru/detail/container.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ namespace kangaru {
1717
using cached_pointer_to_injectable_reference_source = typename cached_pointer_to_source<injectable_reference_source>::template source<T>;
1818

1919
template<source Source, cache_map Cache = std::unordered_map<std::size_t, void*>, heap_storage Storage = default_heap_storage>
20-
struct dynamic_container {
21-
explicit constexpr dynamic_container(Source source) noexcept :
20+
struct container {
21+
explicit constexpr container(Source source) noexcept :
2222
source{
2323
make_source_with_cache(
2424
make_source_with_heap_storage(
@@ -30,8 +30,8 @@ namespace kangaru {
3030
)
3131
} {}
3232

33-
constexpr dynamic_container() noexcept requires std::default_initializable<Source> :
34-
dynamic_container{Source{}} {}
33+
constexpr container() noexcept requires std::default_initializable<Source> :
34+
container{Source{}} {}
3535

3636
private:
3737
with_cache<
@@ -65,14 +65,14 @@ namespace kangaru {
6565

6666
public:
6767
template<injectable T>
68-
constexpr auto provide() & -> T requires source_of<rebound_source_tree_t<dynamic_container&>, T> {
68+
constexpr auto provide() & -> T requires source_of<rebound_source_tree_t<container&>, T> {
6969
return kangaru::provide<T>(
7070
rebound_source_tree(*this, source)
7171
);
7272
}
7373

7474
template<injectable T>
75-
constexpr auto provide() && -> T requires source_of<rebound_source_tree_t<dynamic_container&&>, T> {
75+
constexpr auto provide() && -> T requires source_of<rebound_source_tree_t<container&&>, T> {
7676
return kangaru::provide<T>(
7777
rebound_source_tree(std::move(*this), std::move(source))
7878
);

include/kangaru/detail/ctti.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace kangaru::detail::ctti {
1313
template<typename T>
14-
inline KANGARU5_CONSTEVAL auto raw_typed_signature() -> std::string_view {
14+
inline consteval auto raw_typed_signature() -> std::string_view {
1515
return KANGARU5_FUNCTION_SIGNATURE;
1616
}
1717

@@ -24,7 +24,7 @@ namespace kangaru::detail::ctti {
2424

2525
// TODO: Get stable type name on all compilers
2626
template<typename T>
27-
inline KANGARU5_CONSTEVAL auto type_name_prefix_length() -> std::size_t {
27+
inline consteval auto type_name_prefix_length() -> std::size_t {
2828
using namespace std::literals;
2929
auto const sig_prefix_trimmed = raw_typed_signature<T>().substr(signature_prefix_length);
3030

@@ -40,7 +40,7 @@ namespace kangaru::detail::ctti {
4040
}
4141

4242
template<typename T>
43-
inline KANGARU5_CONSTEVAL auto type_name() -> std::string_view {
43+
inline consteval auto type_name() -> std::string_view {
4444
auto const sig_prefix_trimmed = raw_typed_signature<T>().substr(type_name_prefix_length<T>());
4545
return sig_prefix_trimmed.substr(
4646
0,
@@ -53,7 +53,7 @@ namespace kangaru::detail::ctti {
5353
struct type_id_for_result : std::integral_constant<std::size_t, detail::murmur::murmur64a(type_name<T>())> {};
5454

5555
template<typename T>
56-
inline KANGARU5_CONSTEVAL auto type_id_for() -> type_id_for_result<T> {
56+
inline consteval auto type_id_for() -> type_id_for_result<T> {
5757
return type_id_for_result<T>{};
5858
}
5959
}

include/kangaru/detail/deducer.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ namespace kangaru {
542542

543543
namespace detail::deducer {
544544
template<typename T, typename F, std::size_t... before, std::size_t... after>
545-
inline KANGARU5_CONSTEVAL auto callable_with_nth_parameter_being_expand(std::index_sequence<before...>, std::index_sequence<after...>) -> bool {
545+
inline consteval auto callable_with_nth_parameter_being_expand(std::index_sequence<before...>, std::index_sequence<after...>) -> bool {
546546
return callable<
547547
F,
548548
detail::utility::expand<placeholder_deducer, before>...,
@@ -563,7 +563,7 @@ namespace kangaru {
563563
};
564564

565565
template<typename T, typename F, std::size_t nth, std::size_t max>
566-
inline KANGARU5_CONSTEVAL auto reference_kind_for_nth_parameter() -> reference_kind {
566+
inline consteval auto reference_kind_for_nth_parameter() -> reference_kind {
567567
if constexpr (is_nth_parameter_prvalue<F, nth, max>) {
568568
return reference_kind::none;
569569
} else {

include/kangaru/detail/define.hpp

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#endif
2424

2525
#define KANGARU5_FWD(...) static_cast<decltype(__VA_ARGS__)&&>(__VA_ARGS__)
26-
#define KANGARU5_CONSTRUCTOR_T(...) decltype(::kangaru::constructor<__VA_ARGS__>())
2726
#define KANGARU5_NO_ADL(...) (__VA_ARGS__)
2827

2928
#if KANGARU5_IS_CLANG() == 1
@@ -51,22 +50,7 @@
5150
#endif
5251

5352
#if KANGARU5_IS_CLANG() == 1
54-
#if __clang_major__ < 14
55-
#define KANGARU5_CONSTEVAL_SUPPORTED() 0
56-
#else
57-
#define KANGARU5_CONSTEVAL_SUPPORTED() 1
58-
#endif
59-
#else
60-
#define KANGARU5_CONSTEVAL_SUPPORTED() 1
61-
#endif
62-
63-
#if KANGARU5_CONSTEVAL_SUPPORTED() == 1 && KANGARU5_IS_MSVC() == 1
64-
#define KANGARU5_CONSTEVAL_PLACEHOLDER_SUPPORTED() 0
65-
#else
66-
#define KANGARU5_CONSTEVAL_PLACEHOLDER_SUPPORTED() KANGARU5_CONSTEVAL_SUPPORTED()
67-
#endif
68-
69-
#if KANGARU5_IS_CLANG() == 1
53+
#define KANGARU5_CONSTEVAL_PLACEHOLDER_SUPPORTED() 1
7054
#if __clang_major__ >= 17
7155
#define KANGARU5_CONSTEXPR_VOIDSTAR_CAST_SUPPORTED() 1
7256
#else
@@ -78,6 +62,7 @@
7862
#define KANGARU5_DEDUCING_THIS_SUPPORTED() 0
7963
#endif
8064
#elif KANGARU5_IS_GNU() == 1
65+
#define KANGARU5_CONSTEVAL_PLACEHOLDER_SUPPORTED() 1
8166
#if __GNUC__ >= 14
8267
#define KANGARU5_CONSTEXPR_VOIDSTAR_CAST_SUPPORTED() 1
8368
#else
@@ -90,6 +75,7 @@
9075
#endif
9176
#elif KANGARU5_IS_MSVC() == 1
9277
#define KANGARU5_CONSTEXPR_VOIDSTAR_CAST_SUPPORTED() 0
78+
#define KANGARU5_CONSTEVAL_PLACEHOLDER_SUPPORTED() 0
9379
#if _MSC_VER >= 1943
9480
#define KANGARU5_DEDUCING_THIS_SUPPORTED() 1
9581
#else
@@ -111,12 +97,6 @@
11197
#define KANGARU5_CONSTEVAL_PLACEHOLDER constexpr
11298
#endif
11399

114-
#if KANGARU5_CONSTEVAL_SUPPORTED() == 1
115-
#define KANGARU5_CONSTEVAL consteval
116-
#else
117-
#define KANGARU5_CONSTEVAL constexpr
118-
#endif
119-
120100
#define KANGARU5_UNSAFE /* left undefined */
121101
#define KANGARU5_UNSAFE_BLOCK /* left undefined */
122102

include/kangaru/detail/lazy.hpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#ifndef KANGARU5_DETAIL_LAZY_HPP
2+
#define KANGARU5_DETAIL_LAZY_HPP
3+
4+
#include "source.hpp"
5+
#include "optional.hpp"
6+
7+
namespace kangaru {
8+
template<injectable T, source_of<T> Source>
9+
struct lazy {
10+
explicit constexpr lazy(Source source) noexcept : source{std::move(source)} {}
11+
12+
constexpr auto operator*() & -> T {
13+
ensure_initialized();
14+
return *object;
15+
}
16+
17+
constexpr auto operator*() && -> T {
18+
ensure_initialized();
19+
return *std::move(object);
20+
}
21+
22+
constexpr auto operator->() -> std::remove_reference_t<T>* {
23+
ensure_initialized();
24+
return object.operator->();
25+
}
26+
27+
template<typename U> requires std::convertible_to<U&&, T&>
28+
constexpr auto object_or(U&& default_value) const noexcept -> T& {
29+
return object.has_value() ? *object : KANGARU5_FWD(default_value);
30+
}
31+
32+
private:
33+
constexpr auto ensure_initialized() -> void {
34+
if (not object) {
35+
object.emplace(kangaru::provide<T>(source));
36+
}
37+
}
38+
39+
Source source;
40+
optional<T> object;
41+
};
42+
}
43+
44+
#endif // KANGARU5_DETAIL_LAZY_HPP

include/kangaru/detail/noreturn.hpp

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)