fail_count.ipp 974 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //
  2. // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // Official repository: https://github.com/boostorg/beast
  8. //
  9. #ifndef BOOST_BEAST_TEST_IMPL_FAIL_COUNT_IPP
  10. #define BOOST_BEAST_TEST_IMPL_FAIL_COUNT_IPP
  11. #include <boost/beast/_experimental/test/fail_count.hpp>
  12. #include <boost/throw_exception.hpp>
  13. namespace boost {
  14. namespace beast {
  15. namespace test {
  16. fail_count::
  17. fail_count(
  18. std::size_t n,
  19. error_code ev)
  20. : n_(n)
  21. , ec_(ev)
  22. {
  23. }
  24. void
  25. fail_count::
  26. fail()
  27. {
  28. if(i_ < n_)
  29. ++i_;
  30. if(i_ == n_)
  31. BOOST_THROW_EXCEPTION(system_error{ec_});
  32. }
  33. bool
  34. fail_count::
  35. fail(error_code& ec)
  36. {
  37. if(i_ < n_)
  38. ++i_;
  39. if(i_ == n_)
  40. {
  41. ec = ec_;
  42. return true;
  43. }
  44. ec = {};
  45. return false;
  46. }
  47. } // test
  48. } // beast
  49. } // boost
  50. #endif