amount.hpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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_UNIT_TEST_AMOUNT_HPP
  10. #define BOOST_BEAST_UNIT_TEST_AMOUNT_HPP
  11. #include <cstddef>
  12. #include <ostream>
  13. #include <string>
  14. namespace boost {
  15. namespace beast {
  16. namespace unit_test {
  17. /** Utility for producing nicely composed output of amounts with units. */
  18. class amount
  19. {
  20. private:
  21. std::size_t n_;
  22. std::string const& what_;
  23. public:
  24. amount(amount const&) = default;
  25. amount& operator=(amount const&) = delete;
  26. template<class = void>
  27. amount(std::size_t n, std::string const& what);
  28. friend
  29. std::ostream&
  30. operator<<(std::ostream& s, amount const& t);
  31. };
  32. template<class>
  33. amount::amount(std::size_t n, std::string const& what)
  34. : n_(n)
  35. , what_(what)
  36. {
  37. }
  38. inline
  39. std::ostream&
  40. operator<<(std::ostream& s, amount const& t)
  41. {
  42. s << t.n_ << " " << t.what_ <<((t.n_ != 1) ? "s" : "");
  43. return s;
  44. }
  45. } // unit_test
  46. } // beast
  47. } // boost
  48. #endif