Skip to content
Snippets Groups Projects
Commit aba23ae8 authored by Dmitri Naumov's avatar Dmitri Naumov
Browse files

Use std::integer_sequence replacing own impl.

The integer_sequence is available since c++14.
parent df19e77f
No related branches found
No related tags found
No related merge requests found
...@@ -100,7 +100,7 @@ template <int... Indices, typename Object, typename MethodClass, ...@@ -100,7 +100,7 @@ template <int... Indices, typename Object, typename MethodClass,
typename ReturnType, typename... Args> typename ReturnType, typename... Args>
std::function<ReturnType(Args...)> easyBind_inner( std::function<ReturnType(Args...)> easyBind_inner(
ReturnType (MethodClass::*method)(Args...), Object&& obj, ReturnType (MethodClass::*method)(Args...), Object&& obj,
IntegerSequence<Indices...>) std::integer_sequence<int, Indices...>)
{ {
return easyBind_innermost<Indices...>(method, std::forward<Object>(obj)); return easyBind_innermost<Indices...>(method, std::forward<Object>(obj));
} }
...@@ -109,7 +109,7 @@ template <int... Indices, typename Object, typename MethodClass, ...@@ -109,7 +109,7 @@ template <int... Indices, typename Object, typename MethodClass,
typename ReturnType, typename... Args> typename ReturnType, typename... Args>
std::function<ReturnType(Args...)> easyBind_inner( std::function<ReturnType(Args...)> easyBind_inner(
ReturnType (MethodClass::*method)(Args...) const, Object&& obj, ReturnType (MethodClass::*method)(Args...) const, Object&& obj,
IntegerSequence<Indices...>) std::integer_sequence<int, Indices...>)
{ {
return easyBind_innermost<Indices...>(method, std::forward<Object>(obj)); return easyBind_innermost<Indices...>(method, std::forward<Object>(obj));
} }
...@@ -138,35 +138,6 @@ struct FunctionTraits<ReturnType (Object::*)(Args...) const> { ...@@ -138,35 +138,6 @@ struct FunctionTraits<ReturnType (Object::*)(Args...) const> {
} // namespace detail } // namespace detail
//! Has sequence of integers as template parameters
template <int...>
struct IntegerSequence {
};
//! Generates an IntegerSequence.
//!
//! \see http://stackoverflow.com/a/7858971
template <int N, int... S>
struct GenerateIntegerSequence {
// effectively pushes N-1 from the left to the list int... S of integers.
using type = typename GenerateIntegerSequence<N - 1, N - 1, S...>::type;
};
template <int... S>
struct GenerateIntegerSequence<0, S...> {
using type = IntegerSequence<S...>;
};
/* The template metaprogram proceeds in the following way:
*
* GenerateIntegerSequence<sizeof...(Args)>::type
*
* Assume sizeof...(Args) == 3. Let GIS := GenerateIntegerSequence
* GIS<3, []>
* -> GIS<2, [2]>
* -> GIS<1, [1, 2]>
* -> GIS<0, [0, 1, 2], which has member typedef IntegerSequence<0, 1, 2>
*/
/*! Convenience wrapper for std::bind(). /*! Convenience wrapper for std::bind().
* *
* This function binds the member function pointer \c member of class \c Object * This function binds the member function pointer \c member of class \c Object
...@@ -210,7 +181,7 @@ easyBind(ReturnType (MethodClass::*method)(Args...), Object&& obj) ...@@ -210,7 +181,7 @@ easyBind(ReturnType (MethodClass::*method)(Args...), Object&& obj)
{ {
return detail::easyBind_inner( return detail::easyBind_inner(
method, std::forward<Object>(obj), method, std::forward<Object>(obj),
typename GenerateIntegerSequence<sizeof...(Args)>::type{}); std::make_integer_sequence<int, sizeof...(Args)>{});
} }
//! \overload //! \overload
...@@ -225,7 +196,7 @@ easyBind(ReturnType (MethodClass::*method)(Args...) const, Object&& obj) ...@@ -225,7 +196,7 @@ easyBind(ReturnType (MethodClass::*method)(Args...) const, Object&& obj)
{ {
return detail::easyBind_inner( return detail::easyBind_inner(
method, std::forward<Object>(obj), method, std::forward<Object>(obj),
typename GenerateIntegerSequence<sizeof...(Args)>::type{}); std::make_integer_sequence<int, sizeof...(Args)>{});
} }
//! Wraps a callable object in a std::function. //! Wraps a callable object in a std::function.
......
...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
#include "NamedFunction.h" #include "NamedFunction.h"
#include "BaseLib/Functional.h" #include "BaseLib/Functional.h"
//! Helper struct used in conjunction with BaseLib::IntegerSequence to get a //! Helper struct used in conjunction with std::integer_sequence<int, ...> to
//! sequence of types, where each type is double. //! get a sequence of types, where each type is double.
template <int> template <int>
struct Double struct Double
{ {
...@@ -38,7 +38,7 @@ using CallerFunction = double (*)(void*, const std::vector<double>&); ...@@ -38,7 +38,7 @@ using CallerFunction = double (*)(void*, const std::vector<double>&);
//! Helps instantiating the call_() function. //! Helps instantiating the call_() function.
template <int... Indices> template <int... Indices>
CallerFunction generateCallerFromIntegerSequence( CallerFunction generateCallerFromIntegerSequence(
BaseLib::IntegerSequence<Indices...>) std::integer_sequence<int, Indices...>)
{ {
return call_<Indices...>; return call_<Indices...>;
} }
...@@ -48,7 +48,7 @@ template <int NumArguments> ...@@ -48,7 +48,7 @@ template <int NumArguments>
CallerFunction generateCaller() CallerFunction generateCaller()
{ {
return generateCallerFromIntegerSequence( return generateCallerFromIntegerSequence(
typename BaseLib::GenerateIntegerSequence<NumArguments>::type{}); std::make_integer_sequence<int, NumArguments>{});
} }
//! Holds instantiations of the call_() function for various numbers of //! Holds instantiations of the call_() function for various numbers of
...@@ -87,7 +87,7 @@ using DeleterFunction = void (*)(void*); ...@@ -87,7 +87,7 @@ using DeleterFunction = void (*)(void*);
//! Helps instantiating the delete_() function. //! Helps instantiating the delete_() function.
template <int... Indices> template <int... Indices>
DeleterFunction generateDeleterFromIntegerSequence( DeleterFunction generateDeleterFromIntegerSequence(
BaseLib::IntegerSequence<Indices...>) std::integer_sequence<int, Indices...>)
{ {
return delete_<Indices...>; return delete_<Indices...>;
} }
...@@ -97,7 +97,7 @@ template <int NumArguments> ...@@ -97,7 +97,7 @@ template <int NumArguments>
DeleterFunction generateDeleter() DeleterFunction generateDeleter()
{ {
return generateDeleterFromIntegerSequence( return generateDeleterFromIntegerSequence(
typename BaseLib::GenerateIntegerSequence<NumArguments>::type{}); std::make_integer_sequence<int, NumArguments>{});
} }
//! Holds instantiations of the delete_() function for various numbers of //! Holds instantiations of the delete_() function for various numbers of
...@@ -136,7 +136,7 @@ using CopierFunction = void* (*)(void*); ...@@ -136,7 +136,7 @@ using CopierFunction = void* (*)(void*);
//! Helps instantiating the copy_() function. //! Helps instantiating the copy_() function.
template <int... Indices> template <int... Indices>
CopierFunction generateCopierFromIntegerSequence( CopierFunction generateCopierFromIntegerSequence(
BaseLib::IntegerSequence<Indices...>) std::integer_sequence<int, Indices...>)
{ {
return copy_<Indices...>; return copy_<Indices...>;
} }
...@@ -146,7 +146,7 @@ template <int NumArguments> ...@@ -146,7 +146,7 @@ template <int NumArguments>
CopierFunction generateCopier() CopierFunction generateCopier()
{ {
return generateCopierFromIntegerSequence( return generateCopierFromIntegerSequence(
typename BaseLib::GenerateIntegerSequence<NumArguments>::type{}); std::make_integer_sequence<int, NumArguments>{});
} }
//! Holds instantiations of the copy_() function for various numbers of //! Holds instantiations of the copy_() function for various numbers of
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment