Skip to content

Commit

Permalink
Release v1.1.1: Temporary fix for #56
Browse files Browse the repository at this point in the history
  • Loading branch information
eliaskosunen committed Mar 16, 2022
1 parent dafe7c4 commit 72181aa
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
# 1.1.1

_Released 2022-03-16_

* Fix issue with values being skipped when using files and `file.sync()` (#56)
* Every call to `file.sync()` needs to be accompanied by a call to `reset_begin_iterator()` to the result object
* This is a temporary fix, permanent fix coming in v2.0.0

```cpp
int i;
auto ret = scn::scan(scn::cstdin(), "{}", i);
scn::cstdin().sync();
ret.range().reset_begin_iterator();

// Not necessary with input and prompt
ret = scn::input("{}", i);
```

# 1.1

_Released 2022-03-12_
Expand Down
7 changes: 6 additions & 1 deletion include/scn/detail/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
#include <cstdio>
#include <string>

#include "range.h"
#include "../util/algorithm.h"
#include "range.h"

namespace scn {
SCN_BEGIN_NAMESPACE
Expand Down Expand Up @@ -260,6 +260,11 @@ namespace scn {
return !operator<(o);
}

void reset_begin_iterator() const noexcept
{
m_current = 0;
}

private:
friend class basic_file;

Expand Down
36 changes: 36 additions & 0 deletions include/scn/detail/range.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,38 @@ namespace scn {
SCN_BEGIN_NAMESPACE

namespace detail {
namespace _reset_begin_iterator {
struct fn {
private:
template <typename Iterator>
static auto
impl(Iterator& it, priority_tag<1>) noexcept(
noexcept(it.reset_begin_iterator()))
-> decltype(it.reset_begin_iterator())
{
return it.reset_begin_iterator();
}

template <typename Iterator>
static void impl(Iterator&, size_t, priority_tag<0>) noexcept
{
}

public:
template <typename Iterator>
auto operator()(Iterator& it) const
noexcept(noexcept(fn::impl(it, priority_tag<1>{})))
-> decltype(fn::impl(it, priority_tag<1>{}))
{
return fn::impl(it, priority_tag<1>{});
}
};
} // namespace _reset_begin_iterator
namespace {
static constexpr auto& reset_begin_iterator =
static_const<detail::_reset_begin_iterator::fn>::value;
}

template <typename Iterator, typename = void>
struct extract_char_type;
template <typename Iterator>
Expand Down Expand Up @@ -356,6 +388,10 @@ namespace scn {
m_read = 0;
}

void reset_begin_iterator() {
detail::reset_begin_iterator(m_begin);
}

/**
* Construct a new source range from `begin()` and `end()`, and wrap
* it in a new `range_wrapper`.
Expand Down
1 change: 1 addition & 0 deletions include/scn/scan/scan.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ namespace scn {
auto& range = stdin_range<CharT>();
auto ret = detail::scan_boilerplate(range, f, a...);
range.sync();
ret.range().reset_begin_iterator();
return ret;
}
#endif
Expand Down

0 comments on commit 72181aa

Please sign in to comment.