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
98751476
Commit
98751476
authored
Aug 22, 2018
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make convert_to_int public (#818)
parent
ba95e36a
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
32 additions
and
28 deletions
+32
-28
CMakeLists.txt
CMakeLists.txt
+10
-6
include/fmt/core.h
include/fmt/core.h
+7
-7
include/fmt/ostream.h
include/fmt/ostream.h
+9
-9
test/core-test.cc
test/core-test.cc
+4
-4
test/ostream-test.cc
test/ostream-test.cc
+2
-2
No files found.
CMakeLists.txt
View file @
98751476
...
@@ -98,7 +98,7 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
...
@@ -98,7 +98,7 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
-Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-reserved-id-macro
-Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-reserved-id-macro
-Wno-global-constructors -Wno-disabled-macro-expansion
-Wno-global-constructors -Wno-disabled-macro-expansion
-Wno-switch-enum -Wno-documentation-unknown-command
-Wno-switch-enum -Wno-documentation-unknown-command
-Wno-
gnu-string-literal-operator-template -Wno-
unused-member-function
-Wno-unused-member-function
-Wno-format-nonliteral -Wno-missing-noreturn -Wno-undefined-func-template
-Wno-format-nonliteral -Wno-missing-noreturn -Wno-undefined-func-template
-Wno-shadow -Wno-sign-conversion -Wno-used-but-marked-unused
-Wno-shadow -Wno-sign-conversion -Wno-used-but-marked-unused
-Wno-covered-switch-default -Wno-missing-variable-declarations
-Wno-covered-switch-default -Wno-missing-variable-declarations
...
@@ -108,13 +108,17 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
...
@@ -108,13 +108,17 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
check_cxx_compiler_flag
(
-Wno-zero-as-null-pointer-constant HAS_NULLPTR_WARNING
)
check_cxx_compiler_flag
(
-Wno-zero-as-null-pointer-constant HAS_NULLPTR_WARNING
)
if
(
HAS_NULLPTR_WARNING
)
if
(
HAS_NULLPTR_WARNING
)
set
(
PEDANTIC_COMPILE_FLAGS
${
PEDANTIC_COMPILE_FLAGS
}
-Wno-zero-as-null-pointer-constant
)
set
(
PEDANTIC_COMPILE_FLAGS
${
PEDANTIC_COMPILE_FLAGS
}
-Wno-zero-as-null-pointer-constant
)
endif
()
endif
()
check_cxx_compiler_flag
(
-Wno-gnu-string-literal-operator-template HAS_GNU_UDL_WARNING
)
endif
()
if
(
HAS_GNU_UDL_WARNING
)
set
(
PEDANTIC_COMPILE_FLAGS
${
PEDANTIC_COMPILE_FLAGS
}
-Wno-gnu-string-literal-operator-template
)
check_cxx_compiler_flag
(
endif
()
-Wno-gnu-string-literal-operator-template HAS_GNU_UDL_WARNING
)
if
(
HAS_GNU_UDL_WARNING
)
set
(
PEDANTIC_COMPILE_FLAGS
${
PEDANTIC_COMPILE_FLAGS
}
-Wno-gnu-string-literal-operator-template
)
endif
()
endif
()
if
(
MSVC
)
if
(
MSVC
)
...
...
include/fmt/core.h
View file @
98751476
...
@@ -341,6 +341,13 @@ class basic_format_args;
...
@@ -341,6 +341,13 @@ class basic_format_args;
template
<
typename
T
,
typename
Char
=
char
,
typename
Enable
=
void
>
template
<
typename
T
,
typename
Char
=
char
,
typename
Enable
=
void
>
struct
formatter
;
struct
formatter
;
template
<
typename
T
,
typename
Char
,
typename
Enable
=
void
>
struct
convert_to_int
{
enum
{
value
=
!
std
::
is_arithmetic
<
T
>::
value
&&
std
::
is_convertible
<
T
,
int
>::
value
};
};
namespace
internal
{
namespace
internal
{
/** A contiguous memory buffer with an optional growing ability. */
/** A contiguous memory buffer with an optional growing ability. */
...
@@ -490,13 +497,6 @@ FMT_CONSTEXPR bool is_arithmetic(type t) {
...
@@ -490,13 +497,6 @@ FMT_CONSTEXPR bool is_arithmetic(type t) {
return
t
>
internal
::
none_type
&&
t
<=
internal
::
last_numeric_type
;
return
t
>
internal
::
none_type
&&
t
<=
internal
::
last_numeric_type
;
}
}
template
<
typename
T
,
typename
Char
,
bool
ENABLE
=
true
>
struct
convert_to_int
{
enum
{
value
=
!
std
::
is_arithmetic
<
T
>::
value
&&
std
::
is_convertible
<
T
,
int
>::
value
};
};
template
<
typename
Char
>
template
<
typename
Char
>
struct
string_value
{
struct
string_value
{
const
Char
*
value
;
const
Char
*
value
;
...
...
include/fmt/ostream.h
View file @
98751476
...
@@ -71,15 +71,6 @@ class is_streamable {
...
@@ -71,15 +71,6 @@ class is_streamable {
static
const
bool
value
=
result
::
value
;
static
const
bool
value
=
result
::
value
;
};
};
// Disable conversion to int if T has an overloaded operator<< which is a free
// function (not a member of std::ostream).
template
<
typename
T
,
typename
Char
>
class
convert_to_int
<
T
,
Char
,
true
>
{
public:
static
const
bool
value
=
convert_to_int
<
T
,
Char
,
false
>::
value
&&
!
is_streamable
<
T
,
Char
>::
value
;
};
// Write the content of buf to os.
// Write the content of buf to os.
template
<
typename
Char
>
template
<
typename
Char
>
void
write
(
std
::
basic_ostream
<
Char
>
&
os
,
basic_buffer
<
Char
>
&
buf
)
{
void
write
(
std
::
basic_ostream
<
Char
>
&
os
,
basic_buffer
<
Char
>
&
buf
)
{
...
@@ -106,6 +97,15 @@ void format_value(basic_buffer<Char> &buffer, const T &value) {
...
@@ -106,6 +97,15 @@ void format_value(basic_buffer<Char> &buffer, const T &value) {
}
}
}
// namespace internal
}
// namespace internal
// Disable conversion to int if T has an overloaded operator<< which is a free
// function (not a member of std::ostream).
template
<
typename
T
,
typename
Char
>
struct
convert_to_int
<
T
,
Char
,
void
>
{
static
const
bool
value
=
convert_to_int
<
T
,
Char
,
int
>::
value
&&
!
internal
::
is_streamable
<
T
,
Char
>::
value
;
};
// Formats an object of type T that has an overloaded ostream operator<<.
// Formats an object of type T that has an overloaded ostream operator<<.
template
<
typename
T
,
typename
Char
>
template
<
typename
T
,
typename
Char
>
struct
formatter
<
T
,
Char
,
struct
formatter
<
T
,
Char
,
...
...
test/core-test.cc
View file @
98751476
...
@@ -851,15 +851,15 @@ TEST(UtilTest, ReportWindowsError) {
...
@@ -851,15 +851,15 @@ TEST(UtilTest, ReportWindowsError) {
enum
TestEnum2
{};
enum
TestEnum2
{};
TEST
(
UtilTest
,
ConvertToInt
)
{
TEST
(
UtilTest
,
ConvertToInt
)
{
EXPECT_FALSE
((
fmt
::
internal
::
convert_to_int
<
char
,
char
>::
value
));
EXPECT_FALSE
((
fmt
::
convert_to_int
<
char
,
char
>::
value
));
EXPECT_FALSE
((
fmt
::
internal
::
convert_to_int
<
const
char
*
,
char
>::
value
));
EXPECT_FALSE
((
fmt
::
convert_to_int
<
const
char
*
,
char
>::
value
));
EXPECT_TRUE
((
fmt
::
internal
::
convert_to_int
<
TestEnum2
,
char
>::
value
));
EXPECT_TRUE
((
fmt
::
convert_to_int
<
TestEnum2
,
char
>::
value
));
}
}
#if FMT_USE_ENUM_BASE
#if FMT_USE_ENUM_BASE
enum
TestEnum
:
char
{
TestValue
};
enum
TestEnum
:
char
{
TestValue
};
TEST
(
UtilTest
,
IsEnumConvertibleToInt
)
{
TEST
(
UtilTest
,
IsEnumConvertibleToInt
)
{
EXPECT_TRUE
((
fmt
::
internal
::
convert_to_int
<
TestEnum
,
char
>::
value
));
EXPECT_TRUE
((
fmt
::
convert_to_int
<
TestEnum
,
char
>::
value
));
}
}
#endif
#endif
...
...
test/ostream-test.cc
View file @
98751476
...
@@ -37,10 +37,10 @@ static std::wostream &operator<<(std::wostream &os, TestEnum) {
...
@@ -37,10 +37,10 @@ static std::wostream &operator<<(std::wostream &os, TestEnum) {
enum
TestEnum2
{
A
};
enum
TestEnum2
{
A
};
TEST
(
OStreamTest
,
Enum
)
{
TEST
(
OStreamTest
,
Enum
)
{
EXPECT_FALSE
((
fmt
::
internal
::
convert_to_int
<
TestEnum
,
char
>::
value
));
EXPECT_FALSE
((
fmt
::
convert_to_int
<
TestEnum
,
char
>::
value
));
EXPECT_EQ
(
"TestEnum"
,
fmt
::
format
(
"{}"
,
TestEnum
()));
EXPECT_EQ
(
"TestEnum"
,
fmt
::
format
(
"{}"
,
TestEnum
()));
EXPECT_EQ
(
"0"
,
fmt
::
format
(
"{}"
,
A
));
EXPECT_EQ
(
"0"
,
fmt
::
format
(
"{}"
,
A
));
EXPECT_FALSE
((
fmt
::
internal
::
convert_to_int
<
TestEnum
,
wchar_t
>::
value
));
EXPECT_FALSE
((
fmt
::
convert_to_int
<
TestEnum
,
wchar_t
>::
value
));
EXPECT_EQ
(
L"TestEnum"
,
fmt
::
format
(
L"{}"
,
TestEnum
()));
EXPECT_EQ
(
L"TestEnum"
,
fmt
::
format
(
L"{}"
,
TestEnum
()));
EXPECT_EQ
(
L"0"
,
fmt
::
format
(
L"{}"
,
A
));
EXPECT_EQ
(
L"0"
,
fmt
::
format
(
L"{}"
,
A
));
}
}
...
...
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