Skip to content

Commit

Permalink
Change the way mbo::types::Extend types are constructed to support …
Browse files Browse the repository at this point in the history
…more complex and deeper nested types. (#18)

* * Change the way `mbo::types::Extend` types are constructed to support more complex and deeper nested types.

* Use static constexpr function rather than member field.
  • Loading branch information
helly25 authored Mar 24, 2024
1 parent 1094eec commit 1f2dbde
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.2.22

* Change the way `mbo::types::Extend` types are constructed to support more complex and deeper nested types.

# 0.2.21

* Optimize `AnyScan`, `ConstScan` and `ConvertingScan` by dropping clone layer. We also explicitly support multiple iterations on one object.
Expand Down
3 changes: 2 additions & 1 deletion mbo/types/extend_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,8 @@ TEST_F(ExtendTest, StreamableComplexFields) {
EXPECT_THAT(
out.str(),
Conditional(
kStructNameSupport, R"({25, {.name: {.first: "Hugo", .last: "Meyer"}, .age: 42}, *{{"bar", "foo"}}})",
kStructNameSupport,
R"({.index: 25, .person: {.name: {.first: "Hugo", .last: "Meyer"}, .age: 42}, .data: *{{"bar", "foo"}}})",
R"({25, {{"Hugo", "Meyer"}, 42}, *{{"bar", "foo"}}})"));
#ifdef __clang__
if (HasFailure()) {
Expand Down
3 changes: 2 additions & 1 deletion mbo/types/extender.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,10 @@ namespace mbo::types::extender {
// ```
template<tstring ExtenderNameT, template<typename> typename ImplT, typename RequiredExtenderT = void>
struct MakeExtender {
using ExtenderName = decltype(ExtenderNameT);
using RequiredExtender = RequiredExtenderT;

static constexpr std::string_view GetExtenderName() { return decltype(ExtenderNameT)::str(); }

private:
// This friend is necessary to keep symbol visibility in check. But it has to
// be either 'struct' or 'class' and thus results in `ImplT` being a struct.
Expand Down
11 changes: 4 additions & 7 deletions mbo/types/internal/extend.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,11 @@ namespace mbo::types::extender_internal {

struct NoRequirement {};

// Identify `Extender` classes by the fact that they have a type `ExtenderName`
// that can be converted into a `std::string_view`.
// Identify `Extender` classes by the fact that they have a member named
// `kExtenderName` that can be converted into a `std::string_view`.
template<typename MaybeExtender>
concept IsExtender = requires {
typename MaybeExtender::ExtenderName;
//{
// typename MaybeExtender::ExtenderName()
// } -> std::convertible_to<std::string_view>;
{ MaybeExtender::GetExtenderName() } -> std::convertible_to<std::string_view>;
};

template<typename T, typename... Ts>
Expand Down Expand Up @@ -136,7 +133,7 @@ struct ExtendImpl
using RegisteredExtenders = std::tuple<Extender...>;

static constexpr std::array<std::string_view, sizeof...(Extender)> RegisteredExtenderNames() {
return {Extender::ExtenderName::str()...};
return {Extender::GetExtenderName()...};
}
};

Expand Down

0 comments on commit 1f2dbde

Please sign in to comment.