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
838400d2
Commit
838400d2
authored
May 12, 2018
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add inline namespace fmt::v5
parent
b64b24eb
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
73 additions
and
61 deletions
+73
-61
include/fmt/core.h
include/fmt/core.h
+12
-3
include/fmt/format-inl.h
include/fmt/format-inl.h
+2
-2
include/fmt/format.h
include/fmt/format.h
+9
-12
include/fmt/locale.h
include/fmt/locale.h
+7
-2
include/fmt/ostream.h
include/fmt/ostream.h
+2
-4
include/fmt/posix.h
include/fmt/posix.h
+3
-3
include/fmt/printf.h
include/fmt/printf.h
+2
-2
include/fmt/time.h
include/fmt/time.h
+2
-2
src/format.cc
src/format.cc
+2
-2
src/posix.cc
src/posix.cc
+22
-19
test/format-test.cc
test/format-test.cc
+6
-6
test/util-test.cc
test/util-test.cc
+4
-4
No files found.
include/fmt/core.h
View file @
838400d2
...
@@ -133,6 +133,15 @@
...
@@ -133,6 +133,15 @@
# define FMT_DTOR_NOEXCEPT FMT_NOEXCEPT
# define FMT_DTOR_NOEXCEPT FMT_NOEXCEPT
#endif
#endif
#if FMT_HAS_FEATURE(cxx_inline_namespaces) || FMT_MSC_VER >= 1900
# define FMT_INLINE_NAMESPACE inline namespace
# define FMT_END_NAMESPACE }}
#else
# define FMT_INLINE_NAMESPACE namespace
# define FMT_END_NAMESPACE } using namespace v5; }
#endif
#define FMT_BEGIN_NAMESPACE namespace fmt { FMT_INLINE_NAMESPACE v5 {
#if !defined(FMT_HEADER_ONLY) && defined(_WIN32)
#if !defined(FMT_HEADER_ONLY) && defined(_WIN32)
# ifdef FMT_EXPORT
# ifdef FMT_EXPORT
# define FMT_API __declspec(dllexport)
# define FMT_API __declspec(dllexport)
...
@@ -172,7 +181,7 @@
...
@@ -172,7 +181,7 @@
# include <functional>
# include <functional>
#endif
#endif
namespace
fmt
{
FMT_BEGIN_NAMESPACE
// An implementation of declval for pre-C++11 compilers such as gcc 4.
// An implementation of declval for pre-C++11 compilers such as gcc 4.
namespace
internal
{
namespace
internal
{
...
@@ -1190,7 +1199,7 @@ template <typename Char>
...
@@ -1190,7 +1199,7 @@ template <typename Char>
struct
is_contiguous
<
std
::
basic_string
<
Char
>>
:
std
::
true_type
{};
struct
is_contiguous
<
std
::
basic_string
<
Char
>>
:
std
::
true_type
{};
template
<
typename
Char
>
template
<
typename
Char
>
struct
is_contiguous
<
fmt
::
internal
::
basic_buffer
<
Char
>>
:
std
::
true_type
{};
struct
is_contiguous
<
internal
::
basic_buffer
<
Char
>>
:
std
::
true_type
{};
/** Formats a string and writes the output to ``out``. */
/** Formats a string and writes the output to ``out``. */
template
<
typename
Container
>
template
<
typename
Container
>
...
@@ -1288,6 +1297,6 @@ inline void print(wstring_view format_str, const Args & ... args) {
...
@@ -1288,6 +1297,6 @@ inline void print(wstring_view format_str, const Args & ... args) {
format_arg_store
<
wformat_context
,
Args
...
>
as
(
args
...);
format_arg_store
<
wformat_context
,
Args
...
>
as
(
args
...);
vprint
(
format_str
,
as
);
vprint
(
format_str
,
as
);
}
}
}
// namespace fmt
FMT_END_NAMESPACE
#endif // FMT_CORE_H_
#endif // FMT_CORE_H_
include/fmt/format-inl.h
View file @
838400d2
...
@@ -69,7 +69,7 @@ inline fmt::internal::null<> strerror_s(char *, std::size_t, ...) {
...
@@ -69,7 +69,7 @@ inline fmt::internal::null<> strerror_s(char *, std::size_t, ...) {
return
fmt
::
internal
::
null
<>
();
return
fmt
::
internal
::
null
<>
();
}
}
namespace
fmt
{
FMT_BEGIN_NAMESPACE
FMT_FUNC
format_error
::~
format_error
()
throw
()
{}
FMT_FUNC
format_error
::~
format_error
()
throw
()
{}
FMT_FUNC
system_error
::~
system_error
()
FMT_DTOR_NOEXCEPT
{}
FMT_FUNC
system_error
::~
system_error
()
FMT_DTOR_NOEXCEPT
{}
...
@@ -522,7 +522,7 @@ FMT_FUNC void vprint_colored(color c, wstring_view format, wformat_args args) {
...
@@ -522,7 +522,7 @@ FMT_FUNC void vprint_colored(color c, wstring_view format, wformat_args args) {
FMT_FUNC
locale
locale_provider
::
locale
()
{
return
fmt
::
locale
();
}
FMT_FUNC
locale
locale_provider
::
locale
()
{
return
fmt
::
locale
();
}
}
// namespace fmt
FMT_END_NAMESPACE
#ifdef _MSC_VER
#ifdef _MSC_VER
# pragma warning(pop)
# pragma warning(pop)
...
...
include/fmt/format.h
View file @
838400d2
...
@@ -161,7 +161,7 @@
...
@@ -161,7 +161,7 @@
#if FMT_MSC_VER && !defined(FMT_BUILTIN_CLZLL) && !defined(_MANAGED)
#if FMT_MSC_VER && !defined(FMT_BUILTIN_CLZLL) && !defined(_MANAGED)
# include <intrin.h> // _BitScanReverse, _BitScanReverse64
# include <intrin.h> // _BitScanReverse, _BitScanReverse64
namespace
fmt
{
FMT_BEGIN_NAMESPACE
namespace
internal
{
namespace
internal
{
// Avoid Clang with Microsoft CodeGen's -Wunknown-pragmas warning.
// Avoid Clang with Microsoft CodeGen's -Wunknown-pragmas warning.
# ifndef __clang__
# ifndef __clang__
...
@@ -206,10 +206,10 @@ inline uint32_t clzll(uint64_t x) {
...
@@ -206,10 +206,10 @@ inline uint32_t clzll(uint64_t x) {
}
}
# define FMT_BUILTIN_CLZLL(n) fmt::internal::clzll(n)
# define FMT_BUILTIN_CLZLL(n) fmt::internal::clzll(n)
}
}
}
FMT_END_NAMESPACE
#endif
#endif
namespace
fmt
{
FMT_BEGIN_NAMESPACE
namespace
internal
{
namespace
internal
{
// An equivalent of `*reinterpret_cast<Dest*>(&source)` that doesn't produce
// An equivalent of `*reinterpret_cast<Dest*>(&source)` that doesn't produce
...
@@ -246,7 +246,7 @@ struct dummy_int {
...
@@ -246,7 +246,7 @@ struct dummy_int {
int
data
[
2
];
int
data
[
2
];
operator
int
()
const
{
return
0
;
}
operator
int
()
const
{
return
0
;
}
};
};
typedef
std
::
numeric_limits
<
fmt
::
internal
::
dummy_int
>
fputil
;
typedef
std
::
numeric_limits
<
internal
::
dummy_int
>
fputil
;
// Dummy implementations of system functions such as signbit and ecvt called
// Dummy implementations of system functions such as signbit and ecvt called
// if the latter are not available.
// if the latter are not available.
...
@@ -322,7 +322,7 @@ typename Allocator::value_type *allocate(Allocator& alloc, std::size_t n) {
...
@@ -322,7 +322,7 @@ typename Allocator::value_type *allocate(Allocator& alloc, std::size_t n) {
template
<
typename
T
>
template
<
typename
T
>
inline
T
const_check
(
T
value
)
{
return
value
;
}
inline
T
const_check
(
T
value
)
{
return
value
;
}
}
// namespace internal
}
// namespace internal
}
// namespace fmt
FMT_END_NAMESPACE
namespace
std
{
namespace
std
{
// Standard permits specialization of std::numeric_limits. This specialization
// Standard permits specialization of std::numeric_limits. This specialization
...
@@ -339,7 +339,7 @@ class numeric_limits<fmt::internal::dummy_int> :
...
@@ -339,7 +339,7 @@ class numeric_limits<fmt::internal::dummy_int> :
using
namespace
fmt
::
internal
;
using
namespace
fmt
::
internal
;
// The resolution "priority" is:
// The resolution "priority" is:
// isinf macro > std::isinf > ::isinf > fmt::internal::isinf
// isinf macro > std::isinf > ::isinf > fmt::internal::isinf
if
(
const_check
(
sizeof
(
isinf
(
x
))
!=
sizeof
(
fmt
::
internal
::
dummy_int
)))
if
(
const_check
(
sizeof
(
isinf
(
x
))
!=
sizeof
(
dummy_int
)))
return
isinf
(
x
)
!=
0
;
return
isinf
(
x
)
!=
0
;
return
!
_finite
(
static_cast
<
double
>
(
x
));
return
!
_finite
(
static_cast
<
double
>
(
x
));
}
}
...
@@ -368,8 +368,7 @@ class numeric_limits<fmt::internal::dummy_int> :
...
@@ -368,8 +368,7 @@ class numeric_limits<fmt::internal::dummy_int> :
};
};
}
// namespace std
}
// namespace std
namespace
fmt
{
FMT_BEGIN_NAMESPACE
template
<
typename
Range
>
template
<
typename
Range
>
class
basic_writer
;
class
basic_writer
;
...
@@ -2328,7 +2327,7 @@ class system_error : public std::runtime_error {
...
@@ -2328,7 +2327,7 @@ class system_error : public std::runtime_error {
may look like "Unknown error -1" and is platform-dependent.
may look like "Unknown error -1" and is platform-dependent.
\endrst
\endrst
*/
*/
FMT_API
void
format_system_error
(
fmt
::
internal
::
buffer
&
out
,
int
error_code
,
FMT_API
void
format_system_error
(
internal
::
buffer
&
out
,
int
error_code
,
fmt
::
string_view
message
)
FMT_NOEXCEPT
;
fmt
::
string_view
message
)
FMT_NOEXCEPT
;
/**
/**
...
@@ -3527,10 +3526,8 @@ inline std::size_t formatted_size(string_view format_str,
...
@@ -3527,10 +3526,8 @@ inline std::size_t formatted_size(string_view format_str,
auto
it
=
format_to
(
internal
::
counting_iterator
<
char
>
(),
format_str
,
args
...);
auto
it
=
format_to
(
internal
::
counting_iterator
<
char
>
(),
format_str
,
args
...);
return
it
.
count
();
return
it
.
count
();
}
}
}
// namespace fmt
#if FMT_USE_USER_DEFINED_LITERALS
#if FMT_USE_USER_DEFINED_LITERALS
namespace
fmt
{
namespace
internal
{
namespace
internal
{
# if FMT_UDL_TEMPLATE
# if FMT_UDL_TEMPLATE
...
@@ -3611,8 +3608,8 @@ operator"" _a(const char *s, std::size_t) { return {s}; }
...
@@ -3611,8 +3608,8 @@ operator"" _a(const char *s, std::size_t) { return {s}; }
inline
internal
::
udl_arg
<
wchar_t
>
inline
internal
::
udl_arg
<
wchar_t
>
operator
""
_a
(
const
wchar_t
*
s
,
std
::
size_t
)
{
return
{
s
};
}
operator
""
_a
(
const
wchar_t
*
s
,
std
::
size_t
)
{
return
{
s
};
}
}
// inline namespace literals
}
// inline namespace literals
}
// namespace fmt
#endif // FMT_USE_USER_DEFINED_LITERALS
#endif // FMT_USE_USER_DEFINED_LITERALS
FMT_END_NAMESPACE
#define FMT_STRING(s) [] { \
#define FMT_STRING(s) [] { \
struct S : fmt::format_string { \
struct S : fmt::format_string { \
...
...
include/fmt/locale.h
View file @
838400d2
...
@@ -5,10 +5,13 @@
...
@@ -5,10 +5,13 @@
//
//
// For the license information refer to format.h.
// For the license information refer to format.h.
#ifndef FMT_LOCALE_H_
#define FMT_LOCALE_H_
#include "format.h"
#include "format.h"
#include <locale>
#include <locale>
namespace
fmt
{
FMT_BEGIN_NAMESPACE
class
locale
{
class
locale
{
private:
private:
std
::
locale
locale_
;
std
::
locale
locale_
;
...
@@ -17,4 +20,6 @@ class locale {
...
@@ -17,4 +20,6 @@ class locale {
explicit
locale
(
std
::
locale
loc
=
std
::
locale
())
:
locale_
(
loc
)
{}
explicit
locale
(
std
::
locale
loc
=
std
::
locale
())
:
locale_
(
loc
)
{}
std
::
locale
get
()
{
return
locale_
;
}
std
::
locale
get
()
{
return
locale_
;
}
};
};
}
FMT_END_NAMESPACE
#endif // FMT_LOCALE_
include/fmt/ostream.h
View file @
838400d2
...
@@ -11,8 +11,7 @@
...
@@ -11,8 +11,7 @@
#include "format.h"
#include "format.h"
#include <ostream>
#include <ostream>
namespace
fmt
{
FMT_BEGIN_NAMESPACE
namespace
internal
{
namespace
internal
{
template
<
class
Char
>
template
<
class
Char
>
...
@@ -149,7 +148,6 @@ inline void print(std::wostream &os, wstring_view format_str,
...
@@ -149,7 +148,6 @@ inline void print(std::wostream &os, wstring_view format_str,
const
Args
&
...
args
)
{
const
Args
&
...
args
)
{
vprint
(
os
,
format_str
,
make_format_args
<
wformat_context
>
(
args
...));
vprint
(
os
,
format_str
,
make_format_args
<
wformat_context
>
(
args
...));
}
}
FMT_END_NAMESPACE
}
// namespace fmt
#endif // FMT_OSTREAM_H_
#endif // FMT_OSTREAM_H_
include/fmt/posix.h
View file @
838400d2
...
@@ -62,7 +62,7 @@
...
@@ -62,7 +62,7 @@
#define FMT_RETRY(result, expression) FMT_RETRY_VAL(result, expression, -1)
#define FMT_RETRY(result, expression) FMT_RETRY_VAL(result, expression, -1)
namespace
fmt
{
FMT_BEGIN_NAMESPACE
/**
/**
\rst
\rst
...
@@ -388,7 +388,7 @@ class Locale {
...
@@ -388,7 +388,7 @@ class Locale {
Locale
()
:
locale_
(
newlocale
(
LC_NUMERIC_MASK
,
"C"
,
FMT_NULL
))
{
Locale
()
:
locale_
(
newlocale
(
LC_NUMERIC_MASK
,
"C"
,
FMT_NULL
))
{
if
(
!
locale_
)
if
(
!
locale_
)
FMT_THROW
(
fmt
::
system_error
(
errno
,
"cannot create locale"
));
FMT_THROW
(
system_error
(
errno
,
"cannot create locale"
));
}
}
~
Locale
()
{
freelocale
(
locale_
);
}
~
Locale
()
{
freelocale
(
locale_
);
}
...
@@ -404,7 +404,7 @@ class Locale {
...
@@ -404,7 +404,7 @@ class Locale {
}
}
};
};
#endif // FMT_LOCALE
#endif // FMT_LOCALE
}
// namespace fmt
FMT_END_NAMESPACE
#if !FMT_USE_RVALUE_REFERENCES
#if !FMT_USE_RVALUE_REFERENCES
namespace
std
{
namespace
std
{
...
...
include/fmt/printf.h
View file @
838400d2
...
@@ -13,7 +13,7 @@
...
@@ -13,7 +13,7 @@
#include "ostream.h"
#include "ostream.h"
namespace
fmt
{
FMT_BEGIN_NAMESPACE
namespace
internal
{
namespace
internal
{
// Checks if a value fits in int - used to avoid warnings about comparing
// Checks if a value fits in int - used to avoid warnings about comparing
...
@@ -706,6 +706,6 @@ inline int fprintf(std::wostream &os, wstring_view format_str,
...
@@ -706,6 +706,6 @@ inline int fprintf(std::wostream &os, wstring_view format_str,
typename
printf_context
<
internal
::
buffer
>::
type
>
(
args
...);
typename
printf_context
<
internal
::
buffer
>::
type
>
(
args
...);
return
vfprintf
(
os
,
format_str
,
vargs
);
return
vfprintf
(
os
,
format_str
,
vargs
);
}
}
}
// namespace fmt
FMT_END_NAMESPACE
#endif // FMT_PRINTF_H_
#endif // FMT_PRINTF_H_
include/fmt/time.h
View file @
838400d2
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
#include "format.h"
#include "format.h"
#include <ctime>
#include <ctime>
namespace
fmt
{
FMT_BEGIN_NAMESPACE
namespace
internal
{
namespace
internal
{
inline
null
<>
localtime_r
(...)
{
return
null
<>
();
}
inline
null
<>
localtime_r
(...)
{
return
null
<>
();
}
...
@@ -146,6 +146,6 @@ struct formatter<std::tm, Char> {
...
@@ -146,6 +146,6 @@ struct formatter<std::tm, Char> {
basic_memory_buffer
<
Char
>
tm_format
;
basic_memory_buffer
<
Char
>
tm_format
;
};
};
}
FMT_END_NAMESPACE
#endif // FMT_TIME_H_
#endif // FMT_TIME_H_
src/format.cc
View file @
838400d2
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
#include "fmt/format-inl.h"
#include "fmt/format-inl.h"
namespace
fmt
{
FMT_BEGIN_NAMESPACE
template
struct
internal
::
basic_data
<
void
>;
template
struct
internal
::
basic_data
<
void
>;
...
@@ -44,4 +44,4 @@ template FMT_API int internal::char_traits<wchar_t>::format_float(
...
@@ -44,4 +44,4 @@ template FMT_API int internal::char_traits<wchar_t>::format_float(
template
FMT_API
int
internal
::
char_traits
<
wchar_t
>
::
format_float
(
template
FMT_API
int
internal
::
char_traits
<
wchar_t
>
::
format_float
(
wchar_t
*
buffer
,
std
::
size_t
size
,
const
wchar_t
*
format
,
wchar_t
*
buffer
,
std
::
size_t
size
,
const
wchar_t
*
format
,
unsigned
width
,
int
precision
,
long
double
value
);
unsigned
width
,
int
precision
,
long
double
value
);
}
// namespace fmt
FMT_END_NAMESPACE
src/posix.cc
View file @
838400d2
...
@@ -64,20 +64,21 @@ inline std::size_t convert_rwcount(std::size_t count) { return count; }
...
@@ -64,20 +64,21 @@ inline std::size_t convert_rwcount(std::size_t count) { return count; }
#endif
#endif
}
}
fmt
::
BufferedFile
::~
BufferedFile
()
FMT_NOEXCEPT
{
FMT_BEGIN_NAMESPACE
BufferedFile
::~
BufferedFile
()
FMT_NOEXCEPT
{
if
(
file_
&&
FMT_SYSTEM
(
fclose
(
file_
))
!=
0
)
if
(
file_
&&
FMT_SYSTEM
(
fclose
(
file_
))
!=
0
)
fmt
::
report_system_error
(
errno
,
"cannot close file"
);
report_system_error
(
errno
,
"cannot close file"
);
}
}
fmt
::
BufferedFile
::
BufferedFile
(
BufferedFile
::
BufferedFile
(
cstring_view
filename
,
cstring_view
mode
)
{
fmt
::
cstring_view
filename
,
fmt
::
cstring_view
mode
)
{
FMT_RETRY_VAL
(
file_
,
FMT_RETRY_VAL
(
file_
,
FMT_SYSTEM
(
fopen
(
filename
.
c_str
(),
mode
.
c_str
())),
FMT_NULL
);
FMT_SYSTEM
(
fopen
(
filename
.
c_str
(),
mode
.
c_str
())),
FMT_NULL
);
if
(
!
file_
)
if
(
!
file_
)
FMT_THROW
(
system_error
(
errno
,
"cannot open file {}"
,
filename
.
c_str
()));
FMT_THROW
(
system_error
(
errno
,
"cannot open file {}"
,
filename
.
c_str
()));
}
}
void
fmt
::
BufferedFile
::
close
()
{
void
BufferedFile
::
close
()
{
if
(
!
file_
)
if
(
!
file_
)
return
;
return
;
int
result
=
FMT_SYSTEM
(
fclose
(
file_
));
int
result
=
FMT_SYSTEM
(
fclose
(
file_
));
...
@@ -89,14 +90,14 @@ void fmt::BufferedFile::close() {
...
@@ -89,14 +90,14 @@ void fmt::BufferedFile::close() {
// A macro used to prevent expansion of fileno on broken versions of MinGW.
// A macro used to prevent expansion of fileno on broken versions of MinGW.
#define FMT_ARGS
#define FMT_ARGS
int
fmt
::
BufferedFile
::
fileno
()
const
{
int
BufferedFile
::
fileno
()
const
{
int
fd
=
FMT_POSIX_CALL
(
fileno
FMT_ARGS
(
file_
));
int
fd
=
FMT_POSIX_CALL
(
fileno
FMT_ARGS
(
file_
));
if
(
fd
==
-
1
)
if
(
fd
==
-
1
)
FMT_THROW
(
system_error
(
errno
,
"cannot get file descriptor"
));
FMT_THROW
(
system_error
(
errno
,
"cannot get file descriptor"
));
return
fd
;
return
fd
;
}
}
fmt
::
File
::
File
(
fmt
::
cstring_view
path
,
int
oflag
)
{
File
::
File
(
cstring_view
path
,
int
oflag
)
{
int
mode
=
S_IRUSR
|
S_IWUSR
;
int
mode
=
S_IRUSR
|
S_IWUSR
;
#if defined(_WIN32) && !defined(__MINGW32__)
#if defined(_WIN32) && !defined(__MINGW32__)
fd_
=
-
1
;
fd_
=
-
1
;
...
@@ -108,14 +109,14 @@ fmt::File::File(fmt::cstring_view path, int oflag) {
...
@@ -108,14 +109,14 @@ fmt::File::File(fmt::cstring_view path, int oflag) {
FMT_THROW
(
system_error
(
errno
,
"cannot open file {}"
,
path
.
c_str
()));
FMT_THROW
(
system_error
(
errno
,
"cannot open file {}"
,
path
.
c_str
()));
}
}
fmt
::
File
::~
File
()
FMT_NOEXCEPT
{
File
::~
File
()
FMT_NOEXCEPT
{
// Don't retry close in case of EINTR!
// Don't retry close in case of EINTR!
// See http://linux.derkeiler.com/Mailing-Lists/Kernel/2005-09/3000.html
// See http://linux.derkeiler.com/Mailing-Lists/Kernel/2005-09/3000.html
if
(
fd_
!=
-
1
&&
FMT_POSIX_CALL
(
close
(
fd_
))
!=
0
)
if
(
fd_
!=
-
1
&&
FMT_POSIX_CALL
(
close
(
fd_
))
!=
0
)
fmt
::
report_system_error
(
errno
,
"cannot close file"
);
report_system_error
(
errno
,
"cannot close file"
);
}
}
void
fmt
::
File
::
close
()
{
void
File
::
close
()
{
if
(
fd_
==
-
1
)
if
(
fd_
==
-
1
)
return
;
return
;
// Don't retry close in case of EINTR!
// Don't retry close in case of EINTR!
...
@@ -126,7 +127,7 @@ void fmt::File::close() {
...
@@ -126,7 +127,7 @@ void fmt::File::close() {
FMT_THROW
(
system_error
(
errno
,
"cannot close file"
));
FMT_THROW
(
system_error
(
errno
,
"cannot close file"
));
}
}
long
long
fmt
::
File
::
size
()
const
{
long
long
File
::
size
()
const
{
#ifdef _WIN32
#ifdef _WIN32
// Use GetFileSize instead of GetFileSizeEx for the case when _WIN32_WINNT
// Use GetFileSize instead of GetFileSizeEx for the case when _WIN32_WINNT
// is less than 0x0500 as is the case with some default MinGW builds.
// is less than 0x0500 as is the case with some default MinGW builds.
...
@@ -152,7 +153,7 @@ long long fmt::File::size() const {
...
@@ -152,7 +153,7 @@ long long fmt::File::size() const {
#endif
#endif
}
}
std
::
size_t
fmt
::
File
::
read
(
void
*
buffer
,
std
::
size_t
count
)
{
std
::
size_t
File
::
read
(
void
*
buffer
,
std
::
size_t
count
)
{
RWResult
result
=
0
;
RWResult
result
=
0
;
FMT_RETRY
(
result
,
FMT_POSIX_CALL
(
read
(
fd_
,
buffer
,
convert_rwcount
(
count
))));
FMT_RETRY
(
result
,
FMT_POSIX_CALL
(
read
(
fd_
,
buffer
,
convert_rwcount
(
count
))));
if
(
result
<
0
)
if
(
result
<
0
)
...
@@ -160,7 +161,7 @@ std::size_t fmt::File::read(void *buffer, std::size_t count) {
...
@@ -160,7 +161,7 @@ std::size_t fmt::File::read(void *buffer, std::size_t count) {
return
internal
::
to_unsigned
(
result
);
return
internal
::
to_unsigned
(
result
);
}
}
std
::
size_t
fmt
::
File
::
write
(
const
void
*
buffer
,
std
::
size_t
count
)
{
std
::
size_t
File
::
write
(
const
void
*
buffer
,
std
::
size_t
count
)
{
RWResult
result
=
0
;
RWResult
result
=
0
;
FMT_RETRY
(
result
,
FMT_POSIX_CALL
(
write
(
fd_
,
buffer
,
convert_rwcount
(
count
))));
FMT_RETRY
(
result
,
FMT_POSIX_CALL
(
write
(
fd_
,
buffer
,
convert_rwcount
(
count
))));
if
(
result
<
0
)
if
(
result
<
0
)
...
@@ -168,7 +169,7 @@ std::size_t fmt::File::write(const void *buffer, std::size_t count) {
...
@@ -168,7 +169,7 @@ std::size_t fmt::File::write(const void *buffer, std::size_t count) {
return
internal
::
to_unsigned
(
result
);
return
internal
::
to_unsigned
(
result
);
}
}
fmt
::
File
fmt
::
File
::
dup
(
int
fd
)
{
File
File
::
dup
(
int
fd
)
{
// Don't retry as dup doesn't return EINTR.
// Don't retry as dup doesn't return EINTR.
// http://pubs.opengroup.org/onlinepubs/009695399/functions/dup.html
// http://pubs.opengroup.org/onlinepubs/009695399/functions/dup.html
int
new_fd
=
FMT_POSIX_CALL
(
dup
(
fd
));
int
new_fd
=
FMT_POSIX_CALL
(
dup
(
fd
));
...
@@ -177,7 +178,7 @@ fmt::File fmt::File::dup(int fd) {
...
@@ -177,7 +178,7 @@ fmt::File fmt::File::dup(int fd) {
return
File
(
new_fd
);
return
File
(
new_fd
);
}
}
void
fmt
::
File
::
dup2
(
int
fd
)
{
void
File
::
dup2
(
int
fd
)
{
int
result
=
0
;
int
result
=
0
;
FMT_RETRY
(
result
,
FMT_POSIX_CALL
(
dup2
(
fd_
,
fd
)));
FMT_RETRY
(
result
,
FMT_POSIX_CALL
(
dup2
(
fd_
,
fd
)));
if
(
result
==
-
1
)
{
if
(
result
==
-
1
)
{
...
@@ -186,14 +187,14 @@ void fmt::File::dup2(int fd) {
...
@@ -186,14 +187,14 @@ void fmt::File::dup2(int fd) {
}
}
}
}
void
fmt
::
File
::
dup2
(
int
fd
,
ErrorCode
&
ec
)
FMT_NOEXCEPT
{
void
File
::
dup2
(
int
fd
,
ErrorCode
&
ec
)
FMT_NOEXCEPT
{
int
result
=
0
;
int
result
=
0
;
FMT_RETRY
(
result
,
FMT_POSIX_CALL
(
dup2
(
fd_
,
fd
)));
FMT_RETRY
(
result
,
FMT_POSIX_CALL
(
dup2
(
fd_
,
fd
)));
if
(
result
==
-
1
)
if
(
result
==
-
1
)
ec
=
ErrorCode
(
errno
);
ec
=
ErrorCode
(
errno
);
}
}
void
fmt
::
File
::
pipe
(
File
&
read_end
,
File
&
write_end
)
{
void
File
::
pipe
(
File
&
read_end
,
File
&
write_end
)
{
// Close the descriptors first to make sure that assignments don't throw
// Close the descriptors first to make sure that assignments don't throw
// and there are no leaks.
// and there are no leaks.
read_end
.
close
();
read_end
.
close
();
...
@@ -216,7 +217,7 @@ void fmt::File::pipe(File &read_end, File &write_end) {
...
@@ -216,7 +217,7 @@ void fmt::File::pipe(File &read_end, File &write_end) {
write_end
=
File
(
fds
[
1
]);
write_end
=
File
(
fds
[
1
]);
}
}
fmt
::
BufferedFile
fmt
::
File
::
fdopen
(
const
char
*
mode
)
{
BufferedFile
File
::
fdopen
(
const
char
*
mode
)
{
// Don't retry as fdopen doesn't return EINTR.
// Don't retry as fdopen doesn't return EINTR.
FILE
*
f
=
FMT_POSIX_CALL
(
fdopen
(
fd_
,
mode
));
FILE
*
f
=
FMT_POSIX_CALL
(
fdopen
(
fd_
,
mode
));
if
(
!
f
)
if
(
!
f
)
...
@@ -227,7 +228,7 @@ fmt::BufferedFile fmt::File::fdopen(const char *mode) {
...
@@ -227,7 +228,7 @@ fmt::BufferedFile fmt::File::fdopen(const char *mode) {
return
file
;
return
file
;
}
}
long
fmt
::
getpagesize
()
{
long
getpagesize
()
{
#ifdef _WIN32
#ifdef _WIN32
SYSTEM_INFO
si
;
SYSTEM_INFO
si
;
GetSystemInfo
(
&
si
);
GetSystemInfo
(
&
si
);
...
@@ -239,3 +240,5 @@ long fmt::getpagesize() {
...
@@ -239,3 +240,5 @@ long fmt::getpagesize() {
return
size
;
return
size
;
#endif
#endif
}
}
FMT_END_NAMESPACE
test/format-test.cc
View file @
838400d2
...
@@ -1090,7 +1090,7 @@ TEST(FormatterTest, FormatConvertibleToStringView) {
...
@@ -1090,7 +1090,7 @@ TEST(FormatterTest, FormatConvertibleToStringView) {
EXPECT_EQ
(
"foo"
,
format
(
"{}"
,
ConvertibleToStringView
()));
EXPECT_EQ
(
"foo"
,
format
(
"{}"
,
ConvertibleToStringView
()));
}
}
namespace
fmt
{
FMT_BEGIN_NAMESPACE
template
<
>
template
<
>
struct
formatter
<
Date
>
{
struct
formatter
<
Date
>
{
template
<
typename
ParseContext
>
template
<
typename
ParseContext
>
...
@@ -1106,7 +1106,7 @@ struct formatter<Date> {
...
@@ -1106,7 +1106,7 @@ struct formatter<Date> {
return
ctx
.
out
();
return
ctx
.
out
();
}
}
};
};
}
FMT_END_NAMESPACE
TEST
(
FormatterTest
,
FormatCustom
)
{
TEST
(
FormatterTest
,
FormatCustom
)
{
Date
date
(
2012
,
12
,
9
);
Date
date
(
2012
,
12
,
9
);
...
@@ -1116,14 +1116,14 @@ TEST(FormatterTest, FormatCustom) {
...
@@ -1116,14 +1116,14 @@ TEST(FormatterTest, FormatCustom) {
class
Answer
{};
class
Answer
{};
namespace
fmt
{
FMT_BEGIN_NAMESPACE
template
<
>
template
<
>
struct
formatter
<
Answer
>
:
formatter
<
int
>
{
struct
formatter
<
Answer
>
:
formatter
<
int
>
{
auto
format
(
Answer
,
fmt
::
format_context
&
ctx
)
->
decltype
(
ctx
.
out
())
{
auto
format
(
Answer
,
fmt
::
format_context
&
ctx
)
->
decltype
(
ctx
.
out
())
{
return
formatter
<
int
>::
format
(
42
,
ctx
);
return
formatter
<
int
>::
format
(
42
,
ctx
);
}
}
};
};
}
FMT_END_NAMESPACE
TEST
(
FormatterTest
,
CustomFormat
)
{
TEST
(
FormatterTest
,
CustomFormat
)
{
EXPECT_EQ
(
"42"
,
format
(
"{0}"
,
Answer
()));
EXPECT_EQ
(
"42"
,
format
(
"{0}"
,
Answer
()));
...
@@ -1455,7 +1455,7 @@ struct variant {
...
@@ -1455,7 +1455,7 @@ struct variant {
explicit
variant
(
const
char
*
)
:
type
(
STRING
)
{}
explicit
variant
(
const
char
*
)
:
type
(
STRING
)
{}
};
};
namespace
fmt
{
FMT_BEGIN_NAMESPACE
template
<
>
template
<
>
struct
formatter
<
variant
>
:
dynamic_formatter
<>
{
struct
formatter
<
variant
>
:
dynamic_formatter
<>
{
auto
format
(
variant
value
,
format_context
&
ctx
)
->
decltype
(
ctx
.
out
())
{
auto
format
(
variant
value
,
format_context
&
ctx
)
->
decltype
(
ctx
.
out
())
{
...
@@ -1464,7 +1464,7 @@ struct formatter<variant> : dynamic_formatter<> {
...
@@ -1464,7 +1464,7 @@ struct formatter<variant> : dynamic_formatter<> {
return
dynamic_formatter
<>::
format
(
"foo"
,
ctx
);
return
dynamic_formatter
<>::
format
(
"foo"
,
ctx
);
}
}
};
};
}
FMT_END_NAMESPACE
TEST
(
FormatTest
,
DynamicFormatter
)
{
TEST
(
FormatTest
,
DynamicFormatter
)
{
auto
num
=
variant
(
42
);
auto
num
=
variant
(
42
);
...
...
test/util-test.cc
View file @
838400d2
...
@@ -54,7 +54,7 @@ basic_format_arg<Context> make_arg(const T &value) {
...
@@ -54,7 +54,7 @@ basic_format_arg<Context> make_arg(const T &value) {
}
}
}
// namespace
}
// namespace
namespace
fmt
{
FMT_BEGIN_NAMESPACE
template
<
typename
Char
>
template
<
typename
Char
>
struct
formatter
<
Test
,
Char
>
{
struct
formatter
<
Test
,
Char
>
{
template
<
typename
ParseContext
>
template
<
typename
ParseContext
>
...
@@ -70,7 +70,7 @@ struct formatter<Test, Char> {
...
@@ -70,7 +70,7 @@ struct formatter<Test, Char> {
return
std
::
copy_n
(
test
,
std
::
strlen
(
test
),
ctx
.
out
());
return
std
::
copy_n
(
test
,
std
::
strlen
(
test
),
ctx
.
out
());
}
}
};
};
}
FMT_END_NAMESPACE
void
CheckForwarding
(
void
CheckForwarding
(
MockAllocator
<
int
>
&
alloc
,
AllocatorRef
<
MockAllocator
<
int
>
>
&
ref
)
{
MockAllocator
<
int
>
&
alloc
,
AllocatorRef
<
MockAllocator
<
int
>
>
&
ref
)
{
...
@@ -459,7 +459,7 @@ TEST(UtilTest, MakeValueWithCustomFormatter) {
...
@@ -459,7 +459,7 @@ TEST(UtilTest, MakeValueWithCustomFormatter) {
EXPECT_TRUE
(
ctx
.
called
);
EXPECT_TRUE
(
ctx
.
called
);
}
}
namespace
fmt
{
FMT_BEGIN_NAMESPACE
namespace
internal
{
namespace
internal
{
template
<
typename
Char
>
template
<
typename
Char
>
...
@@ -467,7 +467,7 @@ bool operator==(custom_value<Char> lhs, custom_value<Char> rhs) {
...
@@ -467,7 +467,7 @@ bool operator==(custom_value<Char> lhs, custom_value<Char> rhs) {
return
lhs
.
value
==
rhs
.
value
;
return
lhs
.
value
==
rhs
.
value
;
}
}
}
}
}
FMT_END_NAMESPACE
// Use a unique result type to make sure that there are no undesirable
// Use a unique result type to make sure that there are no undesirable
// conversions.
// conversions.
...
...
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