mirror of
https://github.com/CHN-beta/nixos.git
synced 2026-01-12 04:39:23 +08:00
packages.biu: fix
This commit is contained in:
@@ -117,9 +117,11 @@ namespace biu
|
||||
template <typename T> T& operator|(T&& obj, const ToLvalueHelper&);
|
||||
}
|
||||
constexpr detail_::ToLvalueHelper toLvalue;
|
||||
|
||||
template <typename Function, typename T, typename... Ts> void for_each(Function&& function, T&& arg, Ts&&... args);
|
||||
}
|
||||
using common::hash, common::unused, common::block_forever, common::is_interactive, common::env, common::int128_t,
|
||||
common::uint128_t, common::Empty, common::CaseInsensitiveStringLessComparator, common::RemoveMemberPointer,
|
||||
common::MoveQualifiers, common::FallbackIfNoTypeDeclared, common::exec, common::sequence, common::read,
|
||||
common::toLvalue;
|
||||
common::toLvalue, common::for_each;
|
||||
}
|
||||
|
||||
@@ -46,4 +46,31 @@ namespace biu::common
|
||||
return sequence(from, to);
|
||||
}
|
||||
template <typename T> T& detail_::operator|(T&& obj, const ToLvalueHelper&) { return static_cast<T&>(obj); }
|
||||
|
||||
template <typename Function, typename T, typename... Ts> void for_each(Function&& function, T&& arg, Ts&&... args)
|
||||
{
|
||||
if constexpr (sizeof...(Ts) == 0)
|
||||
{
|
||||
[&]<std::size_t... Is>(std::index_sequence<Is...>)
|
||||
{ (std::forward<Function>(function)(std::get<Is>(std::forward<T>(arg))) , ...); }
|
||||
(std::make_index_sequence<sizeof...(Ts)>{});
|
||||
}
|
||||
else
|
||||
{
|
||||
[&]<typename Tuple, std::size_t... Is>(std::index_sequence<Is...>, Tuple&& tuple)
|
||||
{
|
||||
([&]<std::size_t I, std::size_t... Js>(std::index_sequence<Js...>) -> decltype(auto)
|
||||
{
|
||||
std::apply
|
||||
(
|
||||
std::forward<Function>(function),
|
||||
std::forward_as_tuple(std::get<I>(std::get<Js>(std::forward<Tuple>(tuple)))...));
|
||||
}.template operator()<Is>(std::make_index_sequence<std::tuple_size_v<Tuple>>{}), ...);
|
||||
}
|
||||
(
|
||||
std::make_index_sequence<std::tuple_size_v<T>>{},
|
||||
std::forward_as_tuple(std::forward<T>(arg), std::forward<Ts>(args)...)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,4 +10,22 @@ int main()
|
||||
| biu::toLvalue
|
||||
| ranges::views::transform([](int i){ return i + 1; })
|
||||
| ranges::to_vector;
|
||||
|
||||
struct test_struct
|
||||
{
|
||||
int a = 1;
|
||||
double b = 2;
|
||||
std::string c = "3";
|
||||
} c;
|
||||
biu::for_each([&](auto&& i){ std::cout << c.*i << '\n'; },
|
||||
std::tuple(&test_struct::a, &test_struct::b, &test_struct::c));
|
||||
struct test_struct2
|
||||
{
|
||||
int a = 4;
|
||||
double b = 5;
|
||||
std::string c = "6";
|
||||
} d;
|
||||
biu::for_each([&](auto&& i, auto&& j){ c.*i = d.*j; },
|
||||
std::tuple(&test_struct::a, &test_struct::b, &test_struct::c),
|
||||
std::tuple(&test_struct2::a, &test_struct2::b, &test_struct2::c));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user