Skip to content
forked from fmtlib/fmt

Commit

Permalink
Merge pull request #80 from fmtlib/master
Browse files Browse the repository at this point in the history
string_view::char_type -> value_type (fmtlib#1539)
  • Loading branch information
sthagen authored Feb 2, 2020
2 parents 057f719 + b55ea58 commit dc240cc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 3 additions & 2 deletions include/fmt/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,8 @@ template <typename Char> class basic_string_view {
size_t size_;

public:
using char_type = Char;
using char_type FMT_DEPRECATED_ALIAS = Char;
using value_type = Char;
using iterator = const Char*;

FMT_CONSTEXPR basic_string_view() FMT_NOEXCEPT : data_(nullptr), size_(0) {}
Expand Down Expand Up @@ -471,7 +472,7 @@ struct is_string : std::is_class<decltype(to_string_view(std::declval<S>()))> {
template <typename S, typename = void> struct char_t_impl {};
template <typename S> struct char_t_impl<S, enable_if_t<is_string<S>::value>> {
using result = decltype(to_string_view(std::declval<S>()));
using type = typename result::char_type;
using type = typename result::value_type;
};

struct error_handler {
Expand Down
6 changes: 5 additions & 1 deletion test/core-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,12 @@ TEST(ArgTest, VisitInvalidArg) {
fmt::visit_format_arg(visitor, arg);
}

TEST(StringViewTest, ValueType) {
static_assert(std::is_same<string_view::value_type, char>::value, "");
}

TEST(StringViewTest, Length) {
// Test that StringRef::size() returns string length, not buffer size.
// Test that string_view::size() returns string length, not buffer size.
char str[100] = "some string";
EXPECT_EQ(std::strlen(str), string_view(str).size());
EXPECT_LT(std::strlen(str), sizeof(str));
Expand Down

0 comments on commit dc240cc

Please sign in to comment.