2011-10-25 09:16:27 +00:00
|
|
|
#ifndef SPROUT_PIT_HPP
|
|
|
|
#define SPROUT_PIT_HPP
|
2011-10-06 12:45:01 +00:00
|
|
|
|
|
|
|
#include <cstddef>
|
|
|
|
#include <utility>
|
|
|
|
#include <stdexcept>
|
|
|
|
#include <sprout/config.hpp>
|
2012-03-31 07:24:13 +00:00
|
|
|
#include <sprout/container/traits.hpp>
|
|
|
|
#include <sprout/container/functions.hpp>
|
2011-10-06 12:45:01 +00:00
|
|
|
#include <sprout/iterator.hpp>
|
|
|
|
#include <sprout/iterator/value_iterator.hpp>
|
2011-10-30 08:40:35 +00:00
|
|
|
#include <sprout/utility/forward.hpp>
|
2012-05-23 10:33:06 +00:00
|
|
|
#include <sprout/array.hpp>
|
2011-10-06 12:45:01 +00:00
|
|
|
|
|
|
|
namespace sprout {
|
|
|
|
//
|
2011-10-25 09:16:27 +00:00
|
|
|
// pit
|
2011-10-06 12:45:01 +00:00
|
|
|
//
|
|
|
|
template<typename Container>
|
2011-10-25 09:16:27 +00:00
|
|
|
class pit {
|
2011-10-06 12:45:01 +00:00
|
|
|
public:
|
|
|
|
typedef Container container_type;
|
2012-03-31 07:24:13 +00:00
|
|
|
typedef typename sprout::container_traits<container_type>::value_type value_type;
|
|
|
|
typedef typename sprout::container_traits<container_type>::reference reference;
|
|
|
|
typedef typename sprout::container_traits<container_type>::const_reference const_reference;
|
2011-10-06 12:45:01 +00:00
|
|
|
typedef typename sprout::value_iterator<reference> iterator;
|
|
|
|
typedef typename sprout::value_iterator<const_reference> const_iterator;
|
2012-03-31 07:24:13 +00:00
|
|
|
typedef typename sprout::container_traits<container_type>::size_type size_type;
|
|
|
|
typedef typename sprout::container_traits<container_type>::difference_type difference_type;
|
|
|
|
typedef typename sprout::container_traits<container_type>::pointer pointer;
|
|
|
|
typedef typename sprout::container_traits<container_type>::const_pointer const_pointer;
|
2011-10-06 12:45:01 +00:00
|
|
|
typedef typename sprout::reverse_iterator<iterator> reverse_iterator;
|
|
|
|
typedef typename sprout::reverse_iterator<const_iterator> const_reverse_iterator;
|
|
|
|
public:
|
2012-03-31 07:24:13 +00:00
|
|
|
SPROUT_STATIC_CONSTEXPR size_type static_size = sprout::container_traits<container_type>::static_size;
|
2011-10-06 12:45:01 +00:00
|
|
|
public:
|
|
|
|
value_type elem;
|
|
|
|
public:
|
2011-10-25 09:16:27 +00:00
|
|
|
pit() = default;
|
|
|
|
void swap(pit& other) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(std::swap(std::declval<value_type&>(), std::declval<value_type&>()))) {
|
2011-10-08 08:44:50 +00:00
|
|
|
using std::swap;
|
|
|
|
swap(elem, other.elem);
|
2011-10-06 12:45:01 +00:00
|
|
|
}
|
2011-10-08 08:44:50 +00:00
|
|
|
// iterators:
|
2011-10-06 12:45:01 +00:00
|
|
|
iterator begin() {
|
|
|
|
return iterator(elem, static_size);
|
|
|
|
}
|
|
|
|
SPROUT_CONSTEXPR const_iterator begin() const {
|
|
|
|
return const_iterator(elem, static_size);
|
|
|
|
}
|
|
|
|
iterator end() SPROUT_NOEXCEPT {
|
|
|
|
return iterator();
|
|
|
|
}
|
|
|
|
SPROUT_CONSTEXPR const_iterator end() const SPROUT_NOEXCEPT {
|
|
|
|
return const_iterator();
|
|
|
|
}
|
|
|
|
reverse_iterator rbegin() SPROUT_NOEXCEPT {
|
|
|
|
return reverse_iterator(end());
|
|
|
|
}
|
|
|
|
SPROUT_CONSTEXPR const_reverse_iterator rbegin() const SPROUT_NOEXCEPT {
|
|
|
|
return const_reverse_iterator(end());
|
|
|
|
}
|
|
|
|
reverse_iterator rend() SPROUT_NOEXCEPT {
|
|
|
|
return reverse_iterator(begin());
|
|
|
|
}
|
|
|
|
SPROUT_CONSTEXPR const_reverse_iterator rend() const SPROUT_NOEXCEPT {
|
|
|
|
return const_reverse_iterator(begin());
|
|
|
|
}
|
2011-10-08 08:44:50 +00:00
|
|
|
SPROUT_CONSTEXPR const_iterator cbegin() const SPROUT_NOEXCEPT {
|
|
|
|
return const_iterator(elem, static_size);
|
|
|
|
}
|
|
|
|
SPROUT_CONSTEXPR const_iterator cend() const SPROUT_NOEXCEPT {
|
|
|
|
return const_iterator();
|
|
|
|
}
|
|
|
|
SPROUT_CONSTEXPR const_reverse_iterator crbegin() const SPROUT_NOEXCEPT {
|
|
|
|
return const_reverse_iterator(end());
|
|
|
|
}
|
2011-10-06 12:45:01 +00:00
|
|
|
SPROUT_CONSTEXPR const_reverse_iterator crend() const SPROUT_NOEXCEPT {
|
|
|
|
return const_reverse_iterator(begin());
|
|
|
|
}
|
2011-10-08 08:44:50 +00:00
|
|
|
// capacity:
|
|
|
|
SPROUT_CONSTEXPR size_type size() const SPROUT_NOEXCEPT {
|
|
|
|
return static_size;
|
|
|
|
}
|
|
|
|
SPROUT_CONSTEXPR size_type max_size() const SPROUT_NOEXCEPT {
|
|
|
|
return size();
|
|
|
|
}
|
|
|
|
SPROUT_CONSTEXPR bool empty() const SPROUT_NOEXCEPT {
|
|
|
|
return static_size == 0;
|
|
|
|
}
|
|
|
|
// element access:
|
2011-10-06 12:45:01 +00:00
|
|
|
reference operator[](size_type i) {
|
|
|
|
return elem;
|
|
|
|
}
|
|
|
|
SPROUT_CONSTEXPR const_reference operator[](size_type i) const {
|
|
|
|
return elem;
|
|
|
|
}
|
|
|
|
reference at(size_type i) {
|
2011-10-25 13:04:54 +00:00
|
|
|
return i < size()
|
|
|
|
? elem
|
|
|
|
: (throw std::out_of_range("pit<>: index out of range"), elem)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
SPROUT_CONSTEXPR const_reference at(size_type i) const {
|
|
|
|
return i < size()
|
|
|
|
? elem
|
|
|
|
: (throw std::out_of_range("pit<>: index out of range"), elem)
|
|
|
|
;
|
2011-10-06 12:45:01 +00:00
|
|
|
}
|
|
|
|
reference front() {
|
|
|
|
return elem;
|
|
|
|
}
|
|
|
|
SPROUT_CONSTEXPR const_reference front() const {
|
|
|
|
return elem;
|
|
|
|
}
|
|
|
|
reference back() {
|
|
|
|
return elem;
|
|
|
|
}
|
|
|
|
SPROUT_CONSTEXPR const_reference back() const {
|
|
|
|
return elem;
|
|
|
|
}
|
2011-10-08 08:44:50 +00:00
|
|
|
// others:
|
|
|
|
void rangecheck(size_type i) const {
|
|
|
|
if (i >= size()) {
|
2011-10-25 09:16:27 +00:00
|
|
|
throw std::out_of_range("pit<>: index out of range");
|
2011-10-08 08:44:50 +00:00
|
|
|
}
|
2011-10-06 12:45:01 +00:00
|
|
|
}
|
|
|
|
};
|
2011-10-10 12:06:34 +00:00
|
|
|
template<typename Container>
|
2011-10-25 09:16:27 +00:00
|
|
|
SPROUT_CONSTEXPR typename sprout::pit<Container>::size_type sprout::pit<Container>::static_size;
|
2011-10-08 08:44:50 +00:00
|
|
|
|
|
|
|
//
|
2011-10-10 01:20:21 +00:00
|
|
|
// operator==
|
2011-10-08 08:44:50 +00:00
|
|
|
// operator!=
|
|
|
|
// operator<
|
|
|
|
// operator>
|
|
|
|
// operator<=
|
|
|
|
// operator>=
|
|
|
|
//
|
2011-10-06 12:45:01 +00:00
|
|
|
template<typename Container>
|
2012-04-04 13:23:41 +00:00
|
|
|
inline SPROUT_CONSTEXPR bool operator==(sprout::pit<Container> const& lhs, sprout::pit<Container> const& rhs) {
|
2011-10-06 12:45:01 +00:00
|
|
|
return lhs.front() == rhs.front();
|
|
|
|
}
|
|
|
|
template<typename Container>
|
2012-04-04 13:23:41 +00:00
|
|
|
inline SPROUT_CONSTEXPR bool operator!=(sprout::pit<Container> const& lhs, sprout::pit<Container> const& rhs) {
|
2011-10-06 12:45:01 +00:00
|
|
|
return !(lhs == rhs);
|
|
|
|
}
|
|
|
|
template<typename Container>
|
2012-04-04 13:23:41 +00:00
|
|
|
inline SPROUT_CONSTEXPR bool operator<(sprout::pit<Container> const& lhs, sprout::pit<Container> const& rhs) {
|
2011-10-06 12:45:01 +00:00
|
|
|
return lhs.front() < rhs.front();
|
|
|
|
}
|
|
|
|
template<typename Container>
|
2012-04-04 13:23:41 +00:00
|
|
|
inline SPROUT_CONSTEXPR bool operator>(sprout::pit<Container> const& lhs, sprout::pit<Container> const& rhs) {
|
2011-10-06 12:45:01 +00:00
|
|
|
return rhs < lhs;
|
|
|
|
}
|
|
|
|
template<typename Container>
|
2012-04-04 13:23:41 +00:00
|
|
|
inline SPROUT_CONSTEXPR bool operator<=(sprout::pit<Container> const& lhs, sprout::pit<Container> const& rhs) {
|
2011-10-06 12:45:01 +00:00
|
|
|
return !(rhs < lhs);
|
|
|
|
}
|
|
|
|
template<typename Container>
|
2012-04-04 13:23:41 +00:00
|
|
|
inline SPROUT_CONSTEXPR bool operator>=(sprout::pit<Container> const& lhs, sprout::pit<Container> const& rhs) {
|
2011-10-06 12:45:01 +00:00
|
|
|
return !(lhs < rhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// swap
|
|
|
|
//
|
|
|
|
template<typename Container>
|
2011-10-25 09:16:27 +00:00
|
|
|
inline void swap(sprout::pit<Container>& lhs, sprout::pit<Container>& rhs) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) {
|
2011-10-06 12:45:01 +00:00
|
|
|
lhs.swap(rhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2012-03-31 07:24:13 +00:00
|
|
|
// container_construct_traits
|
2011-10-06 12:45:01 +00:00
|
|
|
//
|
|
|
|
template<typename Container>
|
2012-03-31 07:24:13 +00:00
|
|
|
struct container_construct_traits<sprout::pit<Container> > {
|
2011-10-06 12:45:01 +00:00
|
|
|
public:
|
2012-03-31 07:24:13 +00:00
|
|
|
typedef typename sprout::container_construct_traits<Container>::copied_type copied_type;
|
2011-10-06 12:45:01 +00:00
|
|
|
public:
|
2012-03-31 07:24:13 +00:00
|
|
|
template<typename Cont>
|
|
|
|
static SPROUT_CONSTEXPR copied_type deep_copy(Cont&& cont) {
|
|
|
|
return copied_type();
|
2011-10-06 12:45:01 +00:00
|
|
|
}
|
|
|
|
template<typename... Args>
|
2012-03-31 07:24:13 +00:00
|
|
|
static SPROUT_CONSTEXPR copied_type make(Args&&... args) {
|
|
|
|
return sprout::make<copied_type>(sprout::forward<Args>(args)...);
|
|
|
|
}
|
|
|
|
template<typename Cont, typename... Args>
|
|
|
|
static SPROUT_CONSTEXPR copied_type remake(
|
|
|
|
Cont&& cont,
|
|
|
|
typename sprout::container_traits<sprout::pit<Container> >::difference_type size,
|
|
|
|
Args&&... args
|
|
|
|
)
|
|
|
|
{
|
2012-04-30 08:30:47 +00:00
|
|
|
return sprout::remake<copied_type>(sprout::forward<Cont>(cont), size, sprout::forward<Args>(args)...);
|
2011-10-06 12:45:01 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//
|
2012-03-31 07:24:13 +00:00
|
|
|
// container_transform_traits
|
2011-10-06 12:45:01 +00:00
|
|
|
//
|
|
|
|
template<typename Container>
|
2012-03-31 07:24:13 +00:00
|
|
|
struct container_transform_traits<sprout::pit<Container> > {
|
2011-10-06 12:45:01 +00:00
|
|
|
public:
|
2012-03-31 07:24:13 +00:00
|
|
|
template<typename sprout::container_traits<sprout::pit<Container> >::size_type Size>
|
|
|
|
struct rebind_size {
|
|
|
|
public:
|
|
|
|
typedef sprout::pit<
|
|
|
|
typename sprout::container_transform_traits<Container>::template rebind_size<Size>::type
|
|
|
|
> type;
|
|
|
|
};
|
2011-10-06 12:45:01 +00:00
|
|
|
};
|
2012-05-23 10:33:06 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// blank
|
|
|
|
//
|
|
|
|
struct blank {};
|
|
|
|
|
|
|
|
//
|
|
|
|
// blank_pit
|
|
|
|
//
|
|
|
|
template<std::size_t N>
|
|
|
|
inline SPROUT_CONSTEXPR sprout::pit<sprout::array<sprout::blank, N> >
|
|
|
|
blank_pit() {
|
|
|
|
return sprout::pit<sprout::array<sprout::blank, N> >();
|
|
|
|
}
|
2011-10-06 12:45:01 +00:00
|
|
|
} // namespace sprout
|
|
|
|
|
|
|
|
namespace std {
|
|
|
|
//
|
|
|
|
// tuple_size
|
|
|
|
//
|
|
|
|
template<typename Container>
|
2012-05-19 09:46:38 +00:00
|
|
|
struct tuple_size<sprout::pit<Container> >
|
2012-03-31 07:24:13 +00:00
|
|
|
: public std::tuple_size<Container>
|
|
|
|
{};
|
2011-10-06 12:45:01 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// tuple_element
|
|
|
|
//
|
|
|
|
template<std::size_t I, typename Container>
|
2012-05-19 09:46:38 +00:00
|
|
|
struct tuple_element<I, sprout::pit<Container> >
|
2012-03-31 07:24:13 +00:00
|
|
|
: public std::tuple_element<I, Container>
|
|
|
|
{};
|
2011-10-06 12:45:01 +00:00
|
|
|
} // namespace std
|
|
|
|
|
2011-10-25 09:16:27 +00:00
|
|
|
#endif // #ifndef SPROUT_PIT_HPP
|