Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dune-xt
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
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
ag-ohlberger
dune-community
dune-xt
Commits
b277d605
Unverified
Commit
b277d605
authored
7 years ago
by
Tobias Leibner
Browse files
Options
Downloads
Patches
Plain Diff
[tuple] add tuple_element with template recursion depth of O(log(N))
parent
a34bdbd4
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
dune/xt/common/tuple.hh
+47
-2
47 additions, 2 deletions
dune/xt/common/tuple.hh
with
47 additions
and
2 deletions
dune/xt/common/tuple.hh
+
47
−
2
View file @
b277d605
...
@@ -237,13 +237,17 @@ struct Combine
...
@@ -237,13 +237,17 @@ struct Combine
}
// namespace TupleProduct
}
// namespace TupleProduct
// from https://stackoverflow.com/questions/17424477/implementation-c14-make-integer-sequence/17426611
//
!
from https://stackoverflow.com/questions/17424477/implementation-c14-make-integer-sequence/17426611
template
<
size_t
...
Is
>
template
<
size_t
...
Is
>
struct
index_sequence
struct
index_sequence
{
{
using
type
=
index_sequence
;
using
type
=
index_sequence
;
};
};
namespace
internal
{
template
<
class
S1
,
class
S2
>
template
<
class
S1
,
class
S2
>
struct
Concat
;
struct
Concat
;
template
<
class
S1
,
class
S2
>
template
<
class
S1
,
class
S2
>
...
@@ -256,6 +260,9 @@ struct Concat<index_sequence<I1...>, index_sequence<I2...>>
...
@@ -256,6 +260,9 @@ struct Concat<index_sequence<I1...>, index_sequence<I2...>>
};
};
}
// namespace internal
template
<
size_t
N
>
template
<
size_t
N
>
struct
make_index_sequence
;
struct
make_index_sequence
;
template
<
size_t
N
>
template
<
size_t
N
>
...
@@ -264,7 +271,7 @@ using make_index_sequence_t = typename make_index_sequence<N>::type;
...
@@ -264,7 +271,7 @@ using make_index_sequence_t = typename make_index_sequence<N>::type;
template
<
size_t
N
>
template
<
size_t
N
>
struct
make_index_sequence
struct
make_index_sequence
{
{
using
type
=
Concat_t
<
make_index_sequence_t
<
N
/
2
>
,
make_index_sequence_t
<
N
-
N
/
2
>>
;
using
type
=
internal
::
Concat_t
<
make_index_sequence_t
<
N
/
2
>
,
make_index_sequence_t
<
N
-
N
/
2
>>
;
};
};
// break conditions
// break conditions
...
@@ -298,6 +305,44 @@ struct make_identical_tuple<T, N, index_sequence<Indices...>>
...
@@ -298,6 +305,44 @@ struct make_identical_tuple<T, N, index_sequence<Indices...>>
}
}
};
};
//! implementation of std::tuple_element with O(log(N)) template recursion depth
//! from https://stackoverflow.com/questions/18593057/stdtuple-element-need-deep-template-instantination
namespace
internal
{
template
<
std
::
size_t
>
struct
Any
{
Any
(...)
{
}
};
template
<
typename
T
>
struct
wrapper
{
using
type
=
T
;
};
template
<
std
::
size_t
...
Is
>
struct
get_nth_helper
{
template
<
typename
T
>
static
auto
deduce
(
Any
<
Is
>
...,
wrapper
<
T
>
,
...)
->
wrapper
<
T
>
;
};
template
<
std
::
size_t
...
Is
,
typename
...
Ts
>
auto
deduce_seq
(
index_sequence
<
Is
...
>
,
wrapper
<
Ts
>
...
pp
)
->
decltype
(
get_nth_helper
<
Is
...
>::
deduce
(
pp
...));
}
template
<
std
::
size_t
N
,
class
Tuple
>
struct
tuple_element
;
template
<
std
::
size_t
N
,
class
...
Ts
>
struct
tuple_element
<
N
,
std
::
tuple
<
Ts
...
>>
{
using
wrapped_type
=
decltype
(
internal
::
deduce_seq
(
make_index_sequence_t
<
N
>
{},
internal
::
wrapper
<
Ts
>
()...));
using
type
=
typename
wrapped_type
::
type
;
};
}
// namespace Common
}
// namespace Common
}
// namespace XT
}
// namespace XT
}
// namespace Dune
}
// namespace Dune
...
...
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