From f91b6003e25d4ab35aa45f94cb979f3fd6b2ac9d Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Tue, 10 Jul 2018 17:53:20 +0200 Subject: [PATCH] simplify call on nth element of tuple --- alib2std/src/extensions/ptr_tuple.hpp | 16 ++++++++-------- alib2std/src/extensions/tuple.hpp | 18 +++++++++--------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/alib2std/src/extensions/ptr_tuple.hpp b/alib2std/src/extensions/ptr_tuple.hpp index 4bb5efa885..0260455c1e 100644 --- a/alib2std/src/extensions/ptr_tuple.hpp +++ b/alib2std/src/extensions/ptr_tuple.hpp @@ -505,20 +505,20 @@ struct tuple_element < I, ext::ptr_tuple < Types... > > { typedef typename std::tuple_element < I, std::tuple < Types ... > >::type type; }; -template < class Result, unsigned I, class Callable, class ... Types > -struct call_on_nth_helper < Result, I, ext::ptr_tuple < Types ... >, Callable > { - template < class Tuple > +template < class Result, unsigned I, class ... Types > +struct call_on_nth_helper < Result, I, ext::ptr_tuple < Types ... > > { + template < class Tuple, class Callable > static Result call_on_nth_fn ( Tuple && t, unsigned index, Callable callback ) { if ( index == 0 ) - return callback ( std::get < ext::tuple_size < Tuple >::value - I > ( std::forward < ext::ptr_tuple < Types ... > > ( t ) ) ); + return callback ( std::get < ext::tuple_size < Tuple >::value - I > ( std::forward < Tuple && > ( t ) ) ); else - return call_on_nth_helper < Result, I - 1, ext::ptr_tuple < Types ... >, Callable >::call_on_nth_fn ( std::forward < Tuple && > ( t ), index - 1, callback ); + return call_on_nth_helper < Result, I - 1, ext::ptr_tuple < Types ... > >::call_on_nth_fn ( std::forward < Tuple && > ( t ), index - 1, callback ); } }; -template < class Result, class Callable, class ... Types > -struct call_on_nth_helper < Result, 0, ext::ptr_tuple < Types ... >, Callable > { - template < class Tuple > +template < class Result, class ... Types > +struct call_on_nth_helper < Result, 0, ext::ptr_tuple < Types ... > > { + template < class Tuple, class Callable > static Result call_on_nth_fn ( Tuple &&, unsigned, Callable ) { throw std::out_of_range ( "Not enough elements in tuple." ); } diff --git a/alib2std/src/extensions/tuple.hpp b/alib2std/src/extensions/tuple.hpp index 1e30ced360..77d8fca141 100644 --- a/alib2std/src/extensions/tuple.hpp +++ b/alib2std/src/extensions/tuple.hpp @@ -91,23 +91,23 @@ struct tuple_element < I, const volatile T > { typedef typename std::add_cv < typename ext::tuple_element < I, T >::type >::type type; }; -template < class Result, unsigned I, class Tuple, class Callable > +template < class Result, unsigned I, class Tuple > struct call_on_nth_helper; -template < class Result, unsigned I, class Callable, class ... Types > -struct call_on_nth_helper < Result, I, ext::tuple < Types ... >, Callable > { - template < class Tuple > +template < class Result, unsigned I, class ... Types > +struct call_on_nth_helper < Result, I, ext::tuple < Types ... > > { + template < class Tuple, class Callable > static Result call_on_nth_fn ( Tuple && t, unsigned index, Callable callback ) { if ( index == 0 ) return callback ( std::get < ext::tuple_size < Tuple >::value - I > ( std::forward < Tuple && > ( t ) ) ); else - return call_on_nth_helper < Result, I - 1, ext::tuple < Types ... >, Callable >::call_on_nth_fn ( std::forward < Tuple && > ( t ), index - 1, callback ); + return call_on_nth_helper < Result, I - 1, ext::tuple < Types ... > >::call_on_nth_fn ( std::forward < Tuple && > ( t ), index - 1, callback ); } }; -template < class Result, class Callable, class ... Types > -struct call_on_nth_helper < Result, 0, ext::tuple < Types ... >, Callable > { - template < class Tuple > +template < class Result, class ... Types > +struct call_on_nth_helper < Result, 0, ext::tuple < Types ... > > { + template < class Tuple, class Callable > static Result call_on_nth_fn ( Tuple &&, unsigned, Callable ) { throw std::out_of_range ( "Not enough elements in tuple." ); } @@ -115,7 +115,7 @@ struct call_on_nth_helper < Result, 0, ext::tuple < Types ... >, Callable > { template < class Result, class Tuple, class Callable > Result call_on_nth ( Tuple && t, unsigned index, Callable callback ) { - return call_on_nth_helper < Result, ext::tuple_size < Tuple >::value, typename std::decay < Tuple >::type, Callable >::call_on_nth_fn ( std::forward < Tuple && > ( t ), index, callback ); + return call_on_nth_helper < Result, ext::tuple_size < Tuple >::value, typename std::decay < Tuple >::type >::call_on_nth_fn ( std::forward < Tuple && > ( t ), index, callback ); } -- GitLab