Skip to content

Commit

Permalink
Reduce hana in the interface
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-sparus committed Jun 13, 2024
1 parent d822e87 commit 834d802
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 34 deletions.
7 changes: 3 additions & 4 deletions immer/extra/persist/json/policy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ struct hana_struct_auto_policy
template <class T>
auto get_pool_types(const T& value) const
{
return get_pools_for_type(boost::hana::typeid_(value));
return get_pools_for_type<T>();
}
};

Expand All @@ -127,14 +127,13 @@ struct hana_struct_auto_member_name_policy
template <class T>
auto get_pool_types(const T& value) const
{
return get_pools_for_type(boost::hana::typeid_(value));
return get_pools_for_type<T>();
}

template <class T>
auto get_pool_name_fn(const T& value) const
{
using map_t =
decltype(get_named_pools_for_type(boost::hana::typeid_(value)));
using map_t = decltype(get_named_pools_for_type<T>());
return name_from_map_fn<map_t>{};
}
};
Expand Down
22 changes: 12 additions & 10 deletions immer/extra/persist/json/wrap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,15 @@ constexpr auto wrap_for_loading = exclude_internal_pool_types(
* Generate a hana set of types of persistable members for the given type,
* recursively. Example: [type_c<immer::map<K, V>>]
*/
auto get_pools_for_type(auto type)
template <class T>
auto get_pools_for_type()
{
namespace hana = boost::hana;
auto all_types_set = util::get_inner_types(type);
auto all_types_set = util::get_inner_types(hana::type_c<T>);
auto persistable =
hana::filter(hana::to_tuple(all_types_set), [&](auto type) {
using T = typename decltype(type)::type;
return is_persistable(T{});
hana::filter(hana::to_tuple(all_types_set), [](auto type) {
using Type = typename decltype(type)::type;
return is_persistable(Type{});
});
return hana::to_set(persistable);
}
Expand All @@ -132,14 +133,15 @@ auto get_pools_for_type(auto type)
* Example:
* [(type_c<immer::map<K, V>>, "tracks")]
*/
auto get_named_pools_for_type(auto type)
template <class T>
auto get_named_pools_for_type()
{
namespace hana = boost::hana;
auto all_types_map = util::get_inner_types_map(type);
auto all_types_map = util::get_inner_types_map(hana::type_c<T>);
auto persistable =
hana::filter(hana::to_tuple(all_types_map), [&](auto pair) {
using T = typename decltype(+hana::first(pair))::type;
return is_persistable(T{});
hana::filter(hana::to_tuple(all_types_map), [](auto pair) {
using Type = typename decltype(+hana::first(pair))::type;
return is_persistable(Type{});
});
return hana::to_map(persistable);
}
Expand Down
12 changes: 6 additions & 6 deletions test/extra/persist/test_circular_dependency_conversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ TEST_CASE("Test exception while circular converting")
};
}();

const auto names = immer::persist::get_named_pools_for_type(
hana::type_c<model::value_one>);
const auto names =
immer::persist::get_named_pools_for_type<model::value_one>();
const auto model_pool = immer::persist::get_auto_pool(value);

SECTION("Try to load")
Expand Down Expand Up @@ -408,8 +408,8 @@ TEST_CASE("Test circular dependency pools", "[conversion]")
};
}();

const auto names = immer::persist::get_named_pools_for_type(
hana::type_c<model::value_one>);
const auto names =
immer::persist::get_named_pools_for_type<model::value_one>();
const auto model_pools = immer::persist::get_auto_pool(value);

/**
Expand Down Expand Up @@ -517,8 +517,8 @@ TEST_CASE("Test circular dependency pools", "[conversion]")
(void) format_load_pools;
// show_type<decltype(format_load_pools)> qwe;

const auto format_names = immer::persist::get_named_pools_for_type(
hana::type_c<format::value_one>);
const auto format_names =
immer::persist::get_named_pools_for_type<format::value_one>();

SECTION("vector")
{
Expand Down
4 changes: 2 additions & 2 deletions test/extra/persist/test_conversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ TEST_CASE("Convert between two hierarchies via JSON compatibility",
"[conversion]")
{
const auto model_names =
immer::persist::get_named_pools_for_type(hana::type_c<model::history>);
immer::persist::get_named_pools_for_type<model::history>();
const auto format_names =
immer::persist::get_named_pools_for_type(hana::type_c<format::history>);
immer::persist::get_named_pools_for_type<format::history>();
(void) format_names;

const auto value = model::make_example_history();
Expand Down
23 changes: 11 additions & 12 deletions test/extra/persist/test_special_pool_auto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ TEST_CASE("Auto-persisting")
{
constexpr auto names = [] {
return hana::union_(
immer::persist::get_named_pools_for_type(
hana::type_c<test_data_with_immer>),
immer::persist::get_named_pools_for_type<test_data_with_immer>(),
hana::make_map(hana::make_pair(hana::type_c<vector_one<meta_meta>>,
BOOST_HANA_STRING("meta_meta"))));
};
Expand Down Expand Up @@ -237,8 +236,8 @@ TEST_CASE("Test save and load small type")
const auto value = test_data_with_one_immer_member{
.ints = ints1,
};
const auto pool_types =
immer::persist::get_named_pools_for_type(boost::hana::typeid_(value));
const auto pool_types = immer::persist::get_named_pools_for_type<
test_data_with_one_immer_member>();
const auto json_str =
immer::persist::to_json_with_auto_pool(value, pool_types);
// REQUIRE(json_str == "");
Expand Down Expand Up @@ -439,8 +438,8 @@ TEST_CASE("Test table with a funny value")
.twos_table = t1.insert(two2),
};

const auto names = immer::persist::get_named_pools_for_type(
hana::type_c<champ_test::value_one>);
const auto names =
immer::persist::get_named_pools_for_type<champ_test::value_one>();
const auto json_str = immer::persist::to_json_with_auto_pool(value, names);
// REQUIRE(json_str == "");

Expand Down Expand Up @@ -479,8 +478,8 @@ TEST_CASE("Test loading broken table")
.twos_table = t1.insert(two2),
};

const auto names = immer::persist::get_named_pools_for_type(
hana::type_c<champ_test::value_one>);
const auto names =
immer::persist::get_named_pools_for_type<champ_test::value_one>();

const auto json_str = immer::persist::to_json_with_auto_pool(value, names);
// REQUIRE(json_str == "");
Expand Down Expand Up @@ -942,8 +941,8 @@ struct with_variant

TEST_CASE("Test types traversal")
{
auto names = immer::persist::get_named_pools_for_type(
hana::type_c<test_variant::with_variant>);
auto names =
immer::persist::get_named_pools_for_type<test_variant::with_variant>();
SECTION("It goes inside variant")
{
using contains_t = decltype(names[hana::type_c<immer::vector<int>>] ==
Expand All @@ -965,8 +964,8 @@ TEST_CASE("Test types traversal")
hana::false_c)::value);

// But it has the vector when we don't use names
auto only_types = immer::persist::get_pools_for_type(
hana::type_c<test_variant::with_variant>);
auto only_types =
immer::persist::get_pools_for_type<test_variant::with_variant>();
static_assert(decltype(hana::contains(only_types, vector_type))::value);
}
}

0 comments on commit 834d802

Please sign in to comment.