Add inline namespace fmt::v5

This commit is contained in:
Victor Zverovich 2018-05-12 08:33:51 -07:00
parent b64b24ebc5
commit 838400d29b
12 changed files with 73 additions and 61 deletions

View File

@ -133,6 +133,15 @@
# define FMT_DTOR_NOEXCEPT FMT_NOEXCEPT
#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)
# ifdef FMT_EXPORT
# define FMT_API __declspec(dllexport)
@ -172,7 +181,7 @@
# include <functional>
#endif
namespace fmt {
FMT_BEGIN_NAMESPACE
// An implementation of declval for pre-C++11 compilers such as gcc 4.
namespace internal {
@ -1190,7 +1199,7 @@ template <typename Char>
struct is_contiguous<std::basic_string<Char>> : std::true_type {};
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``. */
template <typename Container>
@ -1288,6 +1297,6 @@ inline void print(wstring_view format_str, const Args & ... args) {
format_arg_store<wformat_context, Args...> as(args...);
vprint(format_str, as);
}
} // namespace fmt
FMT_END_NAMESPACE
#endif // FMT_CORE_H_

View File

@ -69,7 +69,7 @@ inline fmt::internal::null<> strerror_s(char *, std::size_t, ...) {
return fmt::internal::null<>();
}
namespace fmt {
FMT_BEGIN_NAMESPACE
FMT_FUNC format_error::~format_error() throw() {}
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) {
FMT_FUNC locale locale_provider::locale() { return fmt::locale(); }
} // namespace fmt
FMT_END_NAMESPACE
#ifdef _MSC_VER
# pragma warning(pop)

View File

@ -161,7 +161,7 @@
#if FMT_MSC_VER && !defined(FMT_BUILTIN_CLZLL) && !defined(_MANAGED)
# include <intrin.h> // _BitScanReverse, _BitScanReverse64
namespace fmt {
FMT_BEGIN_NAMESPACE
namespace internal {
// Avoid Clang with Microsoft CodeGen's -Wunknown-pragmas warning.
# ifndef __clang__
@ -206,10 +206,10 @@ inline uint32_t clzll(uint64_t x) {
}
# define FMT_BUILTIN_CLZLL(n) fmt::internal::clzll(n)
}
}
FMT_END_NAMESPACE
#endif
namespace fmt {
FMT_BEGIN_NAMESPACE
namespace internal {
// An equivalent of `*reinterpret_cast<Dest*>(&source)` that doesn't produce
@ -246,7 +246,7 @@ struct dummy_int {
int data[2];
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
// if the latter are not available.
@ -322,7 +322,7 @@ typename Allocator::value_type *allocate(Allocator& alloc, std::size_t n) {
template <typename T>
inline T const_check(T value) { return value; }
} // namespace internal
} // namespace fmt
FMT_END_NAMESPACE
namespace std {
// Standard permits specialization of std::numeric_limits. This specialization
@ -339,7 +339,7 @@ class numeric_limits<fmt::internal::dummy_int> :
using namespace fmt::internal;
// The resolution "priority" is:
// 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 !_finite(static_cast<double>(x));
}
@ -368,8 +368,7 @@ class numeric_limits<fmt::internal::dummy_int> :
};
} // namespace std
namespace fmt {
FMT_BEGIN_NAMESPACE
template <typename Range>
class basic_writer;
@ -2328,7 +2327,7 @@ class system_error : public std::runtime_error {
may look like "Unknown error -1" and is platform-dependent.
\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;
/**
@ -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...);
return it.count();
}
} // namespace fmt
#if FMT_USE_USER_DEFINED_LITERALS
namespace fmt {
namespace internal {
# if FMT_UDL_TEMPLATE
@ -3611,8 +3608,8 @@ operator"" _a(const char *s, std::size_t) { return {s}; }
inline internal::udl_arg<wchar_t>
operator"" _a(const wchar_t *s, std::size_t) { return {s}; }
} // inline namespace literals
} // namespace fmt
#endif // FMT_USE_USER_DEFINED_LITERALS
FMT_END_NAMESPACE
#define FMT_STRING(s) [] { \
struct S : fmt::format_string { \

View File

@ -5,10 +5,13 @@
//
// For the license information refer to format.h.
#ifndef FMT_LOCALE_H_
#define FMT_LOCALE_H_
#include "format.h"
#include <locale>
namespace fmt {
FMT_BEGIN_NAMESPACE
class locale {
private:
std::locale locale_;
@ -17,4 +20,6 @@ class locale {
explicit locale(std::locale loc = std::locale()) : locale_(loc) {}
std::locale get() { return locale_; }
};
}
FMT_END_NAMESPACE
#endif // FMT_LOCALE_

View File

@ -11,8 +11,7 @@
#include "format.h"
#include <ostream>
namespace fmt {
FMT_BEGIN_NAMESPACE
namespace internal {
template <class Char>
@ -149,7 +148,6 @@ inline void print(std::wostream &os, wstring_view format_str,
const Args & ... args) {
vprint(os, format_str, make_format_args<wformat_context>(args...));
}
} // namespace fmt
FMT_END_NAMESPACE
#endif // FMT_OSTREAM_H_

View File

@ -62,7 +62,7 @@
#define FMT_RETRY(result, expression) FMT_RETRY_VAL(result, expression, -1)
namespace fmt {
FMT_BEGIN_NAMESPACE
/**
\rst
@ -388,7 +388,7 @@ class Locale {
Locale() : locale_(newlocale(LC_NUMERIC_MASK, "C", FMT_NULL)) {
if (!locale_)
FMT_THROW(fmt::system_error(errno, "cannot create locale"));
FMT_THROW(system_error(errno, "cannot create locale"));
}
~Locale() { freelocale(locale_); }
@ -404,7 +404,7 @@ class Locale {
}
};
#endif // FMT_LOCALE
} // namespace fmt
FMT_END_NAMESPACE
#if !FMT_USE_RVALUE_REFERENCES
namespace std {

View File

@ -13,7 +13,7 @@
#include "ostream.h"
namespace fmt {
FMT_BEGIN_NAMESPACE
namespace internal {
// 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,
typename printf_context<internal::buffer>::type>(args...);
return vfprintf(os, format_str, vargs);
}
} // namespace fmt
FMT_END_NAMESPACE
#endif // FMT_PRINTF_H_

View File

@ -11,7 +11,7 @@
#include "format.h"
#include <ctime>
namespace fmt {
FMT_BEGIN_NAMESPACE
namespace internal{
inline null<> localtime_r(...) { return null<>(); }
@ -146,6 +146,6 @@ struct formatter<std::tm, Char> {
basic_memory_buffer<Char> tm_format;
};
}
FMT_END_NAMESPACE
#endif // FMT_TIME_H_

View File

@ -7,7 +7,7 @@
#include "fmt/format-inl.h"
namespace fmt {
FMT_BEGIN_NAMESPACE
template struct internal::basic_data<void>;
@ -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(
wchar_t *buffer, std::size_t size, const wchar_t *format,
unsigned width, int precision, long double value);
} // namespace fmt
FMT_END_NAMESPACE

View File

@ -64,20 +64,21 @@ inline std::size_t convert_rwcount(std::size_t count) { return count; }
#endif
}
fmt::BufferedFile::~BufferedFile() FMT_NOEXCEPT {
FMT_BEGIN_NAMESPACE
BufferedFile::~BufferedFile() FMT_NOEXCEPT {
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(
fmt::cstring_view filename, fmt::cstring_view mode) {
BufferedFile::BufferedFile(cstring_view filename, cstring_view mode) {
FMT_RETRY_VAL(file_,
FMT_SYSTEM(fopen(filename.c_str(), mode.c_str())), FMT_NULL);
if (!file_)
FMT_THROW(system_error(errno, "cannot open file {}", filename.c_str()));
}
void fmt::BufferedFile::close() {
void BufferedFile::close() {
if (!file_)
return;
int result = FMT_SYSTEM(fclose(file_));
@ -89,14 +90,14 @@ void fmt::BufferedFile::close() {
// A macro used to prevent expansion of fileno on broken versions of MinGW.
#define FMT_ARGS
int fmt::BufferedFile::fileno() const {
int BufferedFile::fileno() const {
int fd = FMT_POSIX_CALL(fileno FMT_ARGS(file_));
if (fd == -1)
FMT_THROW(system_error(errno, "cannot get file descriptor"));
return fd;
}
fmt::File::File(fmt::cstring_view path, int oflag) {
File::File(cstring_view path, int oflag) {
int mode = S_IRUSR | S_IWUSR;
#if defined(_WIN32) && !defined(__MINGW32__)
fd_ = -1;
@ -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::File::~File() FMT_NOEXCEPT {
File::~File() FMT_NOEXCEPT {
// Don't retry close in case of EINTR!
// See http://linux.derkeiler.com/Mailing-Lists/Kernel/2005-09/3000.html
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)
return;
// Don't retry close in case of EINTR!
@ -126,7 +127,7 @@ void fmt::File::close() {
FMT_THROW(system_error(errno, "cannot close file"));
}
long long fmt::File::size() const {
long long File::size() const {
#ifdef _WIN32
// Use GetFileSize instead of GetFileSizeEx for the case when _WIN32_WINNT
// is less than 0x0500 as is the case with some default MinGW builds.
@ -152,7 +153,7 @@ long long fmt::File::size() const {
#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;
FMT_RETRY(result, FMT_POSIX_CALL(read(fd_, buffer, convert_rwcount(count))));
if (result < 0)
@ -160,7 +161,7 @@ std::size_t fmt::File::read(void *buffer, std::size_t count) {
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;
FMT_RETRY(result, FMT_POSIX_CALL(write(fd_, buffer, convert_rwcount(count))));
if (result < 0)
@ -168,7 +169,7 @@ std::size_t fmt::File::write(const void *buffer, std::size_t count) {
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.
// http://pubs.opengroup.org/onlinepubs/009695399/functions/dup.html
int new_fd = FMT_POSIX_CALL(dup(fd));
@ -177,7 +178,7 @@ fmt::File fmt::File::dup(int fd) {
return File(new_fd);
}
void fmt::File::dup2(int fd) {
void File::dup2(int fd) {
int result = 0;
FMT_RETRY(result, FMT_POSIX_CALL(dup2(fd_, fd)));
if (result == -1) {
@ -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;
FMT_RETRY(result, FMT_POSIX_CALL(dup2(fd_, fd)));
if (result == -1)
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
// and there are no leaks.
read_end.close();
@ -216,7 +217,7 @@ void fmt::File::pipe(File &read_end, File &write_end) {
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.
FILE *f = FMT_POSIX_CALL(fdopen(fd_, mode));
if (!f)
@ -227,7 +228,7 @@ fmt::BufferedFile fmt::File::fdopen(const char *mode) {
return file;
}
long fmt::getpagesize() {
long getpagesize() {
#ifdef _WIN32
SYSTEM_INFO si;
GetSystemInfo(&si);
@ -239,3 +240,5 @@ long fmt::getpagesize() {
return size;
#endif
}
FMT_END_NAMESPACE

View File

@ -1090,7 +1090,7 @@ TEST(FormatterTest, FormatConvertibleToStringView) {
EXPECT_EQ("foo", format("{}", ConvertibleToStringView()));
}
namespace fmt {
FMT_BEGIN_NAMESPACE
template <>
struct formatter<Date> {
template <typename ParseContext>
@ -1106,7 +1106,7 @@ struct formatter<Date> {
return ctx.out();
}
};
}
FMT_END_NAMESPACE
TEST(FormatterTest, FormatCustom) {
Date date(2012, 12, 9);
@ -1116,14 +1116,14 @@ TEST(FormatterTest, FormatCustom) {
class Answer {};
namespace fmt {
FMT_BEGIN_NAMESPACE
template <>
struct formatter<Answer> : formatter<int> {
auto format(Answer, fmt::format_context &ctx) -> decltype(ctx.out()) {
return formatter<int>::format(42, ctx);
}
};
}
FMT_END_NAMESPACE
TEST(FormatterTest, CustomFormat) {
EXPECT_EQ("42", format("{0}", Answer()));
@ -1455,7 +1455,7 @@ struct variant {
explicit variant(const char *) : type(STRING) {}
};
namespace fmt {
FMT_BEGIN_NAMESPACE
template <>
struct formatter<variant> : dynamic_formatter<> {
auto format(variant value, format_context& ctx) -> decltype(ctx.out()) {
@ -1464,7 +1464,7 @@ struct formatter<variant> : dynamic_formatter<> {
return dynamic_formatter<>::format("foo", ctx);
}
};
}
FMT_END_NAMESPACE
TEST(FormatTest, DynamicFormatter) {
auto num = variant(42);

View File

@ -54,7 +54,7 @@ basic_format_arg<Context> make_arg(const T &value) {
}
} // namespace
namespace fmt {
FMT_BEGIN_NAMESPACE
template <typename Char>
struct formatter<Test, Char> {
template <typename ParseContext>
@ -70,7 +70,7 @@ struct formatter<Test, Char> {
return std::copy_n(test, std::strlen(test), ctx.out());
}
};
}
FMT_END_NAMESPACE
void CheckForwarding(
MockAllocator<int> &alloc, AllocatorRef< MockAllocator<int> > &ref) {
@ -459,7 +459,7 @@ TEST(UtilTest, MakeValueWithCustomFormatter) {
EXPECT_TRUE(ctx.called);
}
namespace fmt {
FMT_BEGIN_NAMESPACE
namespace internal {
template <typename Char>
@ -467,7 +467,7 @@ bool operator==(custom_value<Char> lhs, custom_value<Char> rhs) {
return lhs.value == rhs.value;
}
}
}
FMT_END_NAMESPACE
// Use a unique result type to make sure that there are no undesirable
// conversions.