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
3e75d3e0
Commit
3e75d3e0
authored
Sep 02, 2017
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix handling of types convertible to int
parent
89654cd1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
10 deletions
+27
-10
fmt/format.h
fmt/format.h
+8
-8
fmt/ostream.h
fmt/ostream.h
+4
-2
test/ostream-test.cc
test/ostream-test.cc
+15
-0
No files found.
fmt/format.h
View file @
3e75d3e0
...
...
@@ -1171,17 +1171,17 @@ T &get();
Yes
&
convert
(
fmt
::
ULongLong
);
No
&
convert
(...);
template
<
typename
T
,
bool
ENABLE_CONVERSION
>
template
<
typename
T
,
bool
ENABLE_CONVERSION
>
struct
ConvertToIntImpl
{
enum
{
value
=
ENABLE_CONVERSION
};
};
template
<
typename
T
,
bool
ENABLE_CONVERSION
>
template
<
typename
T
,
bool
ENABLE_CONVERSION
>
struct
ConvertToIntImpl2
{
enum
{
value
=
false
};
};
template
<
typename
T
>
template
<
typename
T
>
struct
ConvertToIntImpl2
<
T
,
true
>
{
enum
{
// Don't convert numeric types.
...
...
@@ -1189,7 +1189,7 @@ struct ConvertToIntImpl2<T, true> {
};
};
template
<
typename
T
>
template
<
typename
T
>
struct
ConvertToInt
{
enum
{
enable_conversion
=
sizeof
(
fmt
::
internal
::
convert
(
get
<
T
>
()))
==
sizeof
(
Yes
)
...
...
@@ -1206,16 +1206,16 @@ FMT_DISABLE_CONVERSION_TO_INT(float);
FMT_DISABLE_CONVERSION_TO_INT
(
double
);
FMT_DISABLE_CONVERSION_TO_INT
(
long
double
);
template
<
bool
B
,
class
T
=
void
>
template
<
bool
B
,
class
T
=
void
>
struct
EnableIf
{};
template
<
class
T
>
template
<
class
T
>
struct
EnableIf
<
true
,
T
>
{
typedef
T
type
;
};
template
<
bool
B
,
class
T
,
class
F
>
template
<
bool
B
,
class
T
,
class
F
>
struct
Conditional
{
typedef
T
type
;
};
template
<
class
T
,
class
F
>
template
<
class
T
,
class
F
>
struct
Conditional
<
false
,
T
,
F
>
{
typedef
F
type
;
};
// For bcc32 which doesn't understand ! in template arguments.
...
...
fmt/ostream.h
View file @
3e75d3e0
...
...
@@ -52,13 +52,15 @@ Yes &convert(std::ostream &);
struct
DummyStream
:
std
::
ostream
{
DummyStream
();
// Suppress a bogus warning in MSVC.
// Hide all operator<< overloads from std::ostream.
void
operator
<<
(
Null
<>
);
template
<
typename
T
>
typename
EnableIf
<
sizeof
(
T
)
==
0
>::
type
operator
<<
(
const
T
&
);
};
No
&
operator
<<
(
std
::
ostream
&
,
int
);
template
<
typename
T
>
template
<
typename
T
>
struct
ConvertToIntImpl
<
T
,
true
>
{
// Convert to int only if T doesn't have an overloaded operator<<.
enum
{
...
...
test/ostream-test.cc
View file @
3e75d3e0
...
...
@@ -172,3 +172,18 @@ TEST(OStreamTest, WriteToOStreamMaxSize) {
}
while
(
size
!=
0
);
fmt
::
internal
::
write
(
os
,
w
);
}
struct
ConvertibleToInt
{
template
<
typename
ValueType
>
operator
ValueType
()
const
{
return
0
;
}
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
o
,
ConvertibleToInt
)
{
return
o
<<
"foo"
;
}
};
TEST
(
FormatTest
,
FormatConvertibleToInt
)
{
EXPECT_EQ
(
"foo"
,
fmt
::
format
(
"{}"
,
ConvertibleToInt
()));
}
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