Skip to content

Commit f608159

Browse files
Refactored primary template enable_affordance_for
1 parent e25447c commit f608159

File tree

5 files changed

+15
-10
lines changed

5 files changed

+15
-10
lines changed

include/simply/dyn.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
namespace simply {
1414

15+
// TODO reconsider template parameters to avoid requiring user to explicitly
16+
// categorize affordances, or provide a type alias template to categorize them
17+
// and inject defaults. Rename to `basic_dyn`?
1518
template <simply::affordance Affordance,
1619
simply::storage_affordance Storage = simply::allocator_storage<>,
1720
simply::dispatch_affordance Dispatch = simply::indirect_dispatch>

include/simply/impl.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,18 @@
77

88
namespace simply {
99

10-
template <typename Affordance, typename T,
11-
typename Fn = affordance_traits<Affordance, T>::function_type>
10+
template <typename Affordance, typename T, typename Fn>
1211
struct impl {
1312
static constexpr auto fn = Affordance::template fn<T>;
1413
};
1514

1615
template <typename Affordance, typename T>
1716
inline constexpr const auto &fn = simply::impl<Affordance, T>::fn;
1817

18+
// TODO consider `bind<Affordance>(self)(rest...)` as an alternative to
19+
// `fn<Affordance, remove_cvref_t<decltype(self)>>(self, rest...)` that exposes
20+
// operator() as an overload set with non-deduced parameter types
21+
1922
template <simply::member_affordance Affordance, typename T>
2023
struct affordance_traits<Affordance, T> {
2124
using function_type = decltype(Affordance::template fn<T>);

include/simply/storage.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ struct iface<Storage, Self> {
7373
using void_pointer = traits::void_pointer;
7474
using const_void_pointer = traits::const_void_pointer;
7575

76-
// TODO use this->alloc instead of other.alloc to copy other->object_ptr
76+
// BUG use this->alloc instead of other.alloc to copy other->object_ptr
7777
constexpr iface(const iface &other)
7878
: alloc(traits::select_on_container_copy_construction(other.alloc)),
7979
object_ptr(

include/simply/type_traits.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ struct dispatch_affordance_base : simply::affordance_base {};
2727
template <typename Affordance, typename T>
2828
struct affordance_traits;
2929

30+
template <typename Affordance, typename T,
31+
typename Fn = affordance_traits<Affordance, T>::function_type>
32+
struct impl;
33+
3034
template <typename Affordance, typename Tag>
3135
struct fundamental_affordance_type {};
3236

@@ -76,10 +80,9 @@ template <typename T>
7680
inline constexpr bool enable_affordance =
7781
std::derived_from<T, simply::affordance_base>;
7882

79-
// TODO integrate this customization point with impl and/or affordance_traits
8083
template <typename Affordance, typename T>
8184
inline constexpr bool enable_affordance_for =
82-
requires { &Affordance::template fn<T>; };
85+
requires { simply::impl<Affordance, T>::fn; };
8386

8487
template <typename T, typename Tag>
8588
inline constexpr bool enable_affordance_tag = std::derived_from<T, Tag>;

tests/counters.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,8 @@ static_assert([] {
6363
: simply::composes<copy_countable<int>, labeled<char>,
6464
simply::copy_constructible, simply::destructible> {};
6565

66-
using dyn = simply::dyn<countable>;
67-
static_assert(requires {
68-
typename simply::affordance_traits<copy_countable<int>, dyn>::function_type;
69-
});
7066
// initialize a vector of dyn<countable> with three different counter types
71-
std::vector<dyn> v;
67+
std::vector<simply::dyn<countable>> v;
7268
v.emplace_back(std::in_place_type<counter<'A'>>);
7369
v.emplace_back(std::in_place_type<counter<'B'>>);
7470
v.emplace_back(std::in_place_type<counter<'C'>>);

0 commit comments

Comments
 (0)