Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
ogs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
wenqing
ogs
Commits
aba23ae8
Commit
aba23ae8
authored
6 years ago
by
Dmitri Naumov
Browse files
Options
Downloads
Patches
Plain Diff
Use std::integer_sequence replacing own impl.
The integer_sequence is available since c++14.
parent
df19e77f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
BaseLib/Functional.h
+4
-33
4 additions, 33 deletions
BaseLib/Functional.h
NumLib/NamedFunction.cpp
+8
-8
8 additions, 8 deletions
NumLib/NamedFunction.cpp
with
12 additions
and
41 deletions
BaseLib/Functional.h
+
4
−
33
View file @
aba23ae8
...
@@ -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
,
I
nteger
S
equence
<
Indices
...
>
)
std
::
i
nteger
_s
equence
<
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
,
I
nteger
S
equence
<
Indices
...
>
)
std
::
i
nteger
_s
equence
<
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
GenerateI
nteger
S
equence
<
sizeof
...(
Args
)
>
::
type
{});
std
::
make_i
nteger
_s
equence
<
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
GenerateI
nteger
S
equence
<
sizeof
...(
Args
)
>
::
type
{});
std
::
make_i
nteger
_s
equence
<
int
,
sizeof
...(
Args
)
>
{});
}
}
//! Wraps a callable object in a std::function.
//! Wraps a callable object in a std::function.
...
...
This diff is collapsed.
Click to expand it.
NumLib/NamedFunction.cpp
+
8
−
8
View file @
aba23ae8
...
@@ -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
::
I
nteger
S
equence
to get a
//! Helper struct used in conjunction with
std
::
i
nteger
_s
equence
<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
::
I
nteger
S
equence
<
Indices
...
>
)
std
::
i
nteger
_s
equence
<
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
::
GenerateI
nteger
S
equence
<
NumArguments
>
::
type
{});
std
::
make_i
nteger
_s
equence
<
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
::
I
nteger
S
equence
<
Indices
...
>
)
std
::
i
nteger
_s
equence
<
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
::
GenerateI
nteger
S
equence
<
NumArguments
>
::
type
{});
std
::
make_i
nteger
_s
equence
<
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
::
I
nteger
S
equence
<
Indices
...
>
)
std
::
i
nteger
_s
equence
<
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
::
GenerateI
nteger
S
equence
<
NumArguments
>
::
type
{});
std
::
make_i
nteger
_s
equence
<
int
,
NumArguments
>
{});
}
}
//! Holds instantiations of the copy_() function for various numbers of
//! Holds instantiations of the copy_() function for various numbers of
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment