Give Op<N>() AppleScript-like semantics, i.e. for negative N it indexes relative...
[oota-llvm.git] / include / llvm / User.h
index f2df23e34125570414dca070f1b9b4c7d54d2b13..1a88ce0cce853b2dba3478cd7ac577df91784d4f 100644 (file)
@@ -83,11 +83,16 @@ public:
     assert(0 && "Constructor throws?");
   }
 protected:
-  template <unsigned Idx> Use &Op() {
-    return OperandTraits<User>::op_begin(this)[Idx];
+  template <int Idx, typename U> static Use &OpFrom(const U *that) {
+    return Idx < 0
+      ? OperandTraits<U>::op_end(const_cast<U*>(that))[Idx]
+      : OperandTraits<U>::op_begin(const_cast<U*>(that))[Idx];
   }
-  template <unsigned Idx> const Use &Op() const {
-    return OperandTraits<User>::op_begin(const_cast<User*>(this))[Idx];
+  template <int Idx> Use &Op() {
+    return OpFrom<Idx>(this);
+  }
+  template <int Idx> const Use &Op() const {
+    return OpFrom<Idx>(this);
   }
 public:
   Value *getOperand(unsigned i) const {