mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-24 22:24:54 +00:00
ADT: Add ilist_node::get{Prev,Next}Node, which return the adjacent node or null.
- This provides a convenient alternative to using something llvm::prior or manual iterator access, for example:: if (T *Prev = foo->getPrevNode()) ... instead of:: iterator it(foo); if (it != begin()) { --it; ... } - Chris, please review. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@103647 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
39
unittests/ADT/ilistTest.cpp
Normal file
39
unittests/ADT/ilistTest.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
//===- llvm/unittest/ADT/APInt.cpp - APInt unit tests ---------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <ostream>
|
||||
#include "gtest/gtest.h"
|
||||
#include "llvm/ADT/ilist.h"
|
||||
#include "llvm/ADT/ilist_node.h"
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
namespace {
|
||||
|
||||
struct Node : ilist_node<Node> {
|
||||
int Value;
|
||||
|
||||
Node() {}
|
||||
Node(int _Value) : Value(_Value) {}
|
||||
};
|
||||
|
||||
TEST(ilistTest, Basic) {
|
||||
ilist<Node> List;
|
||||
List.push_back(Node(1));
|
||||
EXPECT_EQ(1, List.back().Value);
|
||||
EXPECT_EQ(0, List.back().getPrevNode());
|
||||
EXPECT_EQ(0, List.back().getNextNode());
|
||||
|
||||
List.push_back(Node(2));
|
||||
EXPECT_EQ(2, List.back().Value);
|
||||
EXPECT_EQ(2, List.front().getNextNode()->Value);
|
||||
EXPECT_EQ(1, List.back().getPrevNode()->Value);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user