Use llvm::ListSeparator for simpler separators (#671)

I was looking for something like this, I think it's a straightforward simplification for code. Internally, it handles skipping the separator on the first print.

See the bottom of: https://llvm.org/doxygen/StringExtras_8h_source.html
This commit is contained in:
Jon Meow
2021-07-23 08:39:58 -07:00
committed by GitHub
parent f35cda7a99
commit edbc3f7716
5 changed files with 23 additions and 32 deletions
+4 -1
View File
@@ -4,6 +4,8 @@
#include "executable_semantics/interpreter/heap.h"
#include "llvm/ADT/StringExtras.h"
namespace Carbon {
auto Heap::AllocateValue(const Value* v) -> Address {
@@ -48,9 +50,10 @@ void Heap::Deallocate(const Address& address) {
}
void Heap::Print(llvm::raw_ostream& out) const {
llvm::ListSeparator sep;
for (size_t i = 0; i < values_.size(); ++i) {
out << sep;
PrintAddress(Address(i), out);
out << ", ";
}
}