2014-03-04 03:20:40 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is dual licensed under the MIT and the University of Illinois Open
|
|
|
|
// Source Licenses. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2016-03-15 07:07:58 +08:00
|
|
|
#ifndef NASTY_CONTAINERS_H
|
|
|
|
#define NASTY_CONTAINERS_H
|
2014-03-04 03:20:40 +08:00
|
|
|
|
2016-03-15 07:07:58 +08:00
|
|
|
#include <cassert>
|
2014-03-04 03:20:40 +08:00
|
|
|
#include <vector>
|
|
|
|
#include <list>
|
|
|
|
|
2016-10-12 17:31:26 +08:00
|
|
|
#include "test_macros.h"
|
|
|
|
|
2014-03-04 03:20:40 +08:00
|
|
|
template <class T>
|
|
|
|
class nasty_vector
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef typename std::vector<T> nested_container;
|
|
|
|
typedef typename nested_container::value_type value_type;
|
|
|
|
typedef typename nested_container::reference reference;
|
|
|
|
typedef typename nested_container::const_reference const_reference;
|
|
|
|
typedef typename nested_container::iterator iterator;
|
|
|
|
typedef typename nested_container::const_iterator const_iterator;
|
|
|
|
|
|
|
|
typedef typename nested_container::size_type size_type;
|
|
|
|
typedef typename nested_container::difference_type difference_type;
|
|
|
|
typedef typename nested_container::pointer pointer;
|
|
|
|
typedef typename nested_container::const_pointer const_pointer;
|
|
|
|
|
|
|
|
typedef typename nested_container::reverse_iterator reverse_iterator;
|
|
|
|
typedef typename nested_container::const_reverse_iterator const_reverse_iterator;
|
|
|
|
|
|
|
|
nasty_vector() : v_() {}
|
|
|
|
explicit nasty_vector(size_type n) : v_(n) {}
|
|
|
|
nasty_vector(size_type n, const value_type& value) : v_(n, value) {}
|
|
|
|
template <class InputIterator> nasty_vector(InputIterator first, InputIterator last) : v_(first, last) {}
|
2017-04-19 09:02:49 +08:00
|
|
|
#if TEST_STD_VER >= 11
|
2014-03-04 03:20:40 +08:00
|
|
|
nasty_vector(std::initializer_list<value_type> il) : v_(il) {}
|
|
|
|
#endif
|
|
|
|
~nasty_vector() {}
|
|
|
|
|
|
|
|
template <class InputIterator>
|
|
|
|
void assign(InputIterator first, InputIterator last) { v_.assign(first, last); }
|
|
|
|
void assign(size_type n, const value_type& u) { v_.assign(n, u); }
|
2017-04-19 09:02:49 +08:00
|
|
|
#if TEST_STD_VER >= 11
|
2014-03-04 03:20:40 +08:00
|
|
|
void assign(std::initializer_list<value_type> il) { v_.assign(il); }
|
|
|
|
#endif
|
|
|
|
|
2016-10-12 17:31:26 +08:00
|
|
|
iterator begin() TEST_NOEXCEPT { return v_.begin(); }
|
|
|
|
const_iterator begin() const TEST_NOEXCEPT { return v_.begin(); }
|
|
|
|
iterator end() TEST_NOEXCEPT { return v_.end(); }
|
|
|
|
const_iterator end() const TEST_NOEXCEPT { return v_.end(); }
|
|
|
|
|
|
|
|
reverse_iterator rbegin() TEST_NOEXCEPT { return v_.rbegin(); }
|
|
|
|
const_reverse_iterator rbegin() const TEST_NOEXCEPT { return v_.rbegin(); }
|
|
|
|
reverse_iterator rend() TEST_NOEXCEPT { return v_.rend(); }
|
|
|
|
const_reverse_iterator rend() const TEST_NOEXCEPT { return v_.rend(); }
|
|
|
|
|
|
|
|
const_iterator cbegin() const TEST_NOEXCEPT { return v_.cbegin(); }
|
|
|
|
const_iterator cend() const TEST_NOEXCEPT { return v_.cend(); }
|
|
|
|
const_reverse_iterator crbegin() const TEST_NOEXCEPT { return v_.crbegin(); }
|
|
|
|
const_reverse_iterator crend() const TEST_NOEXCEPT { return v_.crend(); }
|
|
|
|
|
|
|
|
size_type size() const TEST_NOEXCEPT { return v_.size(); }
|
|
|
|
size_type max_size() const TEST_NOEXCEPT { return v_.max_size(); }
|
|
|
|
size_type capacity() const TEST_NOEXCEPT { return v_.capacity(); }
|
|
|
|
bool empty() const TEST_NOEXCEPT { return v_.empty(); }
|
2014-03-04 03:20:40 +08:00
|
|
|
void reserve(size_type n) { v_.reserve(n); };
|
2016-10-12 17:31:26 +08:00
|
|
|
void shrink_to_fit() TEST_NOEXCEPT { v_.shrink_to_fit(); }
|
2014-03-04 03:20:40 +08:00
|
|
|
|
|
|
|
reference operator[](size_type n) { return v_[n]; }
|
|
|
|
const_reference operator[](size_type n) const { return v_[n]; }
|
|
|
|
reference at(size_type n) { return v_.at(n); }
|
|
|
|
const_reference at(size_type n) const { return v_.at(n); }
|
|
|
|
|
|
|
|
reference front() { return v_.front(); }
|
|
|
|
const_reference front() const { return v_.front(); }
|
|
|
|
reference back() { return v_.back(); }
|
|
|
|
const_reference back() const { return v_.back(); }
|
|
|
|
|
2016-10-12 17:31:26 +08:00
|
|
|
value_type* data() TEST_NOEXCEPT { return v_.data(); }
|
|
|
|
const value_type* data() const TEST_NOEXCEPT { return v_.data(); }
|
2014-03-04 03:20:40 +08:00
|
|
|
|
|
|
|
void push_back(const value_type& x) { v_.push_back(x); }
|
2017-04-19 09:02:49 +08:00
|
|
|
#if TEST_STD_VER >= 11
|
2014-03-04 03:20:40 +08:00
|
|
|
void push_back(value_type&& x) { v_.push_back(std::forward<value_type&&>(x)); }
|
|
|
|
template <class... Args>
|
|
|
|
void emplace_back(Args&&... args) { v_.emplace_back(std::forward<Args>(args)...); }
|
|
|
|
#endif
|
|
|
|
void pop_back() { v_.pop_back(); }
|
|
|
|
|
2017-04-19 09:02:49 +08:00
|
|
|
#if TEST_STD_VER >= 11
|
2014-03-04 03:20:40 +08:00
|
|
|
template <class... Args> iterator emplace(const_iterator pos, Args&&... args)
|
|
|
|
{ return v_.emplace(pos, std::forward<Args>(args)...); }
|
|
|
|
#endif
|
2016-06-02 05:35:39 +08:00
|
|
|
|
2014-03-04 03:20:40 +08:00
|
|
|
iterator insert(const_iterator pos, const value_type& x) { return v_.insert(pos, x); }
|
2017-04-19 09:02:49 +08:00
|
|
|
#if TEST_STD_VER >= 11
|
2014-03-04 03:20:40 +08:00
|
|
|
iterator insert(const_iterator pos, value_type&& x) { return v_.insert(pos, std::forward<value_type>(x)); }
|
|
|
|
#endif
|
|
|
|
iterator insert(const_iterator pos, size_type n, const value_type& x) { return v_.insert(pos, n, x); }
|
|
|
|
template <class InputIterator>
|
|
|
|
iterator insert(const_iterator pos, InputIterator first, InputIterator last)
|
|
|
|
{ return v_.insert(pos, first, last); }
|
|
|
|
|
2017-04-19 09:02:49 +08:00
|
|
|
#if TEST_STD_VER >= 11
|
2014-03-04 03:20:40 +08:00
|
|
|
iterator insert(const_iterator pos, std::initializer_list<value_type> il) { return v_.insert(pos, il); }
|
|
|
|
#endif
|
|
|
|
|
|
|
|
iterator erase(const_iterator pos) { return v_.erase(pos); }
|
|
|
|
iterator erase(const_iterator first, const_iterator last) { return v_.erase(first, last); }
|
|
|
|
|
2016-10-12 17:31:26 +08:00
|
|
|
void clear() TEST_NOEXCEPT { v_.clear(); }
|
2014-03-04 03:20:40 +08:00
|
|
|
|
|
|
|
void resize(size_type sz) { v_.resize(sz); }
|
|
|
|
void resize(size_type sz, const value_type& c) { v_.resize(sz, c); }
|
|
|
|
|
2016-10-12 17:31:26 +08:00
|
|
|
void swap(nasty_vector &nv)
|
|
|
|
#if TEST_STD_VER > 14
|
|
|
|
noexcept(std::is_nothrow_swappable<nested_container>::value)
|
|
|
|
#elif defined(_LIBCPP_VERSION)
|
|
|
|
TEST_NOEXCEPT_COND(std::__is_nothrow_swappable<nested_container>::value)
|
|
|
|
#endif
|
2014-03-04 03:20:40 +08:00
|
|
|
{ v_.swap(nv.v_); }
|
2016-06-02 05:35:39 +08:00
|
|
|
|
2016-03-15 07:07:58 +08:00
|
|
|
nasty_vector *operator &() { assert(false); return nullptr; } // nasty
|
|
|
|
const nasty_vector *operator &() const { assert(false); return nullptr; } // nasty
|
2016-06-02 05:35:39 +08:00
|
|
|
|
2014-03-04 03:20:40 +08:00
|
|
|
nested_container v_;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
bool operator==(const nasty_vector<T>& x, const nasty_vector<T>& y) { return x.v_ == y.v_; }
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
class nasty_list
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
typedef typename std::list<T> nested_container;
|
|
|
|
typedef typename nested_container::value_type value_type;
|
|
|
|
typedef typename nested_container::reference reference;
|
|
|
|
typedef typename nested_container::const_reference const_reference;
|
|
|
|
typedef typename nested_container::iterator iterator;
|
|
|
|
typedef typename nested_container::const_iterator const_iterator;
|
|
|
|
|
|
|
|
typedef typename nested_container::size_type size_type;
|
|
|
|
typedef typename nested_container::difference_type difference_type;
|
|
|
|
typedef typename nested_container::pointer pointer;
|
|
|
|
typedef typename nested_container::const_pointer const_pointer;
|
|
|
|
|
|
|
|
typedef typename nested_container::reverse_iterator reverse_iterator;
|
|
|
|
typedef typename nested_container::const_reverse_iterator const_reverse_iterator;
|
|
|
|
|
|
|
|
nasty_list() : l_() {}
|
|
|
|
explicit nasty_list(size_type n) : l_(n) {}
|
|
|
|
nasty_list(size_type n, const value_type& value) : l_(n,value) {}
|
|
|
|
template <class Iter>
|
|
|
|
nasty_list(Iter first, Iter last) : l_(first, last) {}
|
2017-04-19 09:02:49 +08:00
|
|
|
#if TEST_STD_VER >= 11
|
2014-03-04 03:20:40 +08:00
|
|
|
nasty_list(std::initializer_list<value_type> il) : l_(il) {}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
~nasty_list() {}
|
|
|
|
|
2017-04-19 09:02:49 +08:00
|
|
|
#if TEST_STD_VER >= 11
|
2014-03-04 03:20:40 +08:00
|
|
|
nasty_list& operator=(std::initializer_list<value_type> il) { l_ = il; return *this; }
|
|
|
|
#endif
|
|
|
|
template <class Iter>
|
|
|
|
void assign(Iter first, Iter last) { l_.assign(first, last); }
|
|
|
|
void assign(size_type n, const value_type& t) { l_.assign(n, t); }
|
2017-04-19 09:02:49 +08:00
|
|
|
#if TEST_STD_VER >= 11
|
2014-03-04 03:20:40 +08:00
|
|
|
void assign(std::initializer_list<value_type> il) { l_.assign(il); }
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2016-10-12 17:31:26 +08:00
|
|
|
iterator begin() TEST_NOEXCEPT { return l_.begin(); }
|
|
|
|
const_iterator begin() const TEST_NOEXCEPT { return l_.begin(); }
|
|
|
|
iterator end() TEST_NOEXCEPT { return l_.end(); }
|
|
|
|
const_iterator end() const TEST_NOEXCEPT { return l_.end(); }
|
2014-03-04 03:20:40 +08:00
|
|
|
|
2016-10-12 17:31:26 +08:00
|
|
|
reverse_iterator rbegin() TEST_NOEXCEPT { return l_.rbegin(); }
|
|
|
|
const_reverse_iterator rbegin() const TEST_NOEXCEPT { return l_.rbegin(); }
|
|
|
|
reverse_iterator rend() TEST_NOEXCEPT { return l_.rend(); }
|
|
|
|
const_reverse_iterator rend() const TEST_NOEXCEPT { return l_.rend(); }
|
2014-03-04 03:20:40 +08:00
|
|
|
|
2016-10-12 17:31:26 +08:00
|
|
|
const_iterator cbegin() const TEST_NOEXCEPT { return l_.cbegin(); }
|
|
|
|
const_iterator cend() const TEST_NOEXCEPT { return l_.cend(); }
|
|
|
|
const_reverse_iterator crbegin() const TEST_NOEXCEPT { return l_.crbegin(); }
|
|
|
|
const_reverse_iterator crend() const TEST_NOEXCEPT { return l_.crend(); }
|
2014-03-04 03:20:40 +08:00
|
|
|
|
|
|
|
reference front() { return l_.front(); }
|
|
|
|
const_reference front() const { return l_.front(); }
|
|
|
|
reference back() { return l_.back(); }
|
|
|
|
const_reference back() const { return l_.back(); }
|
|
|
|
|
2016-10-12 17:31:26 +08:00
|
|
|
size_type size() const TEST_NOEXCEPT { return l_.size(); }
|
|
|
|
size_type max_size() const TEST_NOEXCEPT { return l_.max_size(); }
|
|
|
|
bool empty() const TEST_NOEXCEPT { return l_.empty(); }
|
2014-03-04 03:20:40 +08:00
|
|
|
|
|
|
|
void push_front(const value_type& x) { l_.push_front(x); }
|
|
|
|
void push_back(const value_type& x) { l_.push_back(x); }
|
2017-04-19 09:02:49 +08:00
|
|
|
#if TEST_STD_VER >= 11
|
2014-03-04 03:20:40 +08:00
|
|
|
void push_back(value_type&& x) { l_.push_back(std::forward<value_type&&>(x)); }
|
|
|
|
void push_front(value_type&& x) { l_.push_back(std::forward<value_type&&>(x)); }
|
|
|
|
template <class... Args>
|
|
|
|
void emplace_back(Args&&... args) { l_.emplace_back(std::forward<Args>(args)...); }
|
|
|
|
template <class... Args>
|
|
|
|
void emplace_front(Args&&... args) { l_.emplace_front(std::forward<Args>(args)...); }
|
|
|
|
#endif
|
|
|
|
void pop_front() { l_.pop_front(); }
|
|
|
|
void pop_back() { l_.pop_back(); }
|
|
|
|
|
2017-04-19 09:02:49 +08:00
|
|
|
#if TEST_STD_VER >= 11
|
2014-03-04 03:20:40 +08:00
|
|
|
template <class... Args> iterator emplace(const_iterator pos, Args&&... args)
|
|
|
|
{ return l_.emplace(pos, std::forward<Args>(args)...); }
|
|
|
|
#endif
|
2016-06-02 05:35:39 +08:00
|
|
|
|
2014-03-04 03:20:40 +08:00
|
|
|
iterator insert(const_iterator pos, const value_type& x) { return l_.insert(pos, x); }
|
2017-04-19 09:02:49 +08:00
|
|
|
#if TEST_STD_VER >= 11
|
2014-03-04 03:20:40 +08:00
|
|
|
iterator insert(const_iterator pos, value_type&& x) { return l_.insert(pos, std::forward<value_type>(x)); }
|
|
|
|
#endif
|
|
|
|
iterator insert(const_iterator pos, size_type n, const value_type& x) { return l_.insert(pos, n, x); }
|
|
|
|
template <class InputIterator>
|
|
|
|
iterator insert(const_iterator pos, InputIterator first, InputIterator last)
|
|
|
|
{ return l_.insert(pos, first, last); }
|
|
|
|
|
2017-04-19 09:02:49 +08:00
|
|
|
#if TEST_STD_VER >= 11
|
2014-03-04 03:20:40 +08:00
|
|
|
iterator insert(const_iterator pos, std::initializer_list<value_type> il) { return l_.insert(pos, il); }
|
|
|
|
#endif
|
|
|
|
|
|
|
|
iterator erase(const_iterator pos) { return l_.erase(pos); }
|
|
|
|
iterator erase(const_iterator pos, const_iterator last) { return l_.erase(pos, last); }
|
|
|
|
|
2016-12-24 07:37:52 +08:00
|
|
|
void resize(size_type) { l_.resize(); }
|
|
|
|
void resize(size_type, const value_type& c) { l_.resize(c); }
|
2014-03-04 03:20:40 +08:00
|
|
|
|
2016-10-12 17:31:26 +08:00
|
|
|
void swap(nasty_list &nl)
|
|
|
|
#if TEST_STD_VER > 14
|
|
|
|
noexcept(std::is_nothrow_swappable<nested_container>::value)
|
|
|
|
#elif defined(_LIBCPP_VERSION)
|
|
|
|
TEST_NOEXCEPT_COND(std::__is_nothrow_swappable<nested_container>::value)
|
|
|
|
#endif
|
2014-03-04 03:20:40 +08:00
|
|
|
{ l_.swap(nl.l_); }
|
2016-06-02 05:35:39 +08:00
|
|
|
|
2016-10-12 17:31:26 +08:00
|
|
|
void clear() TEST_NOEXCEPT { l_.clear(); }
|
2014-03-04 03:20:40 +08:00
|
|
|
|
|
|
|
// void splice(const_iterator position, list& x);
|
|
|
|
// void splice(const_iterator position, list&& x);
|
|
|
|
// void splice(const_iterator position, list& x, const_iterator i);
|
|
|
|
// void splice(const_iterator position, list&& x, const_iterator i);
|
|
|
|
// void splice(const_iterator position, list& x, const_iterator first,
|
|
|
|
// const_iterator last);
|
|
|
|
// void splice(const_iterator position, list&& x, const_iterator first,
|
|
|
|
// const_iterator last);
|
2016-06-02 05:35:39 +08:00
|
|
|
//
|
2014-03-04 03:20:40 +08:00
|
|
|
// void remove(const value_type& value);
|
|
|
|
// template <class Pred> void remove_if(Pred pred);
|
|
|
|
// void unique();
|
|
|
|
// template <class BinaryPredicate>
|
|
|
|
// void unique(BinaryPredicate binary_pred);
|
|
|
|
// void merge(list& x);
|
|
|
|
// void merge(list&& x);
|
|
|
|
// template <class Compare>
|
|
|
|
// void merge(list& x, Compare comp);
|
|
|
|
// template <class Compare>
|
|
|
|
// void merge(list&& x, Compare comp);
|
|
|
|
// void sort();
|
|
|
|
// template <class Compare>
|
|
|
|
// void sort(Compare comp);
|
|
|
|
// void reverse() noexcept;
|
|
|
|
|
2016-03-15 07:07:58 +08:00
|
|
|
nasty_list *operator &() { assert(false); return nullptr; } // nasty
|
|
|
|
const nasty_list *operator &() const { assert(false); return nullptr; } // nasty
|
2014-03-04 03:20:40 +08:00
|
|
|
|
|
|
|
nested_container l_;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
bool operator==(const nasty_list<T>& x, const nasty_list<T>& y) { return x.l_ == y.l_; }
|
|
|
|
|
2016-03-15 07:07:58 +08:00
|
|
|
// Not really a mutex, but can play one in tests
|
|
|
|
class nasty_mutex
|
|
|
|
{
|
|
|
|
public:
|
2016-10-12 17:31:26 +08:00
|
|
|
nasty_mutex() TEST_NOEXCEPT {}
|
2016-03-15 07:07:58 +08:00
|
|
|
~nasty_mutex() {}
|
|
|
|
|
2016-04-29 08:45:46 +08:00
|
|
|
nasty_mutex *operator& () { assert(false); return nullptr; }
|
2016-03-15 07:07:58 +08:00
|
|
|
template <typename T>
|
|
|
|
void operator, (const T &) { assert(false); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
nasty_mutex(const nasty_mutex&) { assert(false); }
|
|
|
|
nasty_mutex& operator=(const nasty_mutex&) { assert(false); return *this; }
|
|
|
|
|
|
|
|
public:
|
|
|
|
void lock() {}
|
2016-10-12 17:31:26 +08:00
|
|
|
bool try_lock() TEST_NOEXCEPT { return true; }
|
|
|
|
void unlock() TEST_NOEXCEPT {}
|
2016-03-15 07:07:58 +08:00
|
|
|
|
|
|
|
// Shared ownership
|
|
|
|
void lock_shared() {}
|
|
|
|
bool try_lock_shared() { return true; }
|
|
|
|
void unlock_shared() {}
|
|
|
|
};
|
|
|
|
|
2014-03-04 03:20:40 +08:00
|
|
|
#endif
|