266 lines · c
1#ifndef STRUCTURES_H2#define STRUCTURES_H3 4namespace std {5template <class T> constexpr auto begin(T& t) -> decltype(t.begin());6template <class T> constexpr auto begin(const T& t) -> decltype(t.begin());7template <class T> constexpr auto end(T& t) -> decltype(t.end());8template <class T> constexpr auto end(const T& t) -> decltype(t.end());9template <class T> constexpr auto size(const T& t) -> decltype(t.size());10} // namespace std11 12extern "C" {13extern int printf(const char *restrict, ...);14}15 16struct Val {int X; void g(); };17 18struct MutableVal {19 void constFun(int) const;20 void nonConstFun(int, int);21 void constFun(MutableVal &) const;22 void constParamFun(const MutableVal &) const;23 void nonConstParamFun(const MutableVal &);24 int X;25};26 27struct NonTriviallyCopyable {28 NonTriviallyCopyable() = default;29 // Define this constructor to make this class non-trivially copyable.30 NonTriviallyCopyable(const NonTriviallyCopyable& Ntc);31 int X;32};33 34struct TriviallyCopyableButBig {35 int X;36 char Array[16];37};38 39namespace ADT {40 41struct S {42 typedef MutableVal *iterator;43 typedef const MutableVal *const_iterator;44 const_iterator begin() const;45 const_iterator end() const;46 const_iterator cbegin() const;47 const_iterator cend() const;48 iterator begin();49 iterator end();50};51 52S::const_iterator begin(const S&);53S::const_iterator end(const S&);54S::const_iterator cbegin(const S&);55S::const_iterator cend(const S&);56S::iterator begin(S&);57S::iterator end(S&);58unsigned size(const S&);59 60struct T {61 typedef int value_type;62 struct iterator {63 value_type &operator*();64 const value_type &operator*() const;65 iterator& operator ++();66 bool operator!=(const iterator &other);67 void insert(value_type);68 value_type X;69 };70 iterator begin();71 iterator end();72};73T::iterator begin(T&);74T::iterator end(T&);75 76} // namespace ADT77 78using ADT::S;79using ADT::T;80 81struct Q {82 typedef int value_type;83 struct const_iterator {84 value_type &operator*();85 const value_type &operator*() const;86 const_iterator &operator++();87 bool operator!=(const const_iterator &other);88 void insert(value_type);89 value_type X;90 };91 struct iterator {92 operator const_iterator() const;93 };94 iterator begin();95 iterator end();96};97 98struct U {99 struct iterator {100 Val& operator*();101 const Val& operator*()const;102 iterator& operator ++();103 bool operator!=(const iterator &other);104 Val *operator->();105 };106 iterator begin();107 iterator end();108 int X;109};110 111struct X {112 S Ss;113 T Tt;114 U Uu;115 S getS();116};117 118namespace ADT {119 120template<typename ElemType>121class dependent {122 public:123 dependent<ElemType>();124 struct iterator_base {125 const ElemType& operator*()const;126 iterator_base& operator ++();127 bool operator!=(const iterator_base &other) const;128 const ElemType *operator->() const;129 };130 131 struct iterator : iterator_base {132 ElemType& operator*();133 iterator& operator ++();134 ElemType *operator->();135 };136 137 typedef iterator_base const_iterator;138 const_iterator begin() const;139 const_iterator end() const;140 iterator begin();141 iterator end();142 unsigned size() const;143 ElemType & operator[](unsigned);144 const ElemType & operator[](unsigned) const;145 ElemType & at(unsigned);146 ElemType & at(unsigned, unsigned);147 const ElemType & at(unsigned) const;148 149 // Intentionally evil.150 dependent<ElemType> operator*();151 152 void foo();153 void constFoo() const;154};155 156template<typename ElemType>157unsigned size(const dependent<ElemType>&);158template<typename ElemType>159unsigned length(const dependent<ElemType>&);160 161template<typename ElemType>162class dependent_derived : public dependent<ElemType> {163};164 165} // namespace ADT166 167using ADT::dependent;168using ADT::dependent_derived;169 170template<typename First, typename Second>171class doublyDependent{172 public:173 struct Value {174 First first;175 Second second;176 };177 178 struct iterator_base {179 const Value& operator*()const;180 iterator_base& operator ++();181 bool operator!=(const iterator_base &other) const;182 const Value *operator->() const;183 };184 185 struct iterator : iterator_base {186 Value& operator*();187 Value& operator ++();188 Value *operator->();189 };190 191 typedef iterator_base const_iterator;192 const_iterator begin() const;193 const_iterator end() const;194 iterator begin();195 iterator end();196};197 198template<typename Contained>199class transparent {200 public:201 Contained *at();202 Contained *operator->();203 Contained operator*();204};205 206template<typename IteratorType>207struct Nested {208 typedef IteratorType* iterator;209 typedef const IteratorType* const_iterator;210 IteratorType *operator->();211 IteratorType operator*();212 iterator begin();213 iterator end();214 const_iterator begin() const;215 const_iterator end() const;216};217 218// Like llvm::SmallPtrSet, the iterator has a dereference operator that returns219// by value instead of by reference.220template <typename T>221struct PtrSet {222 struct iterator {223 bool operator!=(const iterator &other) const;224 const T operator*();225 iterator &operator++();226 };227 iterator begin() const;228 iterator end() const;229};230 231template <typename T>232struct TypedefDerefContainer {233 struct iterator {234 typedef T &deref_type;235 bool operator!=(const iterator &other) const;236 deref_type operator*();237 iterator &operator++();238 };239 iterator begin() const;240 iterator end() const;241};242 243template <typename T>244struct RValueDerefContainer {245 struct iterator {246 typedef T &&deref_type;247 bool operator!=(const iterator &other) const;248 deref_type operator*();249 iterator &operator++();250 };251 iterator begin() const;252 iterator end() const;253};254 255namespace Macros {256 257struct MacroStruct {258 int Arr[10];259};260static MacroStruct *MacroSt;261#define CONT MacroSt->262 263} // namespace Macros264 265#endif // STRUCTURES_H266