Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
fmt
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
fmt
Commits
08b0741f
Commit
08b0741f
authored
Apr 25, 2014
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add move ctor to BasicWriter.
parent
259a307d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
23 deletions
+59
-23
format-test.cc
format-test.cc
+50
-21
format.h
format.h
+9
-2
No files found.
format-test.cc
View file @
08b0741f
...
...
@@ -209,33 +209,31 @@ TEST(ArrayTest, Ctor) {
#if FMT_USE_RVALUE_REFERENCES
void
CheckMoveArray
(
const
char
*
str
,
Array
<
char
,
5
>
&
array
)
{
Array
<
char
,
5
>
array2
(
std
::
move
(
array
));
// Move shouldn't destroy the inline content of the first array.
EXPECT_EQ
(
str
,
std
::
string
(
&
array
[
0
],
array
.
size
()));
EXPECT_EQ
(
str
,
std
::
string
(
&
array2
[
0
],
array2
.
size
()));
EXPECT_EQ
(
5
,
array2
.
capacity
());
}
TEST
(
ArrayTest
,
MoveCtor
)
{
Array
<
char
,
5
>
array
;
const
char
test
[]
=
"test"
;
array
.
append
(
test
,
test
+
4
);
{
Array
<
char
,
5
>
array2
(
std
::
move
(
array
));
// Moving shouldn't destroy the inline content of the first array.
EXPECT_EQ
(
test
,
std
::
string
(
&
array
[
0
],
array
.
size
()));
EXPECT_EQ
(
test
,
std
::
string
(
&
array2
[
0
],
array2
.
size
()));
EXPECT_EQ
(
5
,
array2
.
capacity
());
}
CheckMoveArray
(
"test"
,
array
);
// Adding one more character fills the inline buffer, but doesn't cause
// dynamic allocation.
array
.
push_back
(
'a'
);
{
Array
<
char
,
5
>
array2
(
std
::
move
(
array
));
// Moving shouldn't destroy the inline content of the first array.
EXPECT_EQ
(
"testa"
,
std
::
string
(
&
array
[
0
],
array
.
size
()));
EXPECT_EQ
(
"testa"
,
std
::
string
(
&
array2
[
0
],
array2
.
size
()));
EXPECT_EQ
(
5
,
array2
.
capacity
());
}
CheckMoveArray
(
"testa"
,
array
);
// Adding one more character causes the content to move from the inline to
// a dynamically allocated buffer.
array
.
push_back
(
'b'
);
{
Array
<
char
,
5
>
array2
(
std
::
move
(
array
));
// Moving should rip the guts of the first array.
EXPECT_TRUE
(
!&
array
[
0
]);
EXPECT_EQ
(
"testab"
,
std
::
string
(
&
array2
[
0
],
array2
.
size
()));
EXPECT_GT
(
array2
.
capacity
(),
5
);
}
Array
<
char
,
5
>
array2
(
std
::
move
(
array
));
// Move should rip the guts of the first array.
EXPECT_TRUE
(
!&
array
[
0
]);
EXPECT_EQ
(
"testab"
,
std
::
string
(
&
array2
[
0
],
array2
.
size
()));
EXPECT_GT
(
array2
.
capacity
(),
5
);
}
#endif // FMT_USE_RVALUE_REFERENCES
...
...
@@ -317,6 +315,37 @@ TEST(WriterTest, Ctor) {
EXPECT_EQ
(
""
,
w
.
str
());
}
#if FMT_USE_RVALUE_REFERENCES
void
CheckMoveWriter
(
const
std
::
string
&
str
,
Writer
&
w
)
{
Writer
w2
(
std
::
move
(
w
));
// Move shouldn't destroy the inline content of the first writer.
EXPECT_EQ
(
str
,
w
.
str
());
EXPECT_EQ
(
str
,
w2
.
str
());
}
TEST
(
WriterTest
,
MoveCtor
)
{
Writer
w
;
w
<<
"test"
;
CheckMoveWriter
(
"test"
,
w
);
// This fills the inline buffer, but doesn't cause dynamic allocation.
std
::
string
s
;
for
(
int
i
=
0
;
i
<
fmt
::
internal
::
INLINE_BUFFER_SIZE
;
++
i
)
s
+=
'*'
;
w
.
Clear
();
w
<<
s
;
CheckMoveWriter
(
s
,
w
);
// Adding one more character causes the content to move from the inline to
// a dynamically allocated buffer.
w
<<
'*'
;
Writer
w2
(
std
::
move
(
w
));
// Move should rip the guts of the first writer.
EXPECT_TRUE
(
!
w
.
data
());
EXPECT_EQ
(
s
+
'*'
,
w2
.
str
());
}
#endif // FMT_USE_RVALUE_REFERENCES
TEST
(
WriterTest
,
Data
)
{
Writer
w
;
w
<<
42
;
...
...
format.h
View file @
08b0741f
...
...
@@ -693,7 +693,8 @@ inline StrFormatSpec<wchar_t> pad(
template
<
typename
Char
>
class
BasicWriter
{
private:
mutable
internal
::
Array
<
Char
,
internal
::
INLINE_BUFFER_SIZE
>
buffer_
;
// Output buffer.
// Output buffer.
mutable
internal
::
Array
<
Char
,
internal
::
INLINE_BUFFER_SIZE
>
buffer_
;
// Make BasicFormatter a friend so that it can access ArgInfo and Arg.
friend
class
BasicFormatter
<
Char
>
;
...
...
@@ -897,7 +898,13 @@ class BasicWriter {
BasicStringRef
<
Char
>
format
,
std
::
size_t
num_args
,
const
ArgInfo
*
args
);
};
public:
public:
BasicWriter
()
{}
#if FMT_USE_RVALUE_REFERENCES
BasicWriter
(
BasicWriter
&&
other
)
:
buffer_
(
std
::
move
(
other
.
buffer_
))
{}
#endif
/**
Returns the number of characters written to the output buffer.
*/
...
...
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