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
e79588d6
Commit
e79588d6
authored
Jan 21, 2018
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace a bunch of craft with type_traits
parent
3a6c7d0c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
9 additions
and
53 deletions
+9
-53
include/fmt/core.h
include/fmt/core.h
+2
-36
include/fmt/ostream.h
include/fmt/ostream.h
+4
-14
test/util-test.cc
test/util-test.cc
+3
-3
No files found.
include/fmt/core.h
View file @
e79588d6
...
...
@@ -336,47 +336,13 @@ inline void require_wchar() {
"formatting of wide characters into a narrow output is disallowed"
);
}
using
yes
=
char
[
1
];
using
no
=
char
[
2
];
yes
&
convert
(
unsigned
long
long
);
no
&
convert
(...);
template
<
typename
T
,
bool
ENABLE_CONVERSION
>
struct
convert_to_int_impl
{
enum
{
value
=
ENABLE_CONVERSION
};
};
template
<
typename
T
,
bool
ENABLE_CONVERSION
>
struct
convert_to_int_impl2
{
enum
{
value
=
false
};
};
template
<
typename
T
>
struct
convert_to_int_impl2
<
T
,
true
>
{
enum
{
// Don't convert arithmetic types.
value
=
convert_to_int_impl
<
T
,
!
std
::
is_arithmetic
<
T
>::
value
>::
value
};
};
template
<
typename
T
>
template
<
typename
T
,
bool
ENABLE
=
true
>
struct
convert_to_int
{
enum
{
enable_conversion
=
sizeof
(
convert
(
std
::
declval
<
T
>
()))
==
sizeof
(
yes
)
value
=
!
std
::
is_arithmetic
<
T
>::
value
&&
std
::
is_convertible
<
T
,
int
>::
value
};
enum
{
value
=
convert_to_int_impl2
<
T
,
enable_conversion
>::
value
};
};
#define FMT_DISABLE_CONVERSION_TO_INT(Type) \
template <> \
struct convert_to_int<Type> { enum { value = 0 }; }
// Silence warnings about convering float to int.
FMT_DISABLE_CONVERSION_TO_INT
(
float
);
FMT_DISABLE_CONVERSION_TO_INT
(
double
);
FMT_DISABLE_CONVERSION_TO_INT
(
long
double
);
template
<
typename
Char
>
struct
named_arg_base
;
...
...
include/fmt/ostream.h
View file @
e79588d6
...
...
@@ -47,22 +47,12 @@ class FormatBuf : public std::basic_streambuf<Char> {
}
};
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
<>
);
};
no
&
operator
<<
(
std
::
ostream
&
,
int
);
template
<
typename
T
>
struct
convert_to_int_impl
<
T
,
true
>
{
template
<
typename
T
>
struct
convert_to_int
<
T
,
sizeof
(
std
::
declval
<
std
::
ostream
>
()
<<
std
::
declval
<
T
>
())
!=
0
>
{
// Convert to int only if T doesn't have an overloaded operator<<.
enum
{
value
=
sizeof
(
convert
(
std
::
declval
<
DummyStream
&>
()
<<
std
::
declval
<
T
>
()))
==
sizeof
(
no
)
value
=
false
};
};
...
...
test/util-test.cc
View file @
e79588d6
...
...
@@ -827,15 +827,15 @@ TEST(UtilTest, ReportWindowsError) {
enum
TestEnum2
{};
TEST
(
UtilTest
,
ConvertToInt
)
{
EXPECT_
TRUE
(
fmt
::
internal
::
convert_to_int
<
char
>::
enable_conversion
);
EXPECT_FALSE
(
fmt
::
internal
::
convert_to_int
<
const
char
*>::
enable_conversion
);
EXPECT_
FALSE
(
fmt
::
internal
::
convert_to_int
<
char
>::
value
);
EXPECT_FALSE
(
fmt
::
internal
::
convert_to_int
<
const
char
*>::
value
);
EXPECT_TRUE
(
fmt
::
internal
::
convert_to_int
<
TestEnum2
>::
value
);
}
#if FMT_USE_ENUM_BASE
enum
TestEnum
:
char
{
TestValue
};
TEST
(
UtilTest
,
IsEnumConvertibleToInt
)
{
EXPECT_TRUE
(
fmt
::
internal
::
convert_to_int
<
TestEnum
>::
enable_conversion
);
EXPECT_TRUE
(
fmt
::
internal
::
convert_to_int
<
TestEnum
>::
value
);
}
#endif
...
...
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