diff options
author | Chris Bieneman <beanz@apple.com> | 2015-05-28 20:38:12 +0000 |
---|---|---|
committer | Chris Bieneman <beanz@apple.com> | 2015-05-28 20:38:12 +0000 |
commit | f2d1c73cf3eef7623ac375b5de0e805eff2908d9 (patch) | |
tree | 65a9372eb20045b0e8bda221df19c7e2dda44680 /llvm/include/llvm/Support/CommandLine.h | |
parent | bab1a075df4f2d2e2573910c74e8ed183d8a8154 (diff) | |
download | bcm5719-llvm-f2d1c73cf3eef7623ac375b5de0e805eff2908d9.tar.gz bcm5719-llvm-f2d1c73cf3eef7623ac375b5de0e805eff2908d9.zip |
Refactoring cl::list_storage from "is a" to "has a" std::vector.
Summary: This isn't necessarily an ideal change, and I want to at least reduce the API surface area, but for the new API we really shouldn't be relying on cl::list being a std::vector.
Reviewers: chandlerc
Reviewed By: chandlerc
Subscribers: llvm-commits
Differential Revision: http://reviews.llvm.org/D10093
llvm-svn: 238485
Diffstat (limited to 'llvm/include/llvm/Support/CommandLine.h')
-rw-r--r-- | llvm/include/llvm/Support/CommandLine.h | 59 |
1 files changed, 52 insertions, 7 deletions
diff --git a/llvm/include/llvm/Support/CommandLine.h b/llvm/include/llvm/Support/CommandLine.h index bd1d1cb6dc9..24630dbbdc1 100644 --- a/llvm/include/llvm/Support/CommandLine.h +++ b/llvm/include/llvm/Support/CommandLine.h @@ -1284,16 +1284,61 @@ public: } }; -// Define how to hold a class type object, such as a string. Since we can -// inherit from a class, we do so. This makes us exactly compatible with the -// object in all cases that it is used. +// Define how to hold a class type object, such as a string. +// Originally this code inherited from std::vector. In transitioning to a new +// API for command line options we should change this. The new implementation +// of this list_storage specialization implements the minimum subset of the +// std::vector API required for all the current clients. // -template <class DataType> -class list_storage<DataType, bool> : public std::vector<DataType> { +// FIXME: Reduce this API to a more narrow subset of std::vector +// +template <class DataType> class list_storage<DataType, bool> { + std::vector<DataType> Storage; + public: - template <class T> void addValue(const T &V) { - std::vector<DataType>::push_back(V); + typedef typename std::vector<DataType>::iterator iterator; + + iterator begin() { return Storage.begin(); } + iterator end() { return Storage.end(); } + + typedef typename std::vector<DataType>::const_iterator const_iterator; + const_iterator begin() const { return Storage.begin(); } + const_iterator end() const { return Storage.end(); } + + typedef typename std::vector<DataType>::size_type size_type; + size_type size() const { return Storage.size(); } + + bool empty() const { return Storage.empty(); } + + void push_back(const DataType &value) { Storage.push_back(value); } + void push_back(DataType &&value) { Storage.push_back(value); } + + typedef typename std::vector<DataType>::reference reference; + typedef typename std::vector<DataType>::const_reference const_reference; + reference operator[](size_type pos) { return Storage[pos]; } + const_reference operator[](size_type pos) const { return Storage[pos]; } + + iterator erase(const_iterator pos) { return Storage.erase(pos); } + iterator erase(const_iterator first, const_iterator last) { + return Storage.erase(first, last); + } + + iterator insert(const_iterator pos, const DataType &value) { + return Storage.insert(pos, value); + } + iterator insert(const_iterator pos, DataType &&value) { + return Storage.insert(pos, value); } + + reference front() { return Storage.front(); } + const_reference front() const { return Storage.front(); } + + operator std::vector<DataType>&() { return Storage; } + operator ArrayRef<DataType>() { return Storage; } + std::vector<DataType> *operator&() { return &Storage; } + const std::vector<DataType> *operator&() const { return &Storage; } + + template <class T> void addValue(const T &V) { Storage.push_back(V); } }; //===----------------------------------------------------------------------===// |