labeled.h 604 B

12345678910111213141516171819
  1. #pragma once
  2. #include <util/generic/va_args.h>
  3. /**
  4. * Generates an output sequence for the provided expressions that is formatted
  5. * as a labeled comma-separated list.
  6. *
  7. * Example usage:
  8. * @code
  9. * int a = 1, b = 2, c = 3;
  10. * stream << LabeledOutput(a, b, c, a + b + c);
  11. * // Outputs "a = 1, b = 2, c = 3, a + b + c = 6"
  12. * @endcode
  13. */
  14. #define LabeledOutput(...) "" Y_PASS_VA_ARGS(Y_MAP_ARGS_WITH_LAST(__LABELED_OUTPUT_NONLAST__, __LABELED_OUTPUT_IMPL__, __VA_ARGS__))
  15. #define __LABELED_OUTPUT_IMPL__(x) << #x " = " << (x)
  16. #define __LABELED_OUTPUT_NONLAST__(x) __LABELED_OUTPUT_IMPL__(x) << ", "