Skip to content

Commit

Permalink
Reduce syntactic noise
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Sep 23, 2018
1 parent 48e6dcd commit d66fa22
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 26 deletions.
21 changes: 7 additions & 14 deletions include/fmt/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ class arg_map {
if (it->name == name)
return it->arg;
}
return basic_format_arg<Context>();
return {};
}
};

Expand Down Expand Up @@ -899,9 +899,8 @@ class context_base {
}

public:
basic_parse_context<char_type> &parse_context() {
return parse_context_;
}
basic_parse_context<char_type> &parse_context() { return parse_context_; }
basic_format_args<Context> args() const { return args_; }

internal::error_handler error_handler() {
return parse_context_.error_handler();
Expand All @@ -915,8 +914,6 @@ class context_base {

// Advances the begin iterator to ``it``.
void advance_to(iterator it) { out_ = it; }

basic_format_args<Context> args() const { return args_; }
};

// Extracts a reference to the container from back_insert_iterator.
Expand Down Expand Up @@ -1086,15 +1083,11 @@ const long long format_arg_store<Context, Args...>::TYPES = get_types();
*/
template <typename Context, typename ...Args>
inline format_arg_store<Context, Args...>
make_format_args(const Args &... args) {
return format_arg_store<Context, Args...>(args...);
}
make_format_args(const Args &... args) { return {args...}; }

template <typename ...Args>
inline format_arg_store<format_context, Args...>
make_format_args(const Args &... args) {
return format_arg_store<format_context, Args...>(args...);
}
make_format_args(const Args &... args) { return {args...}; }

/** Formatting arguments. */
template <typename Context>
Expand Down Expand Up @@ -1240,12 +1233,12 @@ struct named_arg : named_arg_base<Char> {
*/
template <typename T>
inline internal::named_arg<T, char> arg(string_view name, const T &arg) {
return internal::named_arg<T, char>(name, arg);
return {name, arg};
}

template <typename T>
inline internal::named_arg<T, wchar_t> arg(wstring_view name, const T &arg) {
return internal::named_arg<T, wchar_t>(name, arg);
return {name, arg};
}

// This function template is deleted intentionally to disable nested named
Expand Down
19 changes: 7 additions & 12 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -434,31 +434,26 @@ void basic_buffer<T>::append(const U *begin, const U *end) {
// A UTF-8 code unit type.
struct char8_t {
char value;
FMT_CONSTEXPR explicit operator bool() const FMT_NOEXCEPT {
FMT_CONSTEXPR FMT_EXPLICIT operator bool() const FMT_NOEXCEPT {
return value != 0;
}
};

// A UTF-8 string view.
class u8string_view : public basic_string_view<char8_t> {
private:
typedef basic_string_view<char8_t> base;

public:
using basic_string_view::basic_string_view;
using basic_string_view::char_type;

u8string_view(const char *s)
: base(reinterpret_cast<const char8_t*>(s)) {}
typedef char8_t char_type;

u8string_view(const char *s, size_t count) FMT_NOEXCEPT
: base(reinterpret_cast<const char8_t*>(s), count) {}
u8string_view(const char *s):
basic_string_view<char8_t>(reinterpret_cast<const char8_t*>(s)) {}
u8string_view(const char *s, size_t count) FMT_NOEXCEPT:
basic_string_view<char8_t>(reinterpret_cast<const char8_t*>(s), count) {}
};

#if FMT_USE_USER_DEFINED_LITERALS
inline namespace literals {
inline u8string_view operator"" _u(const char *s, std::size_t n) {
return u8string_view(s, n);
return {s, n};
}
}
#endif
Expand Down

0 comments on commit d66fa22

Please sign in to comment.