Commit a54b52eb authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

nested_for_each(): Keep pointers instead of copies

parent b9d9bd3b
...@@ -67,7 +67,7 @@ struct stop_iteration: public std::exception {}; ...@@ -67,7 +67,7 @@ struct stop_iteration: public std::exception {};
template <class Action, std::size_t N> template <class Action, std::size_t N>
struct all_any_cast struct all_any_cast
{ {
all_any_cast(Action a, std::array<any, N>& args) all_any_cast(Action a, std::array<any*, N>& args)
: _a(a), _args(args) {} : _a(a), _args(args) {}
template <class... Ts> template <class... Ts>
...@@ -96,14 +96,14 @@ struct all_any_cast ...@@ -96,14 +96,14 @@ struct all_any_cast
{ {
try try
{ {
_a(try_any_cast<Ts>(_args[Idx])...); _a(try_any_cast<Ts>(*_args[Idx])...);
throw stop_iteration(); throw stop_iteration();
} }
catch (bad_any_cast) {} catch (bad_any_cast) {}
} }
Action _a; Action _a;
std::array<any, N>& _args; std::array<any*, N>& _args;
}; };
// recursion-free variadic version of for_each // recursion-free variadic version of for_each
...@@ -174,9 +174,9 @@ struct inner_loop<Action, std::tuple<Ts...>, TR1, TRS...> ...@@ -174,9 +174,9 @@ struct inner_loop<Action, std::tuple<Ts...>, TR1, TRS...>
// final function // final function
template <class TR1, class... TRS, class Action, class... Args> template <class TR1, class... TRS, class Action, class... Args>
bool nested_for_each(Action a, Args... args) bool nested_for_each(Action a, Args&&... args)
{ {
std::array<any, sizeof...(args)> as{{args...}}; std::array<any*, sizeof...(args)> as{{&args...}};
auto b = all_any_cast<Action, sizeof...(args)>(a, as); auto b = all_any_cast<Action, sizeof...(args)>(a, as);
try try
{ {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment