diff --git a/doc/validate.md b/doc/validate.md index d30ee2b..d9781db 100644 --- a/doc/validate.md +++ b/doc/validate.md @@ -366,15 +366,15 @@ This is not supposed to be used for validators. If an constraint is provided it will be updated with the value of the parsed integer. This is supposed to be used for validators only. -**`std::vector strings([args], Integer count)`** -**`std::vector strings([args], Integer count, char separator)`** -**`std::vector integers([args], Integer count)`** -**`std::vector integers([args], Integer count, char separator)`** -**`std::vector reals([args], Integer count)`** -**`std::vector reals([args], Integer count, char separator)`** -**`std::vector realsStrict([args], Integer count)`** -**`std::vector realsStrict([args], Integer count, char separator)`** -Will extract the next `count` tokens by calling `string([args])`, `integer([args])` or `real([args])`. +**`std::vector strings(Integer count, [args])`** +**`std::vector strings(Integer count, [args], char separator)`** +**`std::vector integers(Integer count, [args])`** +**`std::vector integers(Integer count, [args], char separator)`** +**`std::vector reals(Integer count, [args])`** +**`std::vector reals(Integer count, [args], char separator)`** +**`std::vector realsStrict(Integer count, [args])`** +**`std::vector realsStrict(Integer count, [args], char separator)`** +Will extract the next `count` tokens by calling `string([args])`, `integer([args])`, `real([args])`, or `realStrict([args])`. The tokens are expected to be separated by the char `separator` which must be `space` or `newline`. If this parameter is not provided a `space` is expected. diff --git a/example/answerValidator.cpp b/example/answerValidator.cpp index 24ce54c..5aea77d 100644 --- a/example/answerValidator.cpp +++ b/example/answerValidator.cpp @@ -10,7 +10,7 @@ int main(int argc, char **argv) { Integer t = testIn.integer(); // read the number of testcases - ans.integers(0, 100, t, NEWLINE); // for each testcase there should be one answer separated by newline + ans.integers(t, 0, 100, NEWLINE); // for each testcase there should be one answer separated by newline ans.newline(); // should also end with newline ans.eof(); // there should be nothing else juryOut << "OK possible" << AC; diff --git a/src/validate.h b/src/validate.h index ac368d8..c690849 100644 --- a/src/validate.h +++ b/src/validate.h @@ -20,7 +20,7 @@ // reproducable fashion. (The randomness is consistent across compilers and // // machines) // //============================================================================// -// version 2.6.5 // +// version 3.0.1 // // https://github.com/mzuenni/icpc-header // //============================================================================// @@ -1973,6 +1973,7 @@ class ParameterBase { public: std::string asString() const { + judgeAssert(token.has_value(), "asString(): missing arg"); return std::string(token.value()); } @@ -1981,6 +1982,7 @@ class ParameterBase { } Integer asInteger() const { + judgeAssert(token.has_value(), "asInteger(): missing arg"); return parse(token.value()); } @@ -1989,6 +1991,7 @@ class ParameterBase { } Real asReal() const { + judgeAssert(token.has_value(), "asReal(): missing arg"); return parse(token.value()); } @@ -2482,7 +2485,7 @@ class InputStream final { } template - std::vector strings(Args... args, Integer count, char separator) { + std::vector strings(Integer count, Args... args, char separator) { auto sepCall = checkSeparator(separator); std::vector res(count); for (std::size_t i = 0; i < res.size(); i++) { @@ -2496,29 +2499,29 @@ class InputStream final { return strings<>(count, separator); } - std::vector strings(Integer lower, Integer upper, - Integer count, char separator = DEFAULT_SEPARATOR) { - return strings(lower, upper, count, separator); + std::vector strings(Integer count, Integer lower, Integer upper, + char separator = DEFAULT_SEPARATOR) { + return strings(count, lower, upper, separator); } - std::vector strings(Integer lower, Integer upper, Constraint& constraint, - Integer count, char separator = DEFAULT_SEPARATOR) { - return strings(lower, upper, constraint, count, separator); + std::vector strings(Integer count, Integer lower, Integer upper, + Constraint& constraint, char separator = DEFAULT_SEPARATOR) { + return strings(count, lower, upper, constraint, separator); } - std::vector strings(const std::regex& pattern, - Integer count, char separator = DEFAULT_SEPARATOR) { - return strings(pattern, count, separator); + std::vector strings(Integer count, const std::regex& pattern, + char separator = DEFAULT_SEPARATOR) { + return strings(count, pattern, separator); } - std::vector strings(const std::regex& pattern, Integer lower, Integer upper, - Integer count, char separator = DEFAULT_SEPARATOR) { - return strings(pattern, lower, upper, count, separator); + std::vector strings(Integer count, const std::regex& pattern, Integer lower, Integer upper, + char separator = DEFAULT_SEPARATOR) { + return strings(count, pattern, lower, upper, separator); } - std::vector strings(const std::regex& pattern, Integer lower, Integer upper, Constraint& constraint, - Integer count, char separator = DEFAULT_SEPARATOR) { - return strings(pattern, lower, upper, constraint, count, separator); + std::vector strings(Integer count, const std::regex& pattern, Integer lower, Integer upper, + Constraint& constraint, char separator = DEFAULT_SEPARATOR) { + return strings(count, pattern, lower, upper, constraint, separator); } Integer integer() { @@ -2541,7 +2544,7 @@ class InputStream final { } template - std::vector integers(Args... args, Integer count, char separator) { + std::vector integers(Integer count, Args... args, char separator) { auto sepCall = checkSeparator(separator); std::vector res(count); for (std::size_t i = 0; i < res.size(); i++) { @@ -2555,14 +2558,14 @@ class InputStream final { return integers<>(count, separator); } - std::vector integers(Integer lower, Integer upper, - Integer count, char separator = DEFAULT_SEPARATOR) { - return integers(lower, upper, count, separator); + std::vector integers(Integer count, Integer lower, Integer upper, + char separator = DEFAULT_SEPARATOR) { + return integers(count, lower, upper, separator); } - std::vector integers(Integer lower, Integer upper, Constraint& constraint, - Integer count, char separator = DEFAULT_SEPARATOR) { - return integers(lower, upper, constraint, count, separator); + std::vector integers(Integer count, Integer lower, Integer upper, + Constraint& constraint, char separator = DEFAULT_SEPARATOR) { + return integers(count, lower, upper, constraint, separator); } // this does not allow NaN or Inf! @@ -2589,7 +2592,7 @@ class InputStream final { } template - std::vector reals(Args... args, Integer count, char separator) { + std::vector reals(Integer count, Args... args, char separator) { auto sepCall = checkSeparator(separator); std::vector res(count); for (std::size_t i = 0; i < res.size(); i++) { @@ -2603,14 +2606,14 @@ class InputStream final { return reals<>(count, separator); } - std::vector reals(Real lower, Real upper, - Integer count, char separator = DEFAULT_SEPARATOR) { - return reals(lower, upper, count, separator); + std::vector reals(Integer count, Real lower, Real upper, + char separator = DEFAULT_SEPARATOR) { + return reals(count, lower, upper, separator); } - std::vector reals(Real lower, Real upper, Constraint& constraint, - Integer count, char separator = DEFAULT_SEPARATOR) { - return reals(lower, upper, constraint, count, separator); + std::vector reals(Integer count, Real lower, Real upper, + Constraint& constraint, char separator = DEFAULT_SEPARATOR) { + return reals(count, lower, upper, constraint, separator); } Real realStrict(Real lower, Real upper, Integer minDecimals, Integer maxDecimals) {// does not use eps @@ -2643,7 +2646,7 @@ class InputStream final { } template - std::vector realsStrict(Args... args, Integer count, char separator) { + std::vector realsStrict(Integer count, Args... args, char separator) { auto sepCall = checkSeparator(separator); std::vector res(count); for (std::size_t i = 0; i < res.size(); i++) { @@ -2653,14 +2656,14 @@ class InputStream final { return res; } - std::vector realsStrict(Real lower, Real upper, Integer minDecimals, Integer maxDecimals, - Integer count, char separator = DEFAULT_SEPARATOR) { - return realsStrict(lower, upper, minDecimals, maxDecimals, count, separator); + std::vector realsStrict(Integer count, Real lower, Real upper, Integer minDecimals, Integer maxDecimals, + char separator = DEFAULT_SEPARATOR) { + return realsStrict(count, lower, upper, minDecimals, maxDecimals, separator); } - std::vector realsStrict(Real lower, Real upper, Integer minDecimals, Integer maxDecimals, Constraint& constraint, - Integer count, char separator = DEFAULT_SEPARATOR) { - return realsStrict(lower, upper, minDecimals, maxDecimals, constraint, count, separator); + std::vector realsStrict(Integer count, Real lower, Real upper, Integer minDecimals, Integer maxDecimals, + Constraint& constraint, char separator = DEFAULT_SEPARATOR) { + return realsStrict(count, lower, upper, minDecimals, maxDecimals, constraint, separator); } void expectString(std::string_view expected) { diff --git a/test/validate.cpp b/test/validate.cpp index d933bd5..8b53ac2 100644 --- a/test/validate.cpp +++ b/test/validate.cpp @@ -533,6 +533,17 @@ void checkInputStream() { InputStream in(rawIn, true, true, ValidateBase::juryOut, Verdicts::Verdict(23)); in.realStrict(-10, 10, 0, 3); }, 23); + assertNoException([](){ + std::istringstream rawIn("Das ist 1\n2 3 test 3.1 4.1 5.9 ende\n"); + InputStream in(rawIn, false, false, ValidateBase::juryOut, Verdicts::FAIL); + + in.strings(2, 3, 4); + in.integers(3, 1, 4); + in.expectString("test"); + in.reals(3, 3.0, 6.0); + in.expectString("ende"); + in.eof(); + }); } void checkJoin() {