ostream.h 719 B

1234567891011121314151617181920212223
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #ifndef COMMON_OSTREAM_H_
  5. #define COMMON_OSTREAM_H_
  6. #include "llvm/Support/raw_ostream.h"
  7. namespace Carbon {
  8. // Support ostream << for types which implement:
  9. // void Print(llvm::raw_ostream& out) const;
  10. template <typename T, typename std::enable_if<std::is_member_function_pointer<
  11. decltype(&T::Print)>::value>::type* = nullptr>
  12. auto operator<<(llvm::raw_ostream& out, const T& obj) -> llvm::raw_ostream& {
  13. obj.Print(out);
  14. return out;
  15. }
  16. } // namespace Carbon
  17. #endif // COMMON_OSTREAM_H_