From 3dba5d5f9ff6f04593a5822a4548e787392f4db7 Mon Sep 17 00:00:00 2001 From: manuel Date: Sat, 6 Jun 2009 13:39:22 +0200 Subject: using some stl-methods removing todos --- ue5/array.hpp | 20 ++++++-------------- ue5/mean_mark.hpp | 2 ++ ue5/shared_ptr.hpp | 55 +++++------------------------------------------------- 3 files changed, 13 insertions(+), 64 deletions(-) diff --git a/ue5/array.hpp b/ue5/array.hpp index e9adc55..0acd37d 100644 --- a/ue5/array.hpp +++ b/ue5/array.hpp @@ -1,12 +1,13 @@ #ifndef ARRAY_H #define ARRAY_H +#include +#include +#include + #undef SOLVED_2 #define SOLVED_2 -#include // for std::move -#include // for std::out_of_range - namespace Ti { template @@ -22,21 +23,12 @@ namespace Ti void fill(const T& u) { - /* std::fill_n(begin(), size(), u); */ - for(size_type i = 0; i < N; ++i) - m_data[i] = u; + std::fill_n(begin(), N, u); } - /* range check not necessary. N must be the same in other */ void swap(array & other) { - /* std::swap_ranges(begin(), end(), other.begin()); */ - for(size_type i = 0; i < N; ++i) - { - T x(m_data[i]); - m_data[i] = other.m_data[i]; - other.m_data[i] = x; - } + std::swap_ranges(begin(), end(), other.begin()); } iterator begin() diff --git a/ue5/mean_mark.hpp b/ue5/mean_mark.hpp index ba5a230..a28b219 100644 --- a/ue5/mean_mark.hpp +++ b/ue5/mean_mark.hpp @@ -1,6 +1,8 @@ #ifndef MEAN_MARK_H #define MEAN_MARK_H +#include + #undef SOLVED_3 #define SOLVED_3 diff --git a/ue5/shared_ptr.hpp b/ue5/shared_ptr.hpp index 00a4dc7..e423904 100644 --- a/ue5/shared_ptr.hpp +++ b/ue5/shared_ptr.hpp @@ -1,19 +1,13 @@ #ifndef SHARED_PTR_H #define SHARED_PTR_H -/* TODO includes */ +#include #undef SOLVED_1 #define SOLVED_1 -/* TODO: remove */ -#define SHPDEBUG if (0) -#include - namespace Ti { - /* TODO helpers */ - template class shared_ptr { @@ -24,20 +18,16 @@ namespace Ti public: shared_ptr() : m_ptr(NULL), m_count(NULL) - { - SHPDEBUG std::cerr << this << ": shared_ptr()" << std::endl; - } + {} T* get() const { - SHPDEBUG std::cerr << this << ": get()" << std::endl; return m_ptr; } shared_ptr(const shared_ptr& other) : m_ptr(other.m_ptr), m_count(other.m_count) { - SHPDEBUG std::cerr << this << ": shared_ptr(shared_ptr& other)" << std::endl; add_ref(); } @@ -45,7 +35,6 @@ namespace Ti shared_ptr(const shared_ptr& other) : m_ptr(other.m_ptr), m_count(other.m_count) { - SHPDEBUG std::cerr << this << ": shared_ptr(shared_ptr& other)" << std::endl; add_ref(); } @@ -54,59 +43,39 @@ namespace Ti shared_ptr(const shared_ptr& other, T* ptr) : m_ptr(ptr), m_count(other.m_count) { - SHPDEBUG std::cerr << this << ": shared_ptr(shared_ptr& other, O* ptr)" << std::endl; add_ref(); } template explicit shared_ptr(O* p) : m_ptr(p), m_count(new unsigned long(1)) - { - SHPDEBUG std::cerr << this << ": shared_ptr(O* p)" << std::endl; - } + {} shared_ptr& operator=(const shared_ptr& other) { - SHPDEBUG std::cerr << this << ": operator=(shared_ptr& other)" << std::endl; -#if 1 - shared_ptr(other).swap(*this); - return *this; -#else if (*this == other) return *this; - release(); - m_ptr = other.m_ptr; m_count = other.m_count; add_ref(); return *this; -#endif } template shared_ptr& operator=(const shared_ptr& other) { - SHPDEBUG std::cerr << this << ": operator=(shared_ptr& other)" << std::endl; -#if 0 - shared_ptr(other).swap(*this); - return *this; -#else if (*this == other) return *this; - release(); - m_ptr = other.m_ptr; m_count = other.m_count; add_ref(); return *this; -#endif } ~shared_ptr() { - SHPDEBUG std::cerr << this << ": ~shared_ptr()" << std::endl; release(); } @@ -122,15 +91,8 @@ namespace Ti void swap(shared_ptr& other) { - /* std::swap(m_ptr, other.m_ptr); */ - T* ptr(m_ptr); - m_ptr = other.m_ptr; - other.m_ptr = ptr; - - /* std::swap(m_count, other.m_count); */ - unsigned long* count(m_count); - m_count = other.m_count; - other.m_count = count; + std::swap(m_ptr, other.m_ptr); + std::swap(m_count, other.m_count); } inline void reset() @@ -188,7 +150,6 @@ namespace Ti template shared_ptr make_shared(Args ... args) { - SHPDEBUG std::cerr << "make_shared(args...)" << std::endl; return shared_ptr(new T(args ...)); } @@ -231,16 +192,12 @@ namespace Ti template shared_ptr shared_dynamic_cast(const shared_ptr& from) { - SHPDEBUG std::cerr << "shared_dynamic_cast(...)" << std::endl; T* castptr = dynamic_cast(from.get()); if (castptr != NULL) - { return shared_ptr(from, castptr); - } else return shared_ptr(); } - } // end namespace ti namespace std @@ -251,8 +208,6 @@ namespace std { t1.swap(t2); } - - /* TODO */ } #endif -- cgit v1.2.3