stack.hpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //---------------------------------------------------------------------------//
  2. // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
  3. //
  4. // Distributed under the Boost Software License, Version 1.0
  5. // See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt
  7. //
  8. // See http://boostorg.github.com/compute for more information.
  9. //---------------------------------------------------------------------------//
  10. #ifndef BOOST_COMPUTE_CONTAINER_STACK_HPP
  11. #define BOOST_COMPUTE_CONTAINER_STACK_HPP
  12. #include <boost/compute/container/vector.hpp>
  13. namespace boost {
  14. namespace compute {
  15. template<class T>
  16. class stack
  17. {
  18. public:
  19. typedef vector<T> container_type;
  20. typedef typename container_type::size_type size_type;
  21. typedef typename container_type::value_type value_type;
  22. stack()
  23. {
  24. }
  25. stack(const stack<T> &other)
  26. : m_vector(other.m_vector)
  27. {
  28. }
  29. stack<T>& operator=(const stack<T> &other)
  30. {
  31. if(this != &other){
  32. m_vector = other.m_vector;
  33. }
  34. return *this;
  35. }
  36. ~stack()
  37. {
  38. }
  39. bool empty() const
  40. {
  41. return m_vector.empty();
  42. }
  43. size_type size() const
  44. {
  45. return m_vector.size();
  46. }
  47. value_type top() const
  48. {
  49. return m_vector.back();
  50. }
  51. void push(const T &value)
  52. {
  53. m_vector.push_back(value);
  54. }
  55. void pop()
  56. {
  57. m_vector.pop_back();
  58. }
  59. private:
  60. container_type m_vector;
  61. };
  62. } // end compute namespace
  63. } // end boost namespace
  64. #endif // BOOST_COMPUTE_CONTAINER_STACK_HPP