Skip to content

Commit

Permalink
Forward-declare best::span (#28)
Browse files Browse the repository at this point in the history
With a little bit of cleverness, we can add `best::span` to the `fwd.h`
header.

The primary obstacle was that it has a `best::option<size_t>` template
parameter, which is not defined until way later. However, by making that
`size_t` dependent on the first template parameter, we eliminate this
problem by forcing two-phase lookup.
  • Loading branch information
mcy authored Jul 22, 2024
1 parent b0a4e42 commit 8d4180b
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 69 deletions.
12 changes: 7 additions & 5 deletions best/base/fwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include "best/base/tags.h"
#include "best/meta/taxonomy.h"
#include "best/meta/traits.h"

//! Forward declarations of all types in best that can be forward-declared.
//!
Expand Down Expand Up @@ -113,12 +114,13 @@ class vtable;
template <typename>
class vptr;

// best::span cannot be forward-declared because that depends on
// best::option<size_t> being defined.
//
// best/memory/span.h
// template <typename, best::option<size_t>>
// class span;
// To actually forward-declare this, we can't utter best::option<size_t> here
// because it's not defined yet. However, if it's a dependent type, we can delay
// it to the second phase of two-phase lookup.
template <best::is_object T, best::option<best::dependent<size_t, T>> =
best::option<best::dependent<size_t, T>>{}>
class span;

// best/meta/empty.h
struct empty;
Expand Down
5 changes: 0 additions & 5 deletions best/container/option.h
Original file line number Diff line number Diff line change
Expand Up @@ -847,11 +847,6 @@ option(best::bind_t, T&&) -> option<T&&>;
option(best::none_t) -> option<void>;

inline constexpr best::option<void> VoidOption{best::in_place};

// Forward declare span as soon as possible.
template <best::is_object, best::option<size_t> = best::none>
class span;

} // namespace best

/* ////////////////////////////////////////////////////////////////////////// *\
Expand Down
Loading

0 comments on commit 8d4180b

Please sign in to comment.