Skip to content

Commit

Permalink
Fix const[expr] in context API
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Nov 3, 2024
1 parent 6580d7b commit cf50e4d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
10 changes: 6 additions & 4 deletions include/fmt/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -2627,18 +2627,20 @@ class context : private detail::locale_ref {
void operator=(const context&) = delete;

FMT_CONSTEXPR auto arg(int id) const -> format_arg { return args_.get(id); }
inline auto arg(string_view name) -> format_arg { return args_.get(name); }
FMT_CONSTEXPR auto arg_id(string_view name) -> int {
inline auto arg(string_view name) const -> format_arg {
return args_.get(name);
}
FMT_CONSTEXPR auto arg_id(string_view name) const -> int {
return args_.get_id(name);
}

// Returns an iterator to the beginning of the output range.
FMT_CONSTEXPR auto out() -> iterator { return out_; }
FMT_CONSTEXPR auto out() const -> iterator { return out_; }

// Advances the begin iterator to `it`.
FMT_CONSTEXPR void advance_to(iterator) {}

FMT_CONSTEXPR auto locale() -> detail::locale_ref { return *this; }
FMT_CONSTEXPR auto locale() const -> detail::locale_ref { return *this; }
};

template <typename Char = char> struct runtime_format_string {
Expand Down
9 changes: 5 additions & 4 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -3708,20 +3708,21 @@ template <typename OutputIt, typename Char> class generic_context {
constexpr auto arg(int id) const -> basic_format_arg<generic_context> {
return args_.get(id);
}
auto arg(basic_string_view<Char> name) -> basic_format_arg<generic_context> {
auto arg(basic_string_view<Char> name) const
-> basic_format_arg<generic_context> {
return args_.get(name);
}
FMT_CONSTEXPR auto arg_id(basic_string_view<Char> name) -> int {
constexpr auto arg_id(basic_string_view<Char> name) const -> int {
return args_.get_id(name);
}

FMT_CONSTEXPR auto out() -> iterator { return out_; }
constexpr auto out() const -> iterator { return out_; }

void advance_to(iterator it) {
if (!detail::is_back_insert_iterator<iterator>()) out_ = it;
}

FMT_CONSTEXPR auto locale() -> detail::locale_ref { return loc_; }
constexpr auto locale() const -> detail::locale_ref { return loc_; }
};

class loc_value {
Expand Down

0 comments on commit cf50e4d

Please sign in to comment.