Skip to content

Commit 59c1124

Browse files
committed
Rename Fn to FnRef, FnMut to FnMutRef and FnOnce to FnOnceRef
These are concrete impls of what will be the Fn/FnMut/FnOnce concepts that are a light reference around the thing they call while erasing its type to avoid requiring a template to receive and use a callable thing in a function (that doesn't store the callable). They are however not constexpr due to language limitations so in constexpr vocab types, the concepts will need to be used directly.
1 parent b8b8f79 commit 59c1124

File tree

11 files changed

+873
-863
lines changed

11 files changed

+873
-863
lines changed

subdoc/lib/database.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ struct FunctionElement : public CommentElement {
146146
return sus::none();
147147
}
148148

149-
void for_each_comment(sus::fn::FnMut<void(Comment&)> fn) { fn(comment); }
149+
void for_each_comment(sus::fn::FnMutRef<void(Comment&)> fn) { fn(comment); }
150150
};
151151

152152
struct FieldElement : public CommentElement {
@@ -187,7 +187,7 @@ struct FieldElement : public CommentElement {
187187
return sus::none();
188188
}
189189

190-
void for_each_comment(sus::fn::FnMut<void(Comment&)> fn) { fn(comment); }
190+
void for_each_comment(sus::fn::FnMutRef<void(Comment&)> fn) { fn(comment); }
191191
};
192192

193193
struct NamespaceId {
@@ -324,7 +324,7 @@ struct RecordElement : public TypeElement {
324324
return out;
325325
}
326326

327-
void for_each_comment(sus::fn::FnMut<void(Comment&)> fn) {
327+
void for_each_comment(sus::fn::FnMutRef<void(Comment&)> fn) {
328328
fn(comment);
329329
for (auto& [k, e] : records) e.for_each_comment(fn);
330330
for (auto& [k, e] : fields) e.for_each_comment(fn);
@@ -427,7 +427,7 @@ struct NamespaceElement : public CommentElement {
427427
return out;
428428
}
429429

430-
void for_each_comment(sus::fn::FnMut<void(Comment&)> fn) {
430+
void for_each_comment(sus::fn::FnMutRef<void(Comment&)> fn) {
431431
fn(comment);
432432
for (auto& [k, e] : namespaces) e.for_each_comment(fn);
433433
for (auto& [k, e] : records) e.for_each_comment(fn);

subspace/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ target_sources(subspace PUBLIC
5151
"fn/bind.h"
5252
"fn/fn_box_defn.h"
5353
"fn/fn_box_impl.h"
54-
"fn/fn_defn.h"
54+
"fn/fn_ref.h"
5555
"iter/__private/into_iterator_archetype.h"
5656
"iter/__private/iterator_end.h"
5757
"iter/__private/iterator_loop.h"
@@ -153,7 +153,7 @@ add_executable(subspace_unittests
153153
"construct/into_unittest.cc"
154154
"construct/default_unittest.cc"
155155
"fn/fn_box_unittest.cc"
156-
"fn/fn_unittest.cc"
156+
"fn/fn_ref_unittest.cc"
157157
"iter/iterator_unittest.cc"
158158
"mem/addressof_unittest.cc"
159159
"mem/clone_unittest.cc"

subspace/fn/bind.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include "subspace/mem/move.h"
2828

2929
/// Bind a const lambda to storage for its bound arguments. The output can be
30-
/// used to construct a FnOnce, FnMut, or Fn.
30+
/// used to construct a FnOnceBox, FnMutBox, or FnBox.
3131
///
3232
/// The first argument is a list of variables that will be bound into storage
3333
/// for access from the lambda, wrapped in sus_store(). If there are no
@@ -79,8 +79,8 @@
7979
}()
8080

8181
/// A variant of `sus_bind()` which only takes a lambda, omitting the
82-
/// `sus_store()` list. The output can be used to construct a FnOnce, FnMut, or
83-
/// Fn.
82+
/// `sus_store()` list. The output can be used to construct a FnOnceBox,
83+
/// FnMutBox, or FnBox.
8484
///
8585
/// Because there is no `sus_store()` list, the lambda can not capture variables
8686
/// from the outside scope, however it can still declare captures contained
@@ -89,15 +89,15 @@
8989
/// # Example
9090
///
9191
/// This defines a lambda with a capture `a` of type `int`, and binds it so it
92-
/// can be used to construct a FnOnce, FnMut, or Fn.
92+
/// can be used to construct a FnOnceBox, FnMutBox, or FnBox.
9393
/// ```
9494
/// sus_bind0([a = int(1)](char, int){})
9595
/// ```
9696
#define sus_bind0(lambda, ...) \
9797
sus_bind(sus_store(), lambda __VA_OPT__(, ) __VA_ARGS__)
9898

9999
/// Bind a mutable lambda to storage for its bound arguments. The output can be
100-
/// used to construct a FnOnce or FnMut.
100+
/// used to construct a FnOnceBox or FnMutBox.
101101
///
102102
/// Because the storage is mutable, the lambda may capture references to the
103103
/// storage and mutate it, and the lambda itself may be marked mutable.
@@ -144,7 +144,8 @@
144144
}()
145145

146146
/// A variant of `sus_bind_mut()` which only takes a lambda, omitting the
147-
/// `sus_store()` list. The output can be used to construct a FnOnce or FnMut.
147+
/// `sus_store()` list. The output can be used to construct a FnOnceBox or
148+
/// FnMutBox.
148149
///
149150
/// Because there is no `sus_store()` list, the lambda can not capture variables
150151
/// from the outside scope, however it can still declare captures contained
@@ -155,7 +156,7 @@
155156
/// # Example
156157
///
157158
/// This defines a lambda with a capture `a` of type `int`, and binds it so it
158-
/// can be used to construct a FnOnce, FnMut, or Fn.
159+
/// can be used to construct a FnOnceBox, FnMutBox, or FnBox.
159160
/// ```
160161
/// sus_bind0_mut([a = int(1)](char, int){})
161162
/// ```

subspace/fn/fn.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
#include "subspace/fn/bind.h"
1818
#include "subspace/fn/fn_box_defn.h"
1919
#include "subspace/fn/fn_box_impl.h"
20-
#include "subspace/fn/fn_defn.h"
20+
#include "subspace/fn/fn_ref.h"

0 commit comments

Comments
 (0)