Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
rlib
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
river
rlib
Commits
5f68ad76
There was an error fetching the commit references. Please try again later.
Commit
5f68ad76
authored
5 years ago
by
Recolic Keghart
Browse files
Options
Downloads
Patches
Plain Diff
add printable_iter
parent
9116bb7f
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
stdio.hpp
+28
-51
28 additions, 51 deletions
stdio.hpp
test/src/common.cc
+11
-0
11 additions, 0 deletions
test/src/common.cc
with
39 additions
and
51 deletions
stdio.hpp
+
28
−
51
View file @
5f68ad76
...
...
@@ -80,14 +80,6 @@ namespace rlib {
void
println
();
template
<
typename
...
Args
>
void
print
(
Args
...
args
);
template
<
typename
Iterable
,
typename
Printable
>
void
print_iter
(
Iterable
arg
,
Printable
spliter
);
template
<
typename
Iterable
,
typename
Printable
>
void
println_iter
(
Iterable
arg
,
Printable
spliter
);
template
<
typename
Iterable
>
void
print_iter
(
Iterable
arg
);
template
<
typename
Iterable
>
void
println_iter
(
Iterable
arg
);
template
<
typename
...
Args
>
size_t
printf
(
const
std
::
string
&
fmt
,
Args
...
args
);
template
<
typename
...
Args
>
...
...
@@ -100,6 +92,23 @@ namespace rlib {
static
bool
instance
=
true
;
return
instance
;
}
template
<
typename
Iterable
,
typename
Printable
>
struct
_printable_iterable
:
private
std
::
pair
<
Iterable
,
Printable
>
{
using
std
::
pair
<
Iterable
,
Printable
>::
pair
;
const
Iterable
&
arg
()
const
{
return
std
::
pair
<
Iterable
,
Printable
>::
first
;}
const
Printable
&
spliter
()
const
{
return
std
::
pair
<
Iterable
,
Printable
>::
second
;}
};
}
// 2 more interfaces...
template
<
typename
Iterable
,
typename
Printable
>
const
impl
::
_printable_iterable
<
Iterable
,
Printable
>
printable_iter
(
Iterable
arg
,
Printable
spliter
)
{
return
impl
::
_printable_iterable
<
Iterable
,
Printable
>
(
arg
,
spliter
);
}
template
<
typename
Iterable
>
const
impl
::
_printable_iterable
<
Iterable
,
char
>
printable_iter
(
Iterable
arg
)
{
return
impl
::
_printable_iterable
<
Iterable
,
char
>
(
arg
,
' '
);
}
inline
bool
sync_with_stdio
(
bool
sync
=
true
)
noexcept
{
...
...
@@ -122,18 +131,18 @@ namespace rlib {
template
<
typename
PrintFinalT
>
void
print
(
std
::
ostream
&
os
,
PrintFinalT
reqArg
)
{
os
<<
reqArg
;
os
<<
std
::
forward
<
PrintFinalT
>
(
reqArg
)
;
}
template
<
typename
Required
,
typename
...
Optional
>
void
print
(
std
::
ostream
&
os
,
Required
reqArgs
,
Optional
...
optiArgs
)
{
os
<<
reqArgs
<<
' '
;
print
(
os
,
optiArgs
...);
print
(
os
,
std
::
forward
<
Optional
>
(
optiArgs
)
...);
}
template
<
typename
...
Optional
>
void
println
(
std
::
ostream
&
os
,
Optional
...
optiArgs
)
{
print
(
os
,
optiArgs
...);
print
(
os
,
std
::
forward
<
Optional
>
(
optiArgs
)
...);
println
(
os
);
}
template
<
>
...
...
@@ -142,29 +151,6 @@ namespace rlib {
os
<<
rlib
::
endl
;
}
template
<
typename
Iterable
,
typename
Printable
>
void
print_iter
(
std
::
ostream
&
os
,
Iterable
arg
,
Printable
spliter
)
{
for
(
const
auto
&
i
:
arg
)
os
<<
i
<<
spliter
;
}
template
<
typename
Iterable
,
typename
Printable
>
void
println_iter
(
std
::
ostream
&
os
,
Iterable
arg
,
Printable
spliter
)
{
print_iter
(
os
,
arg
,
spliter
);
println
(
os
);
}
template
<
typename
Iterable
>
void
print_iter
(
std
::
ostream
&
os
,
Iterable
arg
)
{
print_iter
(
os
,
arg
,
' '
);
}
template
<
typename
Iterable
>
void
println_iter
(
std
::
ostream
&
os
,
Iterable
arg
)
{
println_iter
(
os
,
arg
,
' '
);
}
template
<
typename
...
Args
>
size_t
printf
(
std
::
ostream
&
os
,
const
std
::
string
&
fmt
,
Args
...
args
)
{
...
...
@@ -195,22 +181,6 @@ namespace rlib {
void
print
(
Args
...
args
)
{
return
print
(
std
::
cout
,
std
::
forward
<
Args
>
(
args
)
...);
}
template
<
typename
Iterable
,
typename
Printable
>
void
print_iter
(
Iterable
arg
,
Printable
spliter
)
{
return
print_iter
(
std
::
cout
,
std
::
forward
<
Iterable
>
(
arg
),
spliter
);
}
template
<
typename
Iterable
,
typename
Printable
>
void
println_iter
(
Iterable
arg
,
Printable
spliter
)
{
return
println_iter
(
std
::
cout
,
std
::
forward
<
Iterable
>
(
arg
),
spliter
);
}
template
<
typename
Iterable
>
void
print_iter
(
Iterable
arg
)
{
return
print_iter
(
std
::
cout
,
std
::
forward
<
Iterable
>
(
arg
));
}
template
<
typename
Iterable
>
void
println_iter
(
Iterable
arg
)
{
return
println_iter
(
std
::
cout
,
std
::
forward
<
Iterable
>
(
arg
));
}
template
<
typename
...
Args
>
size_t
printf
(
const
std
::
string
&
fmt
,
Args
...
args
)
{
return
printf
(
std
::
cout
,
fmt
,
std
::
forward
<
Args
>
(
args
)
...);
...
...
@@ -237,7 +207,14 @@ namespace rlib {
std
::
ostream
&
,
impl
::
print_wrapper
<
StreamType
>>::
type
;
return
print
(
static_cast
<
ostream_or_data
>
(
os
),
std
::
forward
<
Args
>
(
args
)
...);
}
}
}
// end namespace rlib
template
<
typename
Iterable
,
typename
Printable
>
std
::
ostream
&
operator
<<
(
std
::
ostream
&
stream
,
const
rlib
::
impl
::
_printable_iterable
<
Iterable
,
Printable
>
&
p
)
{
for
(
auto
val
:
p
.
arg
())
{
stream
<<
val
<<
p
.
spliter
();
}
return
stream
;
}
#endif
This diff is collapsed.
Click to expand it.
test/src/common.cc
+
11
−
0
View file @
5f68ad76
...
...
@@ -62,6 +62,10 @@ struct rlib_test_printable {
return
stream
;
}
};
struct
rlib_test_iterable
:
public
std
::
vector
<
float
>
{
using
std
::
vector
<
float
>::
vector
;
};
TEST_CASE
(
"stdio.hpp"
)
{
std
::
stringstream
test_ss
;
rlib
::
print
(
test_ss
,
'>'
);
...
...
@@ -72,6 +76,13 @@ TEST_CASE("stdio.hpp") {
rlib
::
printfln
(
test_ss
,
"hello, {}."
,
"godaddy"
);
REQUIRE
(
rlib
::
scanln
(
test_ss
)
==
">a b 123 0.25 2"
);
REQUIRE
(
rlib
::
scanln
(
test_ss
)
==
"1hello, godaddy."
);
rlib_test_iterable
v
{
1.2
,
6.666
,
12
,
-
11.11
};
std
::
string
answer
=
"1.21.2 6.666 12 -11.11 6.6661.2 6.666 12 -11.11 121.2 6.666 12 -11.11 -11.111.2 6.666 12 -11.11 "
;
std
::
stringstream
ss1
,
ss2
;
rlib
::
println
(
ss1
,
rlib
::
printable_iter
(
v
,
rlib
::
printable_iter
(
v
)));
rlib
::
print
(
ss2
,
rlib
::
printable_iter
(
v
,
rlib
::
printable_iter
(
v
)));
rlib
::
println
(
ss1
.
str
()
==
answer
+
'\n'
,
ss2
.
str
()
==
answer
);
}
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