From aba23ae89eac506f09500b5fdd5c855d11cfca57 Mon Sep 17 00:00:00 2001 From: "Dmitry Yu. Naumov" <github@naumov.de> Date: Fri, 13 Jul 2018 13:52:47 +0200 Subject: [PATCH] Use std::integer_sequence replacing own impl. The integer_sequence is available since c++14. --- BaseLib/Functional.h | 37 ++++--------------------------------- NumLib/NamedFunction.cpp | 16 ++++++++-------- 2 files changed, 12 insertions(+), 41 deletions(-) diff --git a/BaseLib/Functional.h b/BaseLib/Functional.h index 8f2e521d955..2914f697595 100644 --- a/BaseLib/Functional.h +++ b/BaseLib/Functional.h @@ -100,7 +100,7 @@ template <int... Indices, typename Object, typename MethodClass, typename ReturnType, typename... Args> std::function<ReturnType(Args...)> easyBind_inner( ReturnType (MethodClass::*method)(Args...), Object&& obj, - IntegerSequence<Indices...>) + std::integer_sequence<int, Indices...>) { return easyBind_innermost<Indices...>(method, std::forward<Object>(obj)); } @@ -109,7 +109,7 @@ template <int... Indices, typename Object, typename MethodClass, typename ReturnType, typename... Args> std::function<ReturnType(Args...)> easyBind_inner( ReturnType (MethodClass::*method)(Args...) const, Object&& obj, - IntegerSequence<Indices...>) + std::integer_sequence<int, Indices...>) { return easyBind_innermost<Indices...>(method, std::forward<Object>(obj)); } @@ -138,35 +138,6 @@ struct FunctionTraits<ReturnType (Object::*)(Args...) const> { } // 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(). * * This function binds the member function pointer \c member of class \c Object @@ -210,7 +181,7 @@ easyBind(ReturnType (MethodClass::*method)(Args...), Object&& obj) { return detail::easyBind_inner( method, std::forward<Object>(obj), - typename GenerateIntegerSequence<sizeof...(Args)>::type{}); + std::make_integer_sequence<int, sizeof...(Args)>{}); } //! \overload @@ -225,7 +196,7 @@ easyBind(ReturnType (MethodClass::*method)(Args...) const, Object&& obj) { return detail::easyBind_inner( 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. diff --git a/NumLib/NamedFunction.cpp b/NumLib/NamedFunction.cpp index 0a1cd274b37..4f5c48befb7 100644 --- a/NumLib/NamedFunction.cpp +++ b/NumLib/NamedFunction.cpp @@ -10,8 +10,8 @@ #include "NamedFunction.h" #include "BaseLib/Functional.h" -//! Helper struct used in conjunction with BaseLib::IntegerSequence to get a -//! sequence of types, where each type is double. +//! Helper struct used in conjunction with std::integer_sequence<int, ...> to +//! get a sequence of types, where each type is double. template <int> struct Double { @@ -38,7 +38,7 @@ using CallerFunction = double (*)(void*, const std::vector<double>&); //! Helps instantiating the call_() function. template <int... Indices> CallerFunction generateCallerFromIntegerSequence( - BaseLib::IntegerSequence<Indices...>) + std::integer_sequence<int, Indices...>) { return call_<Indices...>; } @@ -48,7 +48,7 @@ template <int NumArguments> CallerFunction generateCaller() { return generateCallerFromIntegerSequence( - typename BaseLib::GenerateIntegerSequence<NumArguments>::type{}); + std::make_integer_sequence<int, NumArguments>{}); } //! Holds instantiations of the call_() function for various numbers of @@ -87,7 +87,7 @@ using DeleterFunction = void (*)(void*); //! Helps instantiating the delete_() function. template <int... Indices> DeleterFunction generateDeleterFromIntegerSequence( - BaseLib::IntegerSequence<Indices...>) + std::integer_sequence<int, Indices...>) { return delete_<Indices...>; } @@ -97,7 +97,7 @@ template <int NumArguments> DeleterFunction generateDeleter() { return generateDeleterFromIntegerSequence( - typename BaseLib::GenerateIntegerSequence<NumArguments>::type{}); + std::make_integer_sequence<int, NumArguments>{}); } //! Holds instantiations of the delete_() function for various numbers of @@ -136,7 +136,7 @@ using CopierFunction = void* (*)(void*); //! Helps instantiating the copy_() function. template <int... Indices> CopierFunction generateCopierFromIntegerSequence( - BaseLib::IntegerSequence<Indices...>) + std::integer_sequence<int, Indices...>) { return copy_<Indices...>; } @@ -146,7 +146,7 @@ template <int NumArguments> CopierFunction generateCopier() { return generateCopierFromIntegerSequence( - typename BaseLib::GenerateIntegerSequence<NumArguments>::type{}); + std::make_integer_sequence<int, NumArguments>{}); } //! Holds instantiations of the copy_() function for various numbers of -- GitLab