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
67e070fe
Commit
67e070fe
authored
Feb 07, 2018
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make format work with C++17 std::string_view (#571)
parent
64599973
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
16 deletions
+18
-16
include/fmt/core.h
include/fmt/core.h
+17
-10
test/format-test.cc
test/format-test.cc
+0
-5
test/printf-test.cc
test/printf-test.cc
+1
-1
No files found.
include/fmt/core.h
View file @
67e070fe
...
@@ -24,6 +24,12 @@
...
@@ -24,6 +24,12 @@
# define FMT_HAS_FEATURE(x) 0
# define FMT_HAS_FEATURE(x) 0
#endif
#endif
#if defined(__has_include)
# define FMT_HAS_INCLUDE(x) __has_include(x)
#else
# define FMT_HAS_INCLUDE(x) 0
#endif
#ifdef __GNUC__
#ifdef __GNUC__
# define FMT_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
# define FMT_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
#else
#else
...
@@ -137,8 +143,15 @@
...
@@ -137,8 +143,15 @@
Type(const Type &) FMT_DELETED; \
Type(const Type &) FMT_DELETED; \
void operator=(const Type &) FMT_DELETED
void operator=(const Type &) FMT_DELETED
#if (FMT_HAS_INCLUDE(<string_view>) && __cplusplus > 201402L) || \
(defined(_MSVC_LANG) && _MSVC_LANG > 201402L && _MSC_VER >= 1910)
# include <string_view>
namespace
fmt
{
using
std
::
basic_string_view
;
}
#elif (FMT_HAS_INCLUDE(<experimental/string_view>) && __cplusplus >= 201402L)
# include <experimental/string_view>
namespace
fmt
{
using
std
::
experimental
::
basic_string_view
;
}
#else
namespace
fmt
{
namespace
fmt
{
/**
/**
\rst
\rst
An implementation of ``std::basic_string_view`` for pre-C++17. It provides a
An implementation of ``std::basic_string_view`` for pre-C++17. It provides a
...
@@ -180,15 +193,6 @@ class basic_string_view {
...
@@ -180,15 +193,6 @@ class basic_string_view {
const
std
::
basic_string
<
Char
,
Alloc
>
&
s
)
FMT_NOEXCEPT
const
std
::
basic_string
<
Char
,
Alloc
>
&
s
)
FMT_NOEXCEPT
:
data_
(
s
.
c_str
()),
size_
(
s
.
size
())
{}
:
data_
(
s
.
c_str
()),
size_
(
s
.
size
())
{}
/**
\rst
Converts a string reference to an ``std::string`` object.
\endrst
*/
std
::
basic_string
<
Char
>
to_string
()
const
{
return
std
::
basic_string
<
Char
>
(
data_
,
size_
);
}
/** Returns a pointer to the string data. */
/** Returns a pointer to the string data. */
const
Char
*
data
()
const
{
return
data_
;
}
const
Char
*
data
()
const
{
return
data_
;
}
...
@@ -231,7 +235,10 @@ class basic_string_view {
...
@@ -231,7 +235,10 @@ class basic_string_view {
return
lhs
.
compare
(
rhs
)
>=
0
;
return
lhs
.
compare
(
rhs
)
>=
0
;
}
}
};
};
}
// namespace fmt
#endif
namespace
fmt
{
using
string_view
=
basic_string_view
<
char
>
;
using
string_view
=
basic_string_view
<
char
>
;
using
wstring_view
=
basic_string_view
<
wchar_t
>
;
using
wstring_view
=
basic_string_view
<
wchar_t
>
;
...
...
test/format-test.cc
View file @
67e070fe
...
@@ -137,11 +137,6 @@ TEST(StringViewTest, Ctor) {
...
@@ -137,11 +137,6 @@ TEST(StringViewTest, Ctor) {
EXPECT_EQ
(
4u
,
string_view
(
std
::
string
(
"defg"
)).
size
());
EXPECT_EQ
(
4u
,
string_view
(
std
::
string
(
"defg"
)).
size
());
}
}
TEST
(
StringViewTest
,
ConvertToString
)
{
std
::
string
s
=
string_view
(
"abc"
).
to_string
();
EXPECT_EQ
(
"abc"
,
s
);
}
TEST
(
WriterTest
,
NotCopyConstructible
)
{
TEST
(
WriterTest
,
NotCopyConstructible
)
{
EXPECT_FALSE
(
std
::
is_copy_constructible
<
fmt
::
writer
>::
value
);
EXPECT_FALSE
(
std
::
is_copy_constructible
<
fmt
::
writer
>::
value
);
}
}
...
...
test/printf-test.cc
View file @
67e070fe
...
@@ -41,7 +41,7 @@ const unsigned BIG_NUM = INT_MAX + 1u;
...
@@ -41,7 +41,7 @@ const unsigned BIG_NUM = INT_MAX + 1u;
// Makes format string argument positional.
// Makes format string argument positional.
std
::
string
make_positional
(
fmt
::
string_view
format
)
{
std
::
string
make_positional
(
fmt
::
string_view
format
)
{
std
::
string
s
(
format
.
to_string
());
std
::
string
s
(
format
.
data
(),
format
.
size
());
s
.
replace
(
s
.
find
(
'%'
),
1
,
"%1$"
);
s
.
replace
(
s
.
find
(
'%'
),
1
,
"%1$"
);
return
s
;
return
s
;
}
}
...
...
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