#ifndef ARRAY_H #define ARRAY_H #undef SOLVED_2 #define SOLVED_2 /* TODO: * Angabe: Im Gegensatz zu den Beispielen bis jetzt ist die Verwendung * der STL und Boostuntersagt! */ #include // for std::move #include // for std::out_of_range #include // for std::fill_n + std::swap_ranges namespace Ti { template struct array { typedef T& reference; typedef const T& const_reference; typedef T* iterator; typedef const T* const_iterator; typedef size_t size_type; static_assert(N != 0, "array not allowed"); void fill (const T& u) { std::fill_n(begin(), size(), u); } void swap (array & other) { std::swap_ranges(begin(), end(), other.begin()); } iterator begin() { return m_data; } const_iterator begin() const { return m_data; } iterator end() { return m_data + size(); } const_iterator end() const { return m_data + size(); } size_type size() const { return N; } size_type max_size() const { return N; } bool empty() const { return false; /* size() == 0 */ } reference operator[] (size_type n) { return m_data[n]; } const_reference operator[] (size_type n) const { return m_data[n]; } reference at(size_type n) { if (n >= size()) throw std::out_of_range("array::at"); return m_data[n]; } const_reference at (size_type n) const { if (n >= size()) throw std::out_of_range("array::at"); return m_data[n]; } T* data() { return m_data; } private: T m_data[N]; }; /* TODO: was macht std::move() genau?! :) */ template array&& make_array() { return std::move(array()); } } // namespace #endif /* vim: set et sw=2 ts=2: */