Any++
Loading...
Searching...
No Matches
anyxx_range.hpp
1#pragma once
2
4
5namespace anyxx {
6
8 ((Base)), incrementable, Base, (),
9 (ANY_OP(anyxx::self &, ++, (), ),
10 ANY_FN_DEF(public, anyxx::self, post_inc, (), , ([&x]() { return x++; }))),
11 , , (template <typename Self> auto operator++(this Self &&self, int) {
12 return std::forward<Self>(self).post_inc();
13 }))
14
15// target for 0.9.1: this works!
16// ANY_TEMPLATE_EX_(((ValueType), (Reference)), forward_iterator,
17// incrementable<anyxx::base_trait>, (),
18// (ANY_OP(Reference, *, (), const),
19// ANY_OP_DEF(bool, ==, equal_to, (anyxx::self const &),
20// const,
21// ([&x](auto const &r) { return x == r; })),
22// ANY_OP_DEF(bool, !=, not_equal_to, (anyxx::self const &),
23// const, ([&x](auto const &r) { return x != r;
24// }))),
25// anyxx::val,
26// (using iterator_category = std::forward_iterator_tag;
27// using difference_type = std::ptrdiff_t;
28// using value_type = ValueType; using reference =
29// Reference;))
30
31ANY_TEMPLATE_EX(
32 ((ValueType), (Reference)), forward_iterator,
33 (ANY_OP(anyxx::self &, ++, (), ),
34 ANY_FN_DEF(public, anyxx::self, post_inc, (), , ([&x]() { return x++; })),
35 ANY_OP(Reference, *, (), const),
36 ANY_OP_DEF(public, bool, ==, equal_to, (anyxx::self const &), const,
37 ([&x](auto const &r) { return x == r; })),
38 ANY_OP_DEF(public, bool, !=, not_equal_to, (anyxx::self const &), const,
39 ([&x](auto const &r) { return x != r; }))),
40 anyxx::val, , ,
41 (using iterator_category = std::forward_iterator_tag;
42 using difference_type = std::ptrdiff_t; using value_type = ValueType;
43 using reference = Reference;
44 template <typename Self> auto operator++(this Self &&self, int) {
45 return std::forward<Self>(self).post_inc();
46 }))
47
49 ((ValueType), (Reference)), forward_range,
50 (ANY_FN((any_forward_iterator<ValueType, Reference>), begin, (), const),
51 ANY_FN((any_forward_iterator<ValueType, Reference>), end, (), const)))
52
53template <typename ValueType, typename Reference, typename Box = anyxx::cref>
54using any_forward_range = any<Box, forward_range<ValueType, Reference>>;
55
56template <typename A>
57concept is_any_self_forward_range =
58 is_any<A> && std::ranges::forward_range<A> &&
59 std::same_as<std::ranges::range_value_t<A>, self>;
60//
61
62template <typename AnyForwardRange>
63 requires is_any_self_forward_range<AnyForwardRange>
64struct translate_sig_model_map<AnyForwardRange const &>
65 : translate_sig_default_model_map<self> {
66 template <typename AnyValue>
67 using v_table_param =
68 any_forward_range<AnyValue, AnyValue,
69 typename AnyForwardRange::proxy_t> const &;
70 template <typename Model>
71 using concept_arg = anyxx::any_forward_range<Model, Model, anyxx::cref>;
72};
73
74template <typename Concrete, typename AnyForwardRange>
75 requires is_any_self_forward_range<AnyForwardRange>
76struct v_table_to_map<Concrete, AnyForwardRange const &> {
77 static auto forward(auto const &any_range) {
78 return std::views::transform(any_range, [](auto const &any) {
79 return *unerase_cast<Concrete>(any);
80 });
81 }
82};
83//
84template <typename Traited, typename AnyForwardRange>
85 requires is_any_self_forward_range<AnyForwardRange>
86struct forward_trait_to_map<Traited, AnyForwardRange const &> {
87 static auto forward(auto any_range) {
88 return std::views::transform(any_range,
89 []<typename T>(T const &any) -> Traited {
90 if constexpr (is_any<T>) {
91 if constexpr (T::dyn) {
92 return *unerase_cast<Traited>(any);
93 } else {
94 return get_proxy_value(any);
95 }
96 } else {
97 return any;
98 }
99 });
100 }
101};
102
103} // namespace anyxx
C++ header only library for external polymorphism.
The core class template to control dispatch for external polymorphism.
Definition anyxx.hpp:2806
#define ANY_OP(ret, op, params, const_)
TRAIT operator with default behavior is to call the related operator of the model.
Definition anyxx.hpp:1059
#define ANY_FN(ret, name, params, const_)
TRAIT function whose default behavior is to call an equally named member function of the model.
Definition anyxx.hpp:1019
#define ANY_OP_DEF(access, ret, op, name, params, const_,...)
TRAIT operator with default behavior.
Definition anyxx.hpp:1066
observer< const_void > cref
Definition anyxx.hpp:1863
#define TRAIT_TEMPLATE_EX_(t, n, base, base_template_types, l, static_fns, typedefs, decoration)
TRAIT template with base and decoration.
Definition anyxx.hpp:790
#define TRAIT_TEMPLATE(t, n, l)
TRAIT template.
Definition anyxx.hpp:819
#define ANY_FN_DEF(access, ret, name, params, const_,...)
TRAIT function with default behavior.
Definition anyxx.hpp:998