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
33d0d995
Commit
33d0d995
authored
Jun 30, 2019
by
Anton Bukov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add append and prepend methods
parent
0fedea17
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
128 additions
and
0 deletions
+128
-0
README.md
README.md
+1
-0
boolinq.h
include/boolinq/boolinq.h
+45
-0
AppendTest.cpp
test/AppendTest.cpp
+40
-0
CMakeLists.txt
test/CMakeLists.txt
+2
-0
PrependTest.cpp
test/PrependTest.cpp
+40
-0
No files found.
README.md
View file @
33d0d995
...
...
@@ -89,6 +89,7 @@ int DenisUniqueContactCount =
-
`skip(count)`
,
`skipWhile(predicate)`
,
`skipWhile_i(predicate)`
-
`orderBy()`
,
`orderBy(transform)`
-
`distinct()`
,
`distinct(transform)`
-
`append(items)`
,
`prepend(items)`
-
`concat(linq)`
-
`reverse()`
-
`cast<T>()`
...
...
include/boolinq/boolinq.h
View file @
33d0d995
...
...
@@ -152,6 +152,51 @@ namespace boolinq {
return
skipWhile_i
([
predicate
](
T
value
,
int
/*i*/
)
{
return
predicate
(
value
);
});
}
template
<
typename
SS
,
typename
TT
>
struct
LinqValueIndex
{
Linq
<
SS
,
TT
>
linq
;
std
::
vector
<
TT
>
values
;
int
index
;
};
template
<
typename
...
Types
>
Linq
<
LinqValueIndex
<
S
,
T
>
,
T
>
append
(
Types
...
newValues
)
const
{
return
Linq
<
LinqValueIndex
<
S
,
T
>
,
T
>
(
{
*
this
,
{
newValues
...
},
-
1
},
[](
LinqValueIndex
<
S
,
T
>
&
tuple
)
{
if
(
tuple
.
index
==
-
1
)
{
try
{
return
tuple
.
linq
.
next
();
}
catch
(
LinqEndException
&
)
{
tuple
.
index
=
0
;
}
}
if
(
tuple
.
index
<
tuple
.
values
.
size
())
{
return
tuple
.
values
[
tuple
.
index
++
];
}
throw
LinqEndException
();
}
);
}
template
<
typename
...
Types
>
Linq
<
LinqValueIndex
<
S
,
T
>
,
T
>
prepend
(
Types
...
newValues
)
const
{
return
Linq
<
LinqValueIndex
<
S
,
T
>
,
T
>
(
{
*
this
,
{
newValues
...
},
0
},
[](
LinqValueIndex
<
S
,
T
>
&
tuple
)
{
if
(
tuple
.
index
<
tuple
.
values
.
size
())
{
return
tuple
.
values
[
tuple
.
index
++
];
}
return
tuple
.
linq
.
next
();
}
);
}
template
<
typename
F
,
typename
_TRet
=
typename
std
::
result_of
<
F
(
T
,
int
)
>::
type
>
Linq
<
LinqIndex
<
S
,
T
>
,
_TRet
>
select_i
(
F
apply
)
const
{
...
...
test/AppendTest.cpp
0 → 100644
View file @
33d0d995
#include <vector>
#include <string>
#include <gtest/gtest.h>
#include "CommonTests.h"
#include "boolinq.h"
using
namespace
boolinq
;
TEST
(
Append
,
ThreePlusOne
)
{
std
::
vector
<
int
>
src
=
{
1
,
2
,
3
};
auto
rng
=
from
(
src
).
append
(
4
);
int
ans
[]
=
{
1
,
2
,
3
,
4
};
CheckRangeEqArray
(
rng
,
ans
);
}
TEST
(
Append
,
ThreePlusTwo
)
{
std
::
vector
<
int
>
src
=
{
1
,
2
,
3
};
auto
rng
=
from
(
src
).
append
(
4
,
5
);
int
ans
[]
=
{
1
,
2
,
3
,
4
,
5
};
CheckRangeEqArray
(
rng
,
ans
);
}
TEST
(
Append
,
ZeroPlusTwo
)
{
std
::
vector
<
int
>
src
;
auto
rng
=
from
(
src
).
append
(
7
,
8
);
int
ans
[]
=
{
7
,
8
};
CheckRangeEqArray
(
rng
,
ans
);
}
\ No newline at end of file
test/CMakeLists.txt
View file @
33d0d995
...
...
@@ -23,6 +23,7 @@ SET (
${
PROJECT_SOURCE_DIR
}
/test/AllTest.cpp
${
PROJECT_SOURCE_DIR
}
/test/AnyTest.cpp
${
PROJECT_SOURCE_DIR
}
/test/AvgTest.cpp
${
PROJECT_SOURCE_DIR
}
/test/AppendTest.cpp
${
PROJECT_SOURCE_DIR
}
/test/BitsTest.cpp
${
PROJECT_SOURCE_DIR
}
/test/BytesTest.cpp
${
PROJECT_SOURCE_DIR
}
/test/ConcatTest.cpp
...
...
@@ -38,6 +39,7 @@ SET (
${
PROJECT_SOURCE_DIR
}
/test/MaxTest.cpp
${
PROJECT_SOURCE_DIR
}
/test/MinTest.cpp
${
PROJECT_SOURCE_DIR
}
/test/OrderByTest.cpp
${
PROJECT_SOURCE_DIR
}
/test/PrependTest.cpp
${
PROJECT_SOURCE_DIR
}
/test/ReverseTest.cpp
${
PROJECT_SOURCE_DIR
}
/test/SelectTest.cpp
${
PROJECT_SOURCE_DIR
}
/test/SkipTest.cpp
...
...
test/PrependTest.cpp
0 → 100644
View file @
33d0d995
#include <vector>
#include <string>
#include <gtest/gtest.h>
#include "CommonTests.h"
#include "boolinq.h"
using
namespace
boolinq
;
TEST
(
Prepend
,
ThreePlusOne
)
{
std
::
vector
<
int
>
src
=
{
1
,
2
,
3
};
auto
rng
=
from
(
src
).
prepend
(
4
);
int
ans
[]
=
{
4
,
1
,
2
,
3
};
CheckRangeEqArray
(
rng
,
ans
);
}
TEST
(
Prepend
,
ThreePlusTwo
)
{
std
::
vector
<
int
>
src
=
{
1
,
2
,
3
};
auto
rng
=
from
(
src
).
prepend
(
4
,
5
);
int
ans
[]
=
{
4
,
5
,
1
,
2
,
3
};
CheckRangeEqArray
(
rng
,
ans
);
}
TEST
(
Prepend
,
ZeroPlusTwo
)
{
std
::
vector
<
int
>
src
;
auto
rng
=
from
(
src
).
prepend
(
7
,
8
);
int
ans
[]
=
{
7
,
8
};
CheckRangeEqArray
(
rng
,
ans
);
}
\ No newline at end of file
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