Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
B
boolinq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
boolinq
Commits
79066aaa
Unverified
Commit
79066aaa
authored
Jul 01, 2019
by
Anton Bukov
Committed by
GitHub
Jul 01, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #27 from k06a/feature/v3-tuple
Replace LinqIndex with tuple
parents
33d0d995
2b6ae465
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
29 deletions
+30
-29
boolinq.h
include/boolinq/boolinq.h
+30
-29
No files found.
include/boolinq/boolinq.h
View file @
79066aaa
...
...
@@ -3,9 +3,10 @@
#include <limits.h>
#include <functional>
#include <tuple>
#include <iterator>
#include <iostream>
#include <iterator>
#include <vector>
#include <deque>
#include <list>
...
...
@@ -49,18 +50,12 @@ namespace boolinq {
return
nextFunc
(
storage
);
}
template
<
typename
SS
,
typename
TT
>
struct
LinqIndex
{
Linq
<
SS
,
TT
>
linq
;
int
index
;
};
void
for_each_i
(
std
::
function
<
void
(
T
,
int
)
>
apply
)
const
{
Linq
Index
<
S
,
T
>
storage
=
{
*
this
,
0
}
;
Linq
<
S
,
T
>
linq
=
*
this
;
try
{
while
(
true
)
{
apply
(
storage
.
linq
.
next
(),
storage
.
index
++
);
for
(
int
i
=
0
;
;
i
++
)
{
apply
(
linq
.
next
(),
i
);
}
}
catch
(
LinqEndException
&
)
{}
...
...
@@ -71,14 +66,17 @@ namespace boolinq {
return
for_each_i
([
apply
](
T
value
,
int
index
)
{
return
apply
(
value
);
});
}
Linq
<
LinqIndex
<
S
,
T
>
,
T
>
where_i
(
std
::
function
<
bool
(
T
,
int
)
>
filter
)
const
Linq
<
std
::
tuple
<
Linq
<
S
,
T
>
,
int
>
,
T
>
where_i
(
std
::
function
<
bool
(
T
,
int
)
>
filter
)
const
{
return
Linq
<
LinqIndex
<
S
,
T
>
,
T
>
(
{
*
this
,
0
},
[
filter
](
LinqIndex
<
S
,
T
>
&
pair
)
{
return
Linq
<
std
::
tuple
<
Linq
<
S
,
T
>
,
int
>
,
T
>
(
std
::
make_tuple
(
*
this
,
0
),
[
filter
](
std
::
tuple
<
Linq
<
S
,
T
>
,
int
>
&
tuple
)
{
Linq
<
S
,
T
>
&
linq
=
std
::
get
<
0
>
(
tuple
);
int
&
index
=
std
::
get
<
1
>
(
tuple
);
while
(
true
)
{
T
ret
=
pair
.
linq
.
next
();
if
(
filter
(
ret
,
pair
.
index
++
))
{
T
ret
=
linq
.
next
();
if
(
filter
(
ret
,
index
++
))
{
return
ret
;
}
}
...
...
@@ -86,12 +84,12 @@ namespace boolinq {
);
}
Linq
<
LinqIndex
<
S
,
T
>
,
T
>
where
(
std
::
function
<
bool
(
T
)
>
filter
)
const
Linq
<
std
::
tuple
<
Linq
<
S
,
T
>
,
int
>
,
T
>
where
(
std
::
function
<
bool
(
T
)
>
filter
)
const
{
return
where_i
([
filter
](
T
value
,
int
index
)
{
return
filter
(
value
);
});
}
Linq
<
LinqIndex
<
S
,
T
>
,
T
>
take
(
int
count
)
const
Linq
<
std
::
tuple
<
Linq
<
S
,
T
>
,
int
>
,
T
>
take
(
int
count
)
const
{
return
where_i
([
count
](
T
/*value*/
,
int
i
)
{
if
(
i
==
count
)
{
...
...
@@ -101,7 +99,7 @@ namespace boolinq {
});
}
Linq
<
LinqIndex
<
S
,
T
>
,
T
>
takeWhile_i
(
std
::
function
<
bool
(
T
,
int
)
>
predicate
)
const
Linq
<
std
::
tuple
<
Linq
<
S
,
T
>
,
int
>
,
T
>
takeWhile_i
(
std
::
function
<
bool
(
T
,
int
)
>
predicate
)
const
{
return
where_i
([
predicate
](
T
value
,
int
i
)
{
if
(
!
predicate
(
value
,
i
))
{
...
...
@@ -111,12 +109,12 @@ namespace boolinq {
});
}
Linq
<
LinqIndex
<
S
,
T
>
,
T
>
takeWhile
(
std
::
function
<
bool
(
T
)
>
predicate
)
const
Linq
<
std
::
tuple
<
Linq
<
S
,
T
>
,
int
>
,
T
>
takeWhile
(
std
::
function
<
bool
(
T
)
>
predicate
)
const
{
return
takeWhile_i
([
predicate
](
T
value
,
int
/*i*/
)
{
return
predicate
(
value
);
});
}
Linq
<
LinqIndex
<
S
,
T
>
,
T
>
skip
(
int
count
)
const
Linq
<
std
::
tuple
<
Linq
<
S
,
T
>
,
int
>
,
T
>
skip
(
int
count
)
const
{
return
where_i
([
count
](
T
value
,
int
i
)
{
return
i
>=
count
;
});
}
...
...
@@ -198,24 +196,27 @@ namespace boolinq {
}
template
<
typename
F
,
typename
_TRet
=
typename
std
::
result_of
<
F
(
T
,
int
)
>::
type
>
Linq
<
LinqIndex
<
S
,
T
>
,
_TRet
>
select_i
(
F
apply
)
const
Linq
<
std
::
tuple
<
Linq
<
S
,
T
>
,
int
>
,
_TRet
>
select_i
(
F
apply
)
const
{
return
Linq
<
LinqIndex
<
S
,
T
>
,
_TRet
>
(
{
*
this
,
0
},
[
apply
](
LinqIndex
<
S
,
T
>
&
pair
)
{
return
apply
(
pair
.
linq
.
next
(),
pair
.
index
++
);
return
Linq
<
std
::
tuple
<
Linq
<
S
,
T
>
,
int
>
,
_TRet
>
(
std
::
make_tuple
(
*
this
,
0
),
[
apply
](
std
::
tuple
<
Linq
<
S
,
T
>
,
int
>
&
tuple
)
{
Linq
<
S
,
T
>
&
linq
=
std
::
get
<
0
>
(
tuple
);
int
&
index
=
std
::
get
<
1
>
(
tuple
);
return
apply
(
linq
.
next
(),
index
++
);
}
);
}
template
<
typename
F
,
typename
_TRet
=
typename
std
::
result_of
<
F
(
T
)
>::
type
>
Linq
<
LinqIndex
<
S
,
T
>
,
_TRet
>
select
(
F
apply
)
const
Linq
<
std
::
tuple
<
Linq
<
S
,
T
>
,
int
>
,
_TRet
>
select
(
F
apply
)
const
{
return
select_i
([
apply
](
T
value
,
int
/*index*/
)
{
return
apply
(
value
);
});
}
template
<
typename
TRet
>
Linq
<
LinqIndex
<
S
,
T
>
,
TRet
>
cast
()
const
Linq
<
std
::
tuple
<
Linq
<
S
,
T
>
,
int
>
,
TRet
>
cast
()
const
{
return
select_i
([](
T
value
,
int
/*i*/
)
{
return
TRet
(
value
);
});
}
...
...
@@ -298,7 +299,7 @@ namespace boolinq {
template
<
typename
F
,
typename
_TKey
=
typename
std
::
result_of
<
F
(
T
)
>::
type
,
typename
_TValue
=
Linq
<
LinqIndex
<
S
,
T
>
,
T
>
// where(predicate)
typename
_TValue
=
Linq
<
std
::
tuple
<
Linq
<
S
,
T
>
,
int
>
,
T
>
// where(predicate)
>
Linq
<
LinqCopyUnorderedSet
<
S
,
T
,
_TKey
>
,
std
::
pair
<
_TKey
,
_TValue
>
>
groupBy
(
F
apply
)
const
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment