Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Algorithms Library Toolkit Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
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
Container Registry
Model registry
Monitor
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Algorithms Library Toolkit
Algorithms Library Toolkit Core
Commits
f91b6003
Commit
f91b6003
authored
6 years ago
by
Jan Trávníček
Browse files
Options
Downloads
Patches
Plain Diff
simplify call on nth element of tuple
parent
db2062a6
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
alib2std/src/extensions/ptr_tuple.hpp
+8
-8
8 additions, 8 deletions
alib2std/src/extensions/ptr_tuple.hpp
alib2std/src/extensions/tuple.hpp
+9
-9
9 additions, 9 deletions
alib2std/src/extensions/tuple.hpp
with
17 additions
and
17 deletions
alib2std/src/extensions/ptr_tuple.hpp
+
8
−
8
View file @
f91b6003
...
@@ -505,20 +505,20 @@ struct tuple_element < I, ext::ptr_tuple < Types... > > {
...
@@ -505,20 +505,20 @@ struct tuple_element < I, ext::ptr_tuple < Types... > > {
typedef
typename
std
::
tuple_element
<
I
,
std
::
tuple
<
Types
...
>
>::
type
type
;
typedef
typename
std
::
tuple_element
<
I
,
std
::
tuple
<
Types
...
>
>::
type
type
;
};
};
template
<
class
Result
,
unsigned
I
,
class
Callable
,
class
...
Types
>
template
<
class
Result
,
unsigned
I
,
class
...
Types
>
struct
call_on_nth_helper
<
Result
,
I
,
ext
::
ptr_tuple
<
Types
...
>
,
Callable
>
{
struct
call_on_nth_helper
<
Result
,
I
,
ext
::
ptr_tuple
<
Types
...
>
>
{
template
<
class
Tuple
>
template
<
class
Tuple
,
class
Callable
>
static
Result
call_on_nth_fn
(
Tuple
&&
t
,
unsigned
index
,
Callable
callback
)
{
static
Result
call_on_nth_fn
(
Tuple
&&
t
,
unsigned
index
,
Callable
callback
)
{
if
(
index
==
0
)
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
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
>
template
<
class
Result
,
class
...
Types
>
struct
call_on_nth_helper
<
Result
,
0
,
ext
::
ptr_tuple
<
Types
...
>
,
Callable
>
{
struct
call_on_nth_helper
<
Result
,
0
,
ext
::
ptr_tuple
<
Types
...
>
>
{
template
<
class
Tuple
>
template
<
class
Tuple
,
class
Callable
>
static
Result
call_on_nth_fn
(
Tuple
&&
,
unsigned
,
Callable
)
{
static
Result
call_on_nth_fn
(
Tuple
&&
,
unsigned
,
Callable
)
{
throw
std
::
out_of_range
(
"Not enough elements in tuple."
);
throw
std
::
out_of_range
(
"Not enough elements in tuple."
);
}
}
...
...
This diff is collapsed.
Click to expand it.
alib2std/src/extensions/tuple.hpp
+
9
−
9
View file @
f91b6003
...
@@ -91,23 +91,23 @@ struct tuple_element < I, const volatile T > {
...
@@ -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
;
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
;
struct
call_on_nth_helper
;
template
<
class
Result
,
unsigned
I
,
class
Callable
,
class
...
Types
>
template
<
class
Result
,
unsigned
I
,
class
...
Types
>
struct
call_on_nth_helper
<
Result
,
I
,
ext
::
tuple
<
Types
...
>
,
Callable
>
{
struct
call_on_nth_helper
<
Result
,
I
,
ext
::
tuple
<
Types
...
>
>
{
template
<
class
Tuple
>
template
<
class
Tuple
,
class
Callable
>
static
Result
call_on_nth_fn
(
Tuple
&&
t
,
unsigned
index
,
Callable
callback
)
{
static
Result
call_on_nth_fn
(
Tuple
&&
t
,
unsigned
index
,
Callable
callback
)
{
if
(
index
==
0
)
if
(
index
==
0
)
return
callback
(
std
::
get
<
ext
::
tuple_size
<
Tuple
>::
value
-
I
>
(
std
::
forward
<
Tuple
&&
>
(
t
)
)
);
return
callback
(
std
::
get
<
ext
::
tuple_size
<
Tuple
>::
value
-
I
>
(
std
::
forward
<
Tuple
&&
>
(
t
)
)
);
else
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
>
template
<
class
Result
,
class
...
Types
>
struct
call_on_nth_helper
<
Result
,
0
,
ext
::
tuple
<
Types
...
>
,
Callable
>
{
struct
call_on_nth_helper
<
Result
,
0
,
ext
::
tuple
<
Types
...
>
>
{
template
<
class
Tuple
>
template
<
class
Tuple
,
class
Callable
>
static
Result
call_on_nth_fn
(
Tuple
&&
,
unsigned
,
Callable
)
{
static
Result
call_on_nth_fn
(
Tuple
&&
,
unsigned
,
Callable
)
{
throw
std
::
out_of_range
(
"Not enough elements in tuple."
);
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 > {
...
@@ -115,7 +115,7 @@ struct call_on_nth_helper < Result, 0, ext::tuple < Types ... >, Callable > {
template
<
class
Result
,
class
Tuple
,
class
Callable
>
template
<
class
Result
,
class
Tuple
,
class
Callable
>
Result
call_on_nth
(
Tuple
&&
t
,
unsigned
index
,
Callable
callback
)
{
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
);
}
}
...
...
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