Skip to content

Commit

Permalink
FMT_EXPLICIT -> explicit, FMT_NULL -> nullptr
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed May 30, 2019
1 parent 4a7966c commit d07cc20
Show file tree
Hide file tree
Showing 25 changed files with 163 additions and 193 deletions.
10 changes: 5 additions & 5 deletions include/fmt/chrono.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ inline std::tm localtime(std::time_t time) {
return handle(localtime_r(&time_, &tm_));
}

bool handle(std::tm* tm) { return tm != FMT_NULL; }
bool handle(std::tm* tm) { return tm != nullptr; }

bool handle(internal::null<>) {
using namespace fmt::internal;
Expand All @@ -56,7 +56,7 @@ inline std::tm localtime(std::time_t time) {
using namespace fmt::internal;
std::tm* tm = std::localtime(&time_);
if (tm) tm_ = *tm;
return tm != FMT_NULL;
return tm != nullptr;
}
#endif
};
Expand All @@ -79,7 +79,7 @@ inline std::tm gmtime(std::time_t time) {
return handle(gmtime_r(&time_, &tm_));
}

bool handle(std::tm* tm) { return tm != FMT_NULL; }
bool handle(std::tm* tm) { return tm != nullptr; }

bool handle(internal::null<>) {
using namespace fmt::internal;
Expand All @@ -92,7 +92,7 @@ inline std::tm gmtime(std::time_t time) {
bool fallback(internal::null<>) {
std::tm* tm = std::gmtime(&time_);
if (tm) tm_ = *tm;
return tm != FMT_NULL;
return tm != nullptr;
}
#endif
};
Expand Down Expand Up @@ -157,7 +157,7 @@ template <typename Char> struct formatter<std::tm, Char> {

namespace internal {
template <typename Period> FMT_CONSTEXPR const char* get_units() {
return FMT_NULL;
return nullptr;
}
template <> FMT_CONSTEXPR const char* get_units<std::atto>() { return "as"; }
template <> FMT_CONSTEXPR const char* get_units<std::femto>() { return "fs"; }
Expand Down
42 changes: 6 additions & 36 deletions include/fmt/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,28 +89,6 @@
# endif
#endif

#if FMT_HAS_FEATURE(cxx_explicit_conversions) || FMT_GCC_VERSION >= 405 || \
FMT_MSC_VER >= 1800
# define FMT_USE_EXPLICIT 1
# define FMT_EXPLICIT explicit
#else
# define FMT_USE_EXPLICIT 0
# define FMT_EXPLICIT
#endif

#ifndef FMT_NULL
# if FMT_HAS_FEATURE(cxx_nullptr) || \
(FMT_GCC_VERSION >= 408 && FMT_HAS_GXX_CXX11) || FMT_MSC_VER >= 1600
# define FMT_NULL nullptr
# define FMT_USE_NULLPTR 1
# else
# define FMT_NULL NULL
# endif
#endif
#ifndef FMT_USE_NULLPTR
# define FMT_USE_NULLPTR 0
#endif

// Check if exceptions are disabled.
#ifndef FMT_EXCEPTIONS
# if (defined(__GNUC__) && !defined(__EXCEPTIONS)) || \
Expand Down Expand Up @@ -220,11 +198,6 @@
# define FMT_STRING_VIEW std::experimental::basic_string_view
#endif

// std::result_of is defined in <functional> in gcc 4.4.
#if FMT_GCC_VERSION && FMT_GCC_VERSION <= 404
# include <functional>
#endif

// An enable_if helper to be used in template parameters. enable_if in template
// parameters results in much shorter symbols: https://godbolt.org/z/sWw4vP.
#define FMT_ENABLE_IF_T(...) typename std::enable_if<(__VA_ARGS__), int>::type
Expand Down Expand Up @@ -272,7 +245,7 @@ template <typename T> class buffer {
// Don't initialize ptr_ since it is not accessed to save a few cycles.
buffer(std::size_t sz) FMT_NOEXCEPT : size_(sz), capacity_(sz) {}

buffer(T* p = FMT_NULL, std::size_t sz = 0, std::size_t cap = 0) FMT_NOEXCEPT
buffer(T* p = nullptr, std::size_t sz = 0, std::size_t cap = 0) FMT_NOEXCEPT
: ptr_(p),
size_(sz),
capacity_(cap) {}
Expand Down Expand Up @@ -379,7 +352,7 @@ typedef char no[2];
template <typename T, typename V> struct is_constructible {
template <typename U> static yes& test(int (*)[sizeof(new U(declval<V>()))]);
template <typename U> static no& test(...);
enum { value = sizeof(test<T>(FMT_NULL)) == sizeof(yes) };
enum { value = sizeof(test<T>(nullptr)) == sizeof(yes) };
};
#else
template <typename... T>
Expand All @@ -404,7 +377,7 @@ template <typename Char> class basic_string_view {
typedef Char char_type;
typedef const Char* iterator;

FMT_CONSTEXPR basic_string_view() FMT_NOEXCEPT : data_(FMT_NULL), size_(0) {}
FMT_CONSTEXPR basic_string_view() FMT_NOEXCEPT : data_(nullptr), size_(0) {}

/** Constructs a string reference object from a C string and a size. */
FMT_CONSTEXPR basic_string_view(const Char* s, size_t count) FMT_NOEXCEPT
Expand Down Expand Up @@ -850,10 +823,7 @@ FMT_MAKE_VALUE(string_type, const std::basic_string<typename C::char_type>&,
basic_string_view<typename C::char_type>)
FMT_MAKE_VALUE(pointer_type, void*, const void*)
FMT_MAKE_VALUE_SAME(pointer_type, const void*)

#if FMT_USE_NULLPTR
FMT_MAKE_VALUE(pointer_type, std::nullptr_t, const void*)
#endif

// Formatting of arbitrary pointers is disallowed. If you want to output a
// pointer cast it to "void *" or "const void *". In particular, this forbids
Expand Down Expand Up @@ -953,7 +923,7 @@ template <typename Context> class basic_format_arg {

FMT_CONSTEXPR basic_format_arg() : type_(internal::none_type) {}

FMT_CONSTEXPR FMT_EXPLICIT operator bool() const FMT_NOEXCEPT {
FMT_CONSTEXPR explicit operator bool() const FMT_NOEXCEPT {
return type_ != internal::none_type;
}

Expand Down Expand Up @@ -1041,7 +1011,7 @@ template <typename Context> class arg_map {
}

public:
arg_map() : map_(FMT_NULL), size_(0) {}
arg_map() : map_(nullptr), size_(0) {}
void init(const basic_format_args<Context>& args);
~arg_map() { delete[] map_; }

Expand All @@ -1061,7 +1031,7 @@ class locale_ref {
friend class locale;

public:
locale_ref() : locale_(FMT_NULL) {}
locale_ref() : locale_(nullptr) {}
template <typename Locale> explicit locale_ref(const Locale& loc);

template <typename Locale> Locale get() const;
Expand Down
22 changes: 11 additions & 11 deletions include/fmt/format-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ typedef void (*FormatFunc)(internal::buffer<char>&, int, string_view);
// Buffer should be at least of size 1.
int safe_strerror(int error_code, char*& buffer,
std::size_t buffer_size) FMT_NOEXCEPT {
FMT_ASSERT(buffer != FMT_NULL && buffer_size != 0, "invalid buffer");
FMT_ASSERT(buffer != nullptr && buffer_size != 0, "invalid buffer");

class dispatcher {
private:
Expand Down Expand Up @@ -650,9 +650,9 @@ template <int GRISU_VERSION> struct grisu_shortest_handler {
// Decrement the generated number approaching value from above.
void round(uint64_t d, uint64_t divisor, uint64_t& remainder,
uint64_t error) {
while (remainder < d && error - remainder >= divisor &&
(remainder + divisor < d ||
d - remainder >= remainder + divisor - d)) {
while (
remainder < d && error - remainder >= divisor &&
(remainder + divisor < d || d - remainder >= remainder + divisor - d)) {
--buf[size - 1];
remainder += divisor;
}
Expand Down Expand Up @@ -782,7 +782,7 @@ void sprintf_format(Double value, internal::buffer<char>& buf,
*format_ptr = '\0';

// Format using snprintf.
char* start = FMT_NULL;
char* start = nullptr;
for (;;) {
std::size_t buffer_size = buf.capacity();
start = &buf[0];
Expand Down Expand Up @@ -839,7 +839,7 @@ FMT_FUNC internal::utf8_to_utf16::utf8_to_utf16(string_view s) {
}

int length = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, s.data(),
s_size, FMT_NULL, 0);
s_size, nullptr, 0);
if (length == 0) FMT_THROW(windows_error(GetLastError(), ERROR_MSG));
buffer_.resize(length + 1);
length = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, s.data(), s_size,
Expand All @@ -865,12 +865,12 @@ FMT_FUNC int internal::utf16_to_utf8::convert(wstring_view s) {
return 0;
}

int length = WideCharToMultiByte(CP_UTF8, 0, s.data(), s_size, FMT_NULL, 0,
FMT_NULL, FMT_NULL);
int length = WideCharToMultiByte(CP_UTF8, 0, s.data(), s_size, nullptr, 0,
nullptr, nullptr);
if (length == 0) return GetLastError();
buffer_.resize(length + 1);
length = WideCharToMultiByte(CP_UTF8, 0, s.data(), s_size, &buffer_[0],
length, FMT_NULL, FMT_NULL);
length, nullptr, nullptr);
if (length == 0) return GetLastError();
buffer_[length] = 0;
return 0;
Expand All @@ -894,9 +894,9 @@ FMT_FUNC void internal::format_windows_error(internal::buffer<char>& out,
for (;;) {
wchar_t* system_message = &buf[0];
int result = FormatMessageW(
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, FMT_NULL,
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, nullptr,
error_code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), system_message,
static_cast<uint32_t>(buf.size()), FMT_NULL);
static_cast<uint32_t>(buf.size()), nullptr);
if (result != 0) {
utf16_to_utf8 utf8_message;
if (utf8_message.convert(system_message) == ERROR_SUCCESS) {
Expand Down
25 changes: 12 additions & 13 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,7 @@ FMT_CONSTEXPR T* end(T (&array)[N]) FMT_NOEXCEPT {
}

// An implementation of iterator_t for pre-C++20 compilers such as gcc 4.
template <typename T>
struct iterator_t {
template <typename T> struct iterator_t {
typedef decltype(internal::begin(internal::declval<const T&>())) type;
};

Expand Down Expand Up @@ -2101,7 +2100,7 @@ inline bool find<false, char>(const char* first, const char* last, char value,
const char*& out) {
out = static_cast<const char*>(
std::memchr(first, value, internal::to_unsigned(last - first)));
return out != FMT_NULL;
return out != nullptr;
}

template <typename Handler, typename Char> struct id_adapter {
Expand All @@ -2123,7 +2122,7 @@ FMT_CONSTEXPR void parse_format_string(basic_string_view<Char> format_str,
FMT_CONSTEXPR void operator()(const Char* begin, const Char* end) {
if (begin == end) return;
for (;;) {
const Char* p = FMT_NULL;
const Char* p = nullptr;
if (!find<IS_CONSTEXPR>(begin, end, '}', p))
return handler_.on_text(begin, end);
++p;
Expand Down Expand Up @@ -2304,8 +2303,8 @@ class arg_formatter
\endrst
*/
explicit arg_formatter(context_type& ctx,
basic_parse_context<char_type>* parse_ctx = FMT_NULL,
format_specs* spec = FMT_NULL)
basic_parse_context<char_type>* parse_ctx = nullptr,
format_specs* spec = nullptr)
: base(Range(ctx.out()), spec, ctx.locale()),
ctx_(ctx),
parse_ctx_(parse_ctx) {}
Expand Down Expand Up @@ -3040,7 +3039,7 @@ template <typename T, typename Char>
struct formatter<T, Char,
typename std::enable_if<internal::format_type<
typename buffer_context<Char>::type, T>::value>::type> {
FMT_CONSTEXPR formatter() : format_str_(FMT_NULL) {}
FMT_CONSTEXPR formatter() : format_str_(nullptr) {}

// Parses format specifiers stopping either at the end of the range or at the
// terminating '}'.
Expand Down Expand Up @@ -3104,7 +3103,7 @@ struct formatter<T, Char,
typedef output_range<typename FormatContext::iterator,
typename FormatContext::char_type>
range_type;
return visit_format_arg(arg_formatter<range_type>(ctx, FMT_NULL, &specs_),
return visit_format_arg(arg_formatter<range_type>(ctx, nullptr, &specs_),
internal::make_arg<FormatContext>(val));
}

Expand Down Expand Up @@ -3160,7 +3159,7 @@ template <typename Char = char> class dynamic_formatter {
typedef output_range<typename FormatContext::iterator,
typename FormatContext::char_type>
range;
visit_format_arg(arg_formatter<range>(ctx, FMT_NULL, &specs_),
visit_format_arg(arg_formatter<range>(ctx, nullptr, &specs_),
internal::make_arg<FormatContext>(val));
return ctx.out();
}
Expand Down Expand Up @@ -3329,14 +3328,14 @@ arg_join<It, wchar_t> join(It begin, It end, wstring_view sep) {
\endrst
*/
template <typename Range>
arg_join<typename internal::iterator_t<Range>::type, char>
join(const Range& range, string_view sep) {
arg_join<typename internal::iterator_t<Range>::type, char> join(
const Range& range, string_view sep) {
return join(internal::begin(range), internal::end(range), sep);
}

template <typename Range>
arg_join<typename internal::iterator_t<Range>::type, wchar_t>
join(const Range& range, wstring_view sep) {
arg_join<typename internal::iterator_t<Range>::type, wchar_t> join(
const Range& range, wstring_view sep) {
return join(internal::begin(range), internal::end(range), sep);
}
#endif
Expand Down
10 changes: 5 additions & 5 deletions include/fmt/posix.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class buffered_file {

public:
// Constructs a buffered_file object which doesn't represent any file.
buffered_file() FMT_NOEXCEPT : file_(FMT_NULL) {}
buffered_file() FMT_NOEXCEPT : file_(nullptr) {}

// Destroys the object closing the file it represents if any.
FMT_API ~buffered_file() FMT_NOEXCEPT;
Expand All @@ -144,13 +144,13 @@ class buffered_file {

public:
buffered_file(buffered_file&& other) FMT_NOEXCEPT : file_(other.file_) {
other.file_ = FMT_NULL;
other.file_ = nullptr;
}

buffered_file& operator=(buffered_file&& other) {
close();
file_ = other.file_;
other.file_ = FMT_NULL;
other.file_ = nullptr;
return *this;
}

Expand Down Expand Up @@ -295,7 +295,7 @@ class Locale {
public:
typedef locale_t Type;

Locale() : locale_(newlocale(LC_NUMERIC_MASK, "C", FMT_NULL)) {
Locale() : locale_(newlocale(LC_NUMERIC_MASK, "C", nullptr)) {
if (!locale_) FMT_THROW(system_error(errno, "cannot create locale"));
}
~Locale() { freelocale(locale_); }
Expand All @@ -305,7 +305,7 @@ class Locale {
// Converts string to floating-point number and advances str past the end
// of the parsed input.
double strtod(const char*& str) const {
char* end = FMT_NULL;
char* end = nullptr;
double result = strtod_l(str, &end, locale_);
str = end;
return result;
Expand Down
2 changes: 1 addition & 1 deletion include/fmt/prepare.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ class prepared_format {
check_prepared_specs(specs, arg.type());
advance_parse_context_to_specification(parse_ctx, part);
ctx.advance_to(
visit_format_arg(arg_formatter<Range>(ctx, FMT_NULL, &specs), arg));
visit_format_arg(arg_formatter<Range>(ctx, nullptr, &specs), arg));
} break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions include/fmt/ranges.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ template <typename T> class is_like_std_string {

public:
static FMT_CONSTEXPR_DECL const bool value =
is_string<T>::value || !std::is_void<decltype(check<T>(FMT_NULL))>::value;
is_string<T>::value || !std::is_void<decltype(check<T>(nullptr))>::value;
};

template <typename Char>
Expand Down Expand Up @@ -113,7 +113,7 @@ template <typename T> class is_tuple_like_ {

public:
static FMT_CONSTEXPR_DECL const bool value =
!std::is_void<decltype(check<T>(FMT_NULL))>::value;
!std::is_void<decltype(check<T>(nullptr))>::value;
};

// Check for integer_sequence
Expand Down
4 changes: 2 additions & 2 deletions src/posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ buffered_file::~buffered_file() FMT_NOEXCEPT {

buffered_file::buffered_file(cstring_view filename, cstring_view mode) {
FMT_RETRY_VAL(file_, FMT_SYSTEM(fopen(filename.c_str(), mode.c_str())),
FMT_NULL);
nullptr);
if (!file_)
FMT_THROW(system_error(errno, "cannot open file {}", filename.c_str()));
}

void buffered_file::close() {
if (!file_) return;
int result = FMT_SYSTEM(fclose(file_));
file_ = FMT_NULL;
file_ = nullptr;
if (result != 0) FMT_THROW(system_error(errno, "cannot close file"));
}

Expand Down
Loading

0 comments on commit d07cc20

Please sign in to comment.