Skip to content

Commit

Permalink
Make ranges only depend on fmt/base.h
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Jan 13, 2024
1 parent da0f84c commit f9bed1b
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
11 changes: 11 additions & 0 deletions include/fmt/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,17 @@ struct has_to_string_view<
T, void_t<decltype(detail::to_string_view(std::declval<T>()))>>
: std::true_type {};

template <typename CharT, CharT... C> struct string_literal {
static constexpr CharT value[sizeof...(C)] = {C...};
constexpr operator basic_string_view<CharT>() const {
return {value, sizeof...(C)};
}
};
#if FMT_CPLUSPLUS < 201703L
template <typename CharT, CharT... C>
constexpr CharT string_literal<CharT, C...>::value[sizeof...(C)];
#endif

enum class type {
none_type,
// Integer types should go first,
Expand Down
12 changes: 0 additions & 12 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,18 +292,6 @@ template <typename Char> using std_string_view = std::basic_string_view<Char>;
template <typename T> struct std_string_view {};
#endif

template <typename CharT, CharT... C> struct string_literal {
static constexpr CharT value[sizeof...(C)] = {C...};
constexpr operator basic_string_view<CharT>() const {
return {value, sizeof...(C)};
}
};

#if FMT_CPLUSPLUS < 201703L
template <typename CharT, CharT... C>
constexpr CharT string_literal<CharT, C...>::value[sizeof...(C)];
#endif

// Implementation of std::bit_cast for pre-C++20.
template <typename To, typename From, FMT_ENABLE_IF(sizeof(To) == sizeof(From))>
FMT_CONSTEXPR20 auto bit_cast(const From& from) -> To {
Expand Down
13 changes: 6 additions & 7 deletions include/fmt/ranges.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
#define FMT_RANGES_H_

#include <initializer_list>
#include <iterator>
#include <tuple>
#include <type_traits>

#include "format.h"
#include "base.h"

FMT_BEGIN_NAMESPACE

Expand Down Expand Up @@ -676,12 +677,10 @@ struct formatter<tuple_join_view<Char, T...>, Char> {
typename FormatContext::iterator {
auto out = std::get<sizeof...(T) - N>(formatters_)
.format(std::get<sizeof...(T) - N>(value.tuple), ctx);
if (N > 1) {
out = std::copy(value.sep.begin(), value.sep.end(), out);
ctx.advance_to(out);
return do_format(value, ctx, std::integral_constant<size_t, N - 1>());
}
return out;
if (N <= 1) return out;
out = detail::copy<Char>(value.sep, out);
ctx.advance_to(out);
return do_format(value, ctx, std::integral_constant<size_t, N - 1>());
}
};

Expand Down
1 change: 1 addition & 0 deletions test/ranges-odr-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <vector>

#include "fmt/format.h"
#include "fmt/ranges.h"
#include "gtest/gtest.h"

Expand Down
1 change: 1 addition & 0 deletions test/ranges-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# include <ranges>
#endif

#include "fmt/format.h"
#include "gtest/gtest.h"

#if !FMT_GCC_VERSION || FMT_GCC_VERSION >= 601
Expand Down

0 comments on commit f9bed1b

Please sign in to comment.