Skip to content

Commit

Permalink
Merge pull request #1 from jwakely/master
Browse files Browse the repository at this point in the history
Adding noexcept and changing typedefs
  • Loading branch information
WG21-SG14 committed Jun 10, 2015
2 parents da6f19f + 0b9bdcd commit 09e1b33
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions SG14/rolling_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,57 @@

namespace sg14
{
template<typename T, const std::size_t capacity>
template<typename T, std::size_t capacity>
class rolling_queue
{
public:
typedef rolling_queue<T, capacity> Type;
typedef std::array<T, capacity> Container;
typedef typename Container::value_type value_type;
typedef typename Container::size_type size_type;
typedef typename Container::reference reference;
typedef typename Container::const_reference const_reference;
typedef typename Container::iterator iterator;
typedef typename Container::const_iterator const_iterator;
typedef typename Container::reverse_iterator reverse_iterator;
typedef typename Container::const_reverse_iterator const_reverse_iterator;

rolling_queue()
typedef std::array<T, capacity> container_type;
typedef typename container_type::value_type value_type;
typedef typename container_type::size_type size_type;
typedef typename container_type::reference reference;
typedef typename container_type::const_reference const_reference;
typedef typename container_type::iterator iterator;
typedef typename container_type::const_iterator const_iterator;
typedef typename container_type::reverse_iterator reverse_iterator;
typedef typename container_type::const_reverse_iterator const_reverse_iterator;

rolling_queue() noexcept(std::is_nothrow_default_constructible<T>::value)
: c()
, count(0)
, next_element(std::begin(c))
, last_element(next_element)
{
}

rolling_queue(const Type& rhs)
rolling_queue(const rolling_queue& rhs) noexcept(std::is_nothrow_copy_constructible<T>::value)
: c(rhs.c)
, count(rhs.count)
, next_element(std::begin(c) + (rhs.next_element - std::begin(rhs.c)))
, last_element(std::begin(c) + (rhs.last_element - std::begin(rhs.c)))
{
}

rolling_queue(Type&& rhs)
rolling_queue(rolling_queue&& rhs) noexcept(std::is_nothrow_move_constructible<T>::value)
: c(std::move(rhs.c))
, count(std::move(rhs.count))
, next_element(std::begin(c) + (rhs.next_element - std::begin(rhs.c)))
, last_element(std::begin(c) + (rhs.last_element - std::begin(rhs.c)))
{
}

Type& operator=(const Type& rhs)
rolling_queue& operator=(const rolling_queue& rhs) noexcept(std::is_nothrow_copy_assignable<T>::value)
{
c = rhs.c;
return (*this);
}

Type& operator=(Type&& rhs)
rolling_queue& operator=(rolling_queue&& rhs) noexcept(std::is_nothrow_move_assignable<T>::value)
{
c = std::move(rhs.c);
return (*this);
}

bool push(const value_type& from_value)
bool push(const value_type& from_value) noexcept(std::is_nothrow_copy_assignable<T>::value)
{
if (count == capacity)
{
Expand All @@ -64,7 +63,7 @@ namespace sg14
return true;
}

bool push(value_type&& from_value)
bool push(value_type&& from_value) noexcept(std::is_nothrow_move_assignable<T>::value)
{
if (count == capacity)
{
Expand All @@ -76,7 +75,8 @@ namespace sg14
}

template<class... FromType>
bool emplace(FromType&&... from_value)
bool emplace(FromType&&... from_value) noexcept(std::is_nothrow_constructible<T, FromType...>::value
&& std::is_nothrow_move_assignable<T>::value)
{
if (count == capacity)
{
Expand All @@ -93,39 +93,39 @@ namespace sg14
increase_front();
}

bool empty() const
bool empty() const noexcept
{
return (next_element == last_element);
}

size_type size() const
size_type size() const noexcept
{
return count;
}

reference front()
reference front() noexcept
{
return (*last_element);
}

const_reference front() const
const_reference front() const noexcept
{
return (*last_element);
}

reference back()
reference back() noexcept
{
auto it = decrease(next_element);
return (*it);
}

const_reference back() const
const_reference back() const noexcept
{
auto it = decrease(next_element);
return (*it);
}

void swap(Type& rhs)
void swap(rolling_queue& rhs) noexcept
{
auto lhs_next = next_element - c.begin();
auto lhs_last = last_element - c.begin();
Expand All @@ -140,7 +140,7 @@ namespace sg14
}

private:
Container c;
container_type c;
size_t count;
iterator next_element;
iterator last_element;
Expand Down

0 comments on commit 09e1b33

Please sign in to comment.