Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowing formatting non-copyable ranges. #3290

Merged
merged 4 commits into from
Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion include/fmt/ranges.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ template <typename T>
struct has_mutable_begin_end<
T, void_t<decltype(detail::range_begin(std::declval<T>())),
decltype(detail::range_end(std::declval<T>())),
enable_if_t<std::is_copy_constructible<T>::value>>>
// the extra int here is because older versions of MSVC don't
// SFINAE properly unless there are distinct types
int>>
: std::true_type {};

template <typename T>
Expand Down
6 changes: 3 additions & 3 deletions test/ranges-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ template <typename T> class noncopyable_range {
std::vector<T> vec;

public:
using const_iterator = typename ::std::vector<T>::const_iterator;
using iterator = typename ::std::vector<T>::iterator;

template <typename... Args>
explicit noncopyable_range(Args&&... args)
Expand All @@ -202,8 +202,8 @@ template <typename T> class noncopyable_range {
noncopyable_range(noncopyable_range const&) = delete;
noncopyable_range(noncopyable_range&) = delete;

const_iterator begin() const { return vec.begin(); }
const_iterator end() const { return vec.end(); }
iterator begin() { return vec.begin(); }
iterator end() { return vec.end(); }
};

TEST(ranges_test, range) {
Expand Down