Files
yaml-cpp/src/ptr_stack.h
Matt Blair 24fa1b3380 Replace Boost usage with C++11 features
- Adds 'std=c++11' compiler flags
 - Replaces boost::type_traits with std::type_traits
 - Replaces boost::shared_ptr with std::shared_ptr
 - Replaces std::auto_ptr with std::unique_ptr
 - Replaces raw pointers with std::unique_ptr in ptr_vector, ptr_stack, and SettingChanges
 - Replaces boost::noncopyable with deleted copy and assignment operators
 - Replaces boost::next with std::next
 - Replaces boost::enable_if with std::enable_if
 - Replaces boost::is_convertible with std::is_convertible
 - Replaces ptrdiff_t with std::ptrdiff_t
 - Replaces boost::iterator_facade and boost::iterator_adaptor with std::iterator, borrowing the 'proxy reference' technique from boost
 - Removes Boost dependency from CMakeLists
 - Formats changed files using clang-format
2016-01-10 22:44:15 -05:00

59 lines
1.3 KiB
C++

#ifndef PTR_STACK_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define PTR_STACK_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
#include <cstddef>
#include <cstdlib>
#include <memory>
#include <vector>
#include "yaml-cpp/noncopyable.h"
// TODO: This class is no longer needed
template <typename T>
class ptr_stack : private YAML::noncopyable {
public:
ptr_stack() {}
void clear() {
m_data.clear();
}
std::size_t size() const { return m_data.size(); }
bool empty() const { return m_data.empty(); }
void push(std::unique_ptr<T>&& t) {
m_data.push_back(std::move(t));
}
std::unique_ptr<T> pop() {
std::unique_ptr<T> t(std::move(m_data.back()));
m_data.pop_back();
return t;
}
T& top() {
return *(m_data.back().get());
}
const T& top() const {
return *(m_data.back().get());
}
T& top(std::ptrdiff_t diff) {
return *((m_data.end() - 1 + diff)->get());
}
const T& top(std::ptrdiff_t diff) const {
return *((m_data.end() - 1 + diff)->get());
}
private:
std::vector<std::unique_ptr<T>> m_data;
};
#endif // PTR_STACK_H_62B23520_7C8E_11DE_8A39_0800200C9A66