Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Dubský Jan
asgn
Commits
7b1811a4
Commit
7b1811a4
authored
Mar 21, 2020
by
Dubský Jan
Browse files
Solution 1.03 (Speed: 1.07)
parent
88f4fb08
Changes
2
Hide whitespace changes
Inline
Side-by-side
sol/macrosol.cpp
View file @
7b1811a4
...
...
@@ -8,11 +8,11 @@
namespace
macrosol
{
void
macroprocessor_impl
::
apply_defines
(
std
::
string_view
token
,
std
::
back_insert_iterator
<
std
::
string
>
&
out
)
{
void
macroprocessor_impl
::
apply_defines
(
std
::
string_view
token
,
std
::
string
&
out
)
{
auto
it
=
defines
.
find
(
token
);
if
(
it
==
defines
.
end
())
{
out
=
std
::
copy
(
token
.
begin
(),
token
.
end
()
,
out
);
*
out
=
' '
;
out
.
append
(
token
.
begin
(),
token
.
end
());
out
.
push_back
(
' '
)
;
return
;
}
// std::string_view(&t.front(), t.length())
...
...
@@ -40,8 +40,7 @@ bool macroprocessor_impl::process(const std::string& s, std::string& output) {
}
assert
(
output
.
size
()
==
0
);
auto
out
=
std
::
back_insert_iterator
(
output
);
for
(
auto
&&
t
:
tokens
)
apply_defines
(
t
,
out
);
for
(
auto
&&
t
:
tokens
)
apply_defines
(
t
,
output
);
if
(
output
.
size
())
output
.
pop_back
();
return
true
;
}
...
...
@@ -83,22 +82,26 @@ void macroprocessor_impl::macro::update(const std::vector<std::string_view>& tok
assert
(
tokens
[
1
]
==
"="
);
right
.
resize
(
tokens
.
size
()
-
2
);
std
::
copy
(
tokens
.
begin
()
+
2
,
tokens
.
end
(),
right
.
begin
());
right_len
=
0
;
for
(
auto
&&
r
:
right
)
right_len
+=
r
.
size
();
}
macroprocessor_impl
::
macro
::
macro
(
macro
&&
m
)
{
this
->
left
=
m
.
left
;
this
->
left_len
=
m
.
left_len
;
m
.
left
=
0
;
m
.
left_len
=
0
;
this
->
right
=
std
::
move
(
m
.
right
);
this
->
left
=
m
.
left
;
this
->
left_len
=
m
.
left_len
;
m
.
left
=
0
;
this
->
right
=
std
::
move
(
m
.
right
);
this
->
right_len
=
m
.
right_len
;
m
.
left_len
=
m
.
right_len
=
0
;
}
macroprocessor_impl
::
macro
&
macroprocessor_impl
::
macro
::
operator
=
(
macro
&&
m
)
{
this
->
left
=
m
.
left
;
this
->
left_len
=
m
.
left_len
;
m
.
left
=
0
;
m
.
left_len
=
0
;
this
->
right
=
std
::
move
(
m
.
right
);
this
->
left
=
m
.
left
;
this
->
left_len
=
m
.
left_len
;
m
.
left
=
0
;
this
->
right
=
std
::
move
(
m
.
right
);
this
->
right_len
=
m
.
right_len
;
m
.
left_len
=
m
.
right_len
=
0
;
return
*
this
;
}
...
...
sol/macrosol.hpp
View file @
7b1811a4
...
...
@@ -52,12 +52,13 @@ private:
char
*
left
;
size_t
left_len
;
std
::
vector
<
std
::
string
>
right
;
size_t
right_len
;
};
std
::
unordered_map
<
std
::
string_view
,
macro
>
defines
;
std
::
vector
<
std
::
string_view
>
parse_tokens
(
const
std
::
string
&
s
);
void
apply_defines
(
std
::
string_view
token
,
std
::
back_insert_iterator
<
std
::
string
>
&
out
);
void
apply_defines
(
std
::
string_view
token
,
std
::
string
&
out
);
};
template
<
typename
policy
>
...
...
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