Skip to content

Commit

Permalink
* Change the way mbo::types::Extend types are constructed to suppor…
Browse files Browse the repository at this point in the history
…t more complex and deeper nested types.
  • Loading branch information
helly25 committed Mar 24, 2024
1 parent 1094eec commit 33ff77a
Show file tree
Hide file tree
Showing 4 changed files with 13 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 kExtenderName = 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
12 changes: 5 additions & 7 deletions mbo/types/internal/extend.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,12 @@ 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::kExtenderName;
std::convertible_to<decltype(MaybeExtender::kExtenderName), std::string_view>;
};

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

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

Expand Down

0 comments on commit 33ff77a

Please sign in to comment.