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
383a8423
Commit
383a8423
authored
Dec 04, 2013
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Forbid copying from a temporary (Basic)Formatter object.
parent
e8a2bdf2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
32 deletions
+25
-32
format.h
format.h
+24
-31
format_test.cc
format_test.cc
+1
-1
No files found.
format.h
View file @
383a8423
...
...
@@ -774,7 +774,8 @@ BasicWriter<Char> &BasicWriter<Char>::operator<<(
template
<
typename
Char
>
BasicFormatter
<
Char
>
BasicWriter
<
Char
>::
Format
(
StringRef
format
)
{
return
BasicFormatter
<
Char
>
(
*
this
,
format
.
c_str
());
BasicFormatter
<
Char
>
f
(
*
this
,
format
.
c_str
());
return
f
;
}
typedef
BasicWriter
<
char
>
Writer
;
...
...
@@ -936,8 +937,12 @@ class BasicFormatter {
friend
class
internal
::
FormatterProxy
<
Char
>
;
// Forbid copying other than from a temporary. Do not implement.
BasicFormatter
(
BasicFormatter
&
);
// Forbid copying from a temporary as in the following example:
// fmt::Formatter<> f = Format("test"); // not allowed
// This is done because BasicFormatter objects should normally exist
// only as temporaries returned by one of the formatting functions.
// Do not implement.
BasicFormatter
(
const
BasicFormatter
&
);
BasicFormatter
&
operator
=
(
const
BasicFormatter
&
);
void
Add
(
const
Arg
&
arg
)
{
...
...
@@ -988,13 +993,8 @@ class BasicFormatter {
CompleteFormatting
();
}
// Constructs a formatter from a proxy object.
BasicFormatter
(
const
Proxy
&
p
)
:
writer_
(
p
.
writer
),
format_
(
p
.
format
)
{}
operator
Proxy
()
{
const
Char
*
format
=
format_
;
format_
=
0
;
return
Proxy
(
writer_
,
format
);
BasicFormatter
(
BasicFormatter
&
f
)
:
writer_
(
f
.
writer_
),
format_
(
f
.
format_
)
{
f
.
format_
=
0
;
}
// Feeds an argument to a formatter.
...
...
@@ -1089,7 +1089,7 @@ class NoAction {
// Formats an error message and prints it to stdout.
fmt::Formatter<PrintError> ReportError(const char *format) {
return
fmt::Formatter<PrintError>(format
);
return
Move(fmt::Formatter<PrintError>(format)
);
}
ReportError("File not found: {}") << path;
...
...
@@ -1102,16 +1102,9 @@ class Formatter : private Action, public BasicFormatter<Char> {
bool
inactive_
;
// Forbid copying other than from a temporary. Do not implement.
Formatter
(
Formatter
&
);
Formatter
(
const
Formatter
&
);
Formatter
&
operator
=
(
const
Formatter
&
);
struct
Proxy
{
const
Char
*
format
;
Action
action
;
Proxy
(
const
Char
*
fmt
,
Action
a
)
:
format
(
fmt
),
action
(
a
)
{}
};
public:
/**
\rst
...
...
@@ -1127,10 +1120,10 @@ class Formatter : private Action, public BasicFormatter<Char> {
inactive_
(
false
)
{
}
// Constructs a formatter from a proxy object.
Formatter
(
const
Proxy
&
p
)
:
Action
(
p
.
action
),
BasicFormatter
<
Char
>
(
writer_
,
p
.
format
),
Formatter
(
Formatter
&
f
)
:
Action
(
f
),
BasicFormatter
<
Char
>
(
writer_
,
f
.
TakeFormatString
()),
inactive_
(
false
)
{
f
.
inactive_
=
true
;
}
/**
...
...
@@ -1142,14 +1135,14 @@ class Formatter : private Action, public BasicFormatter<Char> {
(
*
this
)(
writer_
);
}
}
// Converts the formatter into a proxy object.
operator
Proxy
()
{
inactive_
=
true
;
return
Proxy
(
this
->
TakeFormatString
(),
*
this
);
}
};
// Removes a const qualifier from a formatter object making it moveable.
template
<
typename
Action
,
typename
Char
>
Formatter
<
Action
,
Char
>
&
Move
(
const
Formatter
<
Action
,
Char
>
&
f
)
{
return
const_cast
<
Formatter
<
Action
,
Char
>
&>
(
f
);
}
/**
Fast integer formatter.
*/
...
...
@@ -1223,11 +1216,11 @@ class FormatInt {
\endrst
*/
inline
Formatter
<>
Format
(
StringRef
format
)
{
return
Formatter
<>
(
format
);
return
Move
(
Formatter
<>
(
format
)
);
}
inline
Formatter
<
NoAction
,
wchar_t
>
Format
(
WStringRef
format
)
{
return
Formatter
<
NoAction
,
wchar_t
>
(
format
);
return
Move
(
Formatter
<
NoAction
,
wchar_t
>
(
format
)
);
}
/** A formatting action that writes formatted output to stdout. */
...
...
@@ -1243,7 +1236,7 @@ class Write {
// Example:
// Print("Elapsed time: {0:.2f} seconds") << 1.23;
inline
Formatter
<
Write
>
Print
(
StringRef
format
)
{
return
Formatter
<
Write
>
(
format
);
return
Move
(
Formatter
<
Write
>
(
format
)
);
}
}
...
...
format_test.cc
View file @
383a8423
...
...
@@ -1327,7 +1327,7 @@ struct PrintError {
};
fmt
::
Formatter
<
PrintError
>
ReportError
(
const
char
*
format
)
{
return
fmt
::
Formatter
<
PrintError
>
(
format
);
return
Move
(
fmt
::
Formatter
<
PrintError
>
(
format
)
);
}
TEST
(
FormatterTest
,
Examples
)
{
...
...
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