summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Hodge <tpg@ucc.asn.au>2019-10-13 13:44:21 +0800
committerJohn Hodge <tpg@ucc.asn.au>2019-10-13 13:44:21 +0800
commit5548f38462ae588a059d0b656cce923ec424ef1b (patch)
tree49a3418ba5db8b4873a4bf6cffbc9576d9e0db28
parent1e248ee68d71731de808af120eca61d35f6235f7 (diff)
downloadmrust-5548f38462ae588a059d0b656cce923ec424ef1b.tar.gz
Missing file (from a few weeks ago, oops)
-rw-r--r--src/slice.hpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/slice.hpp b/src/slice.hpp
new file mode 100644
index 00000000..2011e8c2
--- /dev/null
+++ b/src/slice.hpp
@@ -0,0 +1,35 @@
+#pragma once
+
+#include <stddef.h>
+
+template<typename T>
+class slice
+{
+ T* ptr;
+ size_t len;
+public:
+ slice(T* ptr, size_t len): ptr(ptr), len(len) {}
+
+ T* begin() { return ptr; }
+ T* end() { return ptr + len; }
+ const T* begin() const { return ptr; }
+ const T* end() const { return ptr + len; }
+};
+
+namespace std {
+ template<typename T>
+ ostream& operator<<(ostream& os, const slice<T>& x) {
+ os << "[";
+ bool first = true;
+ for(const auto& e : x)
+ {
+ if(!first)
+ os << ",";
+ first = false;
+ os << e;
+ }
+ os << "]";
+ return os;
+ }
+}
+