Skip to content

Commit

Permalink
FMT_NOEXCEPT -> noexcept
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Jan 21, 2022
1 parent 6240d02 commit c285005
Show file tree
Hide file tree
Showing 13 changed files with 149 additions and 170 deletions.
71 changes: 32 additions & 39 deletions include/fmt/color.h
Expand Up @@ -214,17 +214,16 @@ FMT_BEGIN_DETAIL_NAMESPACE

// color is a struct of either a rgb color or a terminal color.
struct color_type {
FMT_CONSTEXPR color_type() FMT_NOEXCEPT : is_rgb(), value{} {}
FMT_CONSTEXPR color_type(color rgb_color) FMT_NOEXCEPT : is_rgb(true),
value{} {
FMT_CONSTEXPR color_type() noexcept : is_rgb(), value{} {}
FMT_CONSTEXPR color_type(color rgb_color) noexcept : is_rgb(true), value{} {
value.rgb_color = static_cast<uint32_t>(rgb_color);
}
FMT_CONSTEXPR color_type(rgb rgb_color) FMT_NOEXCEPT : is_rgb(true), value{} {
FMT_CONSTEXPR color_type(rgb rgb_color) noexcept : is_rgb(true), value{} {
value.rgb_color = (static_cast<uint32_t>(rgb_color.r) << 16) |
(static_cast<uint32_t>(rgb_color.g) << 8) | rgb_color.b;
}
FMT_CONSTEXPR color_type(terminal_color term_color) FMT_NOEXCEPT : is_rgb(),
value{} {
FMT_CONSTEXPR color_type(terminal_color term_color) noexcept
: is_rgb(), value{} {
value.term_color = static_cast<uint8_t>(term_color);
}
bool is_rgb;
Expand All @@ -239,10 +238,8 @@ FMT_END_DETAIL_NAMESPACE
/** A text style consisting of foreground and background colors and emphasis. */
class text_style {
public:
FMT_CONSTEXPR text_style(emphasis em = emphasis()) FMT_NOEXCEPT
: set_foreground_color(),
set_background_color(),
ems(em) {}
FMT_CONSTEXPR text_style(emphasis em = emphasis()) noexcept
: set_foreground_color(), set_background_color(), ems(em) {}

FMT_CONSTEXPR text_style& operator|=(const text_style& rhs) {
if (!set_foreground_color) {
Expand Down Expand Up @@ -283,34 +280,32 @@ class text_style {
return lhs.and_assign(rhs);
}

FMT_CONSTEXPR bool has_foreground() const FMT_NOEXCEPT {
FMT_CONSTEXPR bool has_foreground() const noexcept {
return set_foreground_color;
}
FMT_CONSTEXPR bool has_background() const FMT_NOEXCEPT {
FMT_CONSTEXPR bool has_background() const noexcept {
return set_background_color;
}
FMT_CONSTEXPR bool has_emphasis() const FMT_NOEXCEPT {
FMT_CONSTEXPR bool has_emphasis() const noexcept {
return static_cast<uint8_t>(ems) != 0;
}
FMT_CONSTEXPR detail::color_type get_foreground() const FMT_NOEXCEPT {
FMT_CONSTEXPR detail::color_type get_foreground() const noexcept {
FMT_ASSERT(has_foreground(), "no foreground specified for this style");
return foreground_color;
}
FMT_CONSTEXPR detail::color_type get_background() const FMT_NOEXCEPT {
FMT_CONSTEXPR detail::color_type get_background() const noexcept {
FMT_ASSERT(has_background(), "no background specified for this style");
return background_color;
}
FMT_CONSTEXPR emphasis get_emphasis() const FMT_NOEXCEPT {
FMT_CONSTEXPR emphasis get_emphasis() const noexcept {
FMT_ASSERT(has_emphasis(), "no emphasis specified for this style");
return ems;
}

private:
FMT_CONSTEXPR text_style(bool is_foreground,
detail::color_type text_color) FMT_NOEXCEPT
: set_foreground_color(),
set_background_color(),
ems() {
detail::color_type text_color) noexcept
: set_foreground_color(), set_background_color(), ems() {
if (is_foreground) {
foreground_color = text_color;
set_foreground_color = true;
Expand Down Expand Up @@ -345,11 +340,11 @@ class text_style {
return *this;
}

friend FMT_CONSTEXPR_DECL text_style fg(detail::color_type foreground)
FMT_NOEXCEPT;
friend FMT_CONSTEXPR_DECL text_style
fg(detail::color_type foreground) noexcept;

friend FMT_CONSTEXPR_DECL text_style bg(detail::color_type background)
FMT_NOEXCEPT;
friend FMT_CONSTEXPR_DECL text_style
bg(detail::color_type background) noexcept;

detail::color_type foreground_color;
detail::color_type background_color;
Expand All @@ -359,25 +354,24 @@ class text_style {
};

/** Creates a text style from the foreground (text) color. */
FMT_CONSTEXPR inline text_style fg(detail::color_type foreground) FMT_NOEXCEPT {
FMT_CONSTEXPR inline text_style fg(detail::color_type foreground) noexcept {
return text_style(true, foreground);
}

/** Creates a text style from the background color. */
FMT_CONSTEXPR inline text_style bg(detail::color_type background) FMT_NOEXCEPT {
FMT_CONSTEXPR inline text_style bg(detail::color_type background) noexcept {
return text_style(false, background);
}

FMT_CONSTEXPR inline text_style operator|(emphasis lhs,
emphasis rhs) FMT_NOEXCEPT {
FMT_CONSTEXPR inline text_style operator|(emphasis lhs, emphasis rhs) noexcept {
return text_style(lhs) | rhs;
}

FMT_BEGIN_DETAIL_NAMESPACE

template <typename Char> struct ansi_color_escape {
FMT_CONSTEXPR ansi_color_escape(detail::color_type text_color,
const char* esc) FMT_NOEXCEPT {
const char* esc) noexcept {
// If we have a terminal color, we need to output another escape code
// sequence.
if (!text_color.is_rgb) {
Expand Down Expand Up @@ -412,7 +406,7 @@ template <typename Char> struct ansi_color_escape {
to_esc(color.b, buffer + 15, 'm');
buffer[19] = static_cast<Char>(0);
}
FMT_CONSTEXPR ansi_color_escape(emphasis em) FMT_NOEXCEPT {
FMT_CONSTEXPR ansi_color_escape(emphasis em) noexcept {
uint8_t em_codes[num_emphases] = {};
if (has_emphasis(em, emphasis::bold)) em_codes[0] = 1;
if (has_emphasis(em, emphasis::faint)) em_codes[1] = 2;
Expand All @@ -433,10 +427,10 @@ template <typename Char> struct ansi_color_escape {
}
buffer[index++] = static_cast<Char>(0);
}
FMT_CONSTEXPR operator const Char*() const FMT_NOEXCEPT { return buffer; }
FMT_CONSTEXPR operator const Char*() const noexcept { return buffer; }

FMT_CONSTEXPR const Char* begin() const FMT_NOEXCEPT { return buffer; }
FMT_CONSTEXPR_CHAR_TRAITS const Char* end() const FMT_NOEXCEPT {
FMT_CONSTEXPR const Char* begin() const noexcept { return buffer; }
FMT_CONSTEXPR_CHAR_TRAITS const Char* end() const noexcept {
return buffer + std::char_traits<Char>::length(buffer);
}

Expand All @@ -445,32 +439,31 @@ template <typename Char> struct ansi_color_escape {
Char buffer[7u + 3u * num_emphases + 1u];

static FMT_CONSTEXPR void to_esc(uint8_t c, Char* out,
char delimiter) FMT_NOEXCEPT {
char delimiter) noexcept {
out[0] = static_cast<Char>('0' + c / 100);
out[1] = static_cast<Char>('0' + c / 10 % 10);
out[2] = static_cast<Char>('0' + c % 10);
out[3] = static_cast<Char>(delimiter);
}
static FMT_CONSTEXPR bool has_emphasis(emphasis em,
emphasis mask) FMT_NOEXCEPT {
static FMT_CONSTEXPR bool has_emphasis(emphasis em, emphasis mask) noexcept {
return static_cast<uint8_t>(em) & static_cast<uint8_t>(mask);
}
};

template <typename Char>
FMT_CONSTEXPR ansi_color_escape<Char> make_foreground_color(
detail::color_type foreground) FMT_NOEXCEPT {
detail::color_type foreground) noexcept {
return ansi_color_escape<Char>(foreground, "\x1b[38;2;");
}

template <typename Char>
FMT_CONSTEXPR ansi_color_escape<Char> make_background_color(
detail::color_type background) FMT_NOEXCEPT {
detail::color_type background) noexcept {
return ansi_color_escape<Char>(background, "\x1b[48;2;");
}

template <typename Char>
FMT_CONSTEXPR ansi_color_escape<Char> make_emphasis(emphasis em) FMT_NOEXCEPT {
FMT_CONSTEXPR ansi_color_escape<Char> make_emphasis(emphasis em) noexcept {
return ansi_color_escape<Char>(em);
}

Expand Down
61 changes: 29 additions & 32 deletions include/fmt/core.h
Expand Up @@ -144,9 +144,6 @@
# define FMT_EXCEPTIONS 1
# endif
#endif
#ifndef FMT_NOEXCEPT
# define FMT_NOEXCEPT noexcept
#endif

// [[noreturn]] is disabled on MSVC and NVCC because of bogus unreachable code
// warnings.
Expand Down Expand Up @@ -333,7 +330,7 @@ FMT_BEGIN_DETAIL_NAMESPACE
template <typename... T> FMT_CONSTEXPR void ignore_unused(const T&...) {}

constexpr FMT_INLINE auto is_constant_evaluated(bool default_value = false)
FMT_NOEXCEPT -> bool {
noexcept -> bool {
#ifdef __cpp_lib_is_constant_evaluated
ignore_unused(default_value);
return std::is_constant_evaluated();
Expand Down Expand Up @@ -435,10 +432,10 @@ template <typename Char> class basic_string_view {
using value_type = Char;
using iterator = const Char*;

constexpr basic_string_view() FMT_NOEXCEPT : data_(nullptr), size_(0) {}
constexpr basic_string_view() noexcept : data_(nullptr), size_(0) {}

/** Constructs a string reference object from a C string and a size. */
constexpr basic_string_view(const Char* s, size_t count) FMT_NOEXCEPT
constexpr basic_string_view(const Char* s, size_t count) noexcept
: data_(s),
size_(count) {}

Expand All @@ -460,29 +457,29 @@ template <typename Char> class basic_string_view {
/** Constructs a string reference from a ``std::basic_string`` object. */
template <typename Traits, typename Alloc>
FMT_CONSTEXPR basic_string_view(
const std::basic_string<Char, Traits, Alloc>& s) FMT_NOEXCEPT
const std::basic_string<Char, Traits, Alloc>& s) noexcept
: data_(s.data()),
size_(s.size()) {}

template <typename S, FMT_ENABLE_IF(std::is_same<
S, detail::std_string_view<Char>>::value)>
FMT_CONSTEXPR basic_string_view(S s) FMT_NOEXCEPT : data_(s.data()),
FMT_CONSTEXPR basic_string_view(S s) noexcept : data_(s.data()),
size_(s.size()) {}

/** Returns a pointer to the string data. */
constexpr auto data() const FMT_NOEXCEPT -> const Char* { return data_; }
constexpr auto data() const noexcept -> const Char* { return data_; }

/** Returns the string size. */
constexpr auto size() const FMT_NOEXCEPT -> size_t { return size_; }
constexpr auto size() const noexcept -> size_t { return size_; }

constexpr auto begin() const FMT_NOEXCEPT -> iterator { return data_; }
constexpr auto end() const FMT_NOEXCEPT -> iterator { return data_ + size_; }
constexpr auto begin() const noexcept -> iterator { return data_; }
constexpr auto end() const noexcept -> iterator { return data_ + size_; }

constexpr auto operator[](size_t pos) const FMT_NOEXCEPT -> const Char& {
constexpr auto operator[](size_t pos) const noexcept -> const Char& {
return data_[pos];
}

FMT_CONSTEXPR void remove_prefix(size_t n) FMT_NOEXCEPT {
FMT_CONSTEXPR void remove_prefix(size_t n) noexcept {
data_ += n;
size_ -= n;
}
Expand Down Expand Up @@ -629,14 +626,14 @@ class basic_format_parse_context : private ErrorHandler {
Returns an iterator to the beginning of the format string range being
parsed.
*/
constexpr auto begin() const FMT_NOEXCEPT -> iterator {
constexpr auto begin() const noexcept -> iterator {
return format_str_.begin();
}

/**
Returns an iterator past the end of the format string range being parsed.
*/
constexpr auto end() const FMT_NOEXCEPT -> iterator {
constexpr auto end() const noexcept -> iterator {
return format_str_.end();
}

Expand Down Expand Up @@ -765,18 +762,18 @@ template <typename T> class buffer {
protected:
// Don't initialize ptr_ since it is not accessed to save a few cycles.
FMT_MSC_WARNING(suppress : 26495)
buffer(size_t sz) FMT_NOEXCEPT : size_(sz), capacity_(sz) {}
buffer(size_t sz) noexcept : size_(sz), capacity_(sz) {}

FMT_CONSTEXPR20 buffer(T* p = nullptr, size_t sz = 0,
size_t cap = 0) FMT_NOEXCEPT : ptr_(p),
size_t cap = 0) noexcept : ptr_(p),
size_(sz),
capacity_(cap) {}

FMT_CONSTEXPR20 ~buffer() = default;
buffer(buffer&&) = default;

/** Sets the buffer data and capacity. */
FMT_CONSTEXPR void set(T* buf_data, size_t buf_capacity) FMT_NOEXCEPT {
FMT_CONSTEXPR void set(T* buf_data, size_t buf_capacity) noexcept {
ptr_ = buf_data;
capacity_ = buf_capacity;
}
Expand All @@ -791,23 +788,23 @@ template <typename T> class buffer {
buffer(const buffer&) = delete;
void operator=(const buffer&) = delete;

auto begin() FMT_NOEXCEPT -> T* { return ptr_; }
auto end() FMT_NOEXCEPT -> T* { return ptr_ + size_; }
auto begin() noexcept -> T* { return ptr_; }
auto end() noexcept -> T* { return ptr_ + size_; }

auto begin() const FMT_NOEXCEPT -> const T* { return ptr_; }
auto end() const FMT_NOEXCEPT -> const T* { return ptr_ + size_; }
auto begin() const noexcept -> const T* { return ptr_; }
auto end() const noexcept -> const T* { return ptr_ + size_; }

/** Returns the size of this buffer. */
constexpr auto size() const FMT_NOEXCEPT -> size_t { return size_; }
constexpr auto size() const noexcept -> size_t { return size_; }

/** Returns the capacity of this buffer. */
constexpr auto capacity() const FMT_NOEXCEPT -> size_t { return capacity_; }
constexpr auto capacity() const noexcept -> size_t { return capacity_; }

/** Returns a pointer to the buffer data. */
FMT_CONSTEXPR auto data() FMT_NOEXCEPT -> T* { return ptr_; }
FMT_CONSTEXPR auto data() noexcept -> T* { return ptr_; }

/** Returns a pointer to the buffer data. */
FMT_CONSTEXPR auto data() const FMT_NOEXCEPT -> const T* { return ptr_; }
FMT_CONSTEXPR auto data() const noexcept -> const T* { return ptr_; }

/** Clears this buffer. */
void clear() { size_ = 0; }
Expand Down Expand Up @@ -1495,12 +1492,12 @@ class appender : public std::back_insert_iterator<detail::buffer<char>> {

public:
using std::back_insert_iterator<detail::buffer<char>>::back_insert_iterator;
appender(base it) FMT_NOEXCEPT : base(it) {}
appender(base it) noexcept : base(it) {}
using _Unchecked_type = appender; // Mark iterator as checked.

auto operator++() FMT_NOEXCEPT -> appender& { return *this; }
auto operator++() noexcept -> appender& { return *this; }

auto operator++(int) FMT_NOEXCEPT -> appender { return *this; }
auto operator++(int) noexcept -> appender { return *this; }
};

// A formatting argument. It is a trivially copyable/constructible type to
Expand Down Expand Up @@ -1546,7 +1543,7 @@ template <typename Context> class basic_format_arg {

constexpr basic_format_arg() : type_(detail::type::none_type) {}

constexpr explicit operator bool() const FMT_NOEXCEPT {
constexpr explicit operator bool() const noexcept {
return type_ != detail::type::none_type;
}

Expand Down Expand Up @@ -1656,7 +1653,7 @@ class locale_ref {
constexpr locale_ref() : locale_(nullptr) {}
template <typename Locale> explicit locale_ref(const Locale& loc);

explicit operator bool() const FMT_NOEXCEPT { return locale_ != nullptr; }
explicit operator bool() const noexcept { return locale_ != nullptr; }

template <typename Locale> auto get() const -> Locale;
};
Expand Down

0 comments on commit c285005

Please sign in to comment.