catch_repeat.hpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. * Created by Joachim on 16/04/2019.
  3. * Adapted from donated nonius code.
  4. *
  5. * Distributed under the Boost Software License, Version 1.0. (See accompanying
  6. * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. */
  8. // repeat algorithm
  9. #ifndef TWOBLUECUBES_CATCH_DETAIL_REPEAT_HPP_INCLUDED
  10. #define TWOBLUECUBES_CATCH_DETAIL_REPEAT_HPP_INCLUDED
  11. #include <type_traits>
  12. #include <utility>
  13. namespace Catch {
  14. namespace Benchmark {
  15. namespace Detail {
  16. template <typename Fun>
  17. struct repeater {
  18. void operator()(int k) const {
  19. for (int i = 0; i < k; ++i) {
  20. fun();
  21. }
  22. }
  23. Fun fun;
  24. };
  25. template <typename Fun>
  26. repeater<typename std::decay<Fun>::type> repeat(Fun&& fun) {
  27. return { std::forward<Fun>(fun) };
  28. }
  29. } // namespace Detail
  30. } // namespace Benchmark
  31. } // namespace Catch
  32. #endif // TWOBLUECUBES_CATCH_DETAIL_REPEAT_HPP_INCLUDED