#ifndef PMEMOBJ_PEXT_HPP
#define PMEMOBJ_PEXT_HPP
#include "libpmemobj++/p.hpp"
#include <iostream>
#include <limits>
namespace pmem
{
namespace obj
{
template <typename T>
std::ostream &
operator<<(std::ostream &os, const p<T> &pp)
{
return os << pp.get_ro();
}
template <typename T>
std::istream &
operator>>(std::istream &is, p<T> &pp)
{
is >> pp.get_rw();
return is;
}
template <typename T>
p<T> &operator++(p<T> &pp)
{
++(pp.get_rw());
return pp;
}
template <typename T>
p<T> &operator--(p<T> &pp)
{
--(pp.get_rw());
return pp;
}
template <typename T>
p<T> operator++(p<T> &pp, int)
{
p<T> temp = pp;
++pp;
return temp;
}
template <typename T>
p<T> operator--(p<T> &pp, int)
{
p<T> temp = pp;
--pp;
return temp;
}
template <typename T, typename Y>
p<T> &
operator+=(p<T> &lhs, const p<Y> &rhs)
{
lhs.get_rw() += rhs.get_ro();
return lhs;
}
template <typename T, typename Y>
p<T> &
operator+=(p<T> &lhs, const Y &rhs)
{
lhs.get_rw() += rhs;
return lhs;
}
template <typename T, typename Y>
p<T> &
operator-=(p<T> &lhs, const p<Y> &rhs)
{
lhs.get_rw() -= rhs.get_ro();
return lhs;
}
template <typename T, typename Y>
p<T> &
operator-=(p<T> &lhs, const Y &rhs)
{
lhs.get_rw() -= rhs;
return lhs;
}
template <typename T, typename Y>
p<T> &
operator*=(p<T> &lhs, const p<Y> &rhs)
{
lhs.get_rw() *= rhs.get_ro();
return lhs;
}
template <typename T, typename Y>
p<T> &
operator*=(p<T> &lhs, const Y &rhs)
{
lhs.get_rw() *= rhs;
return lhs;
}
template <typename T, typename Y>
p<T> &
operator/=(p<T> &lhs, const p<Y> &rhs)
{
lhs.get_rw() /= rhs.get_ro();
return lhs;
}
template <typename T, typename Y>
p<T> &
operator/=(p<T> &lhs, const Y &rhs)
{
lhs.get_rw() /= rhs;
return lhs;
}
template <typename T, typename Y>
p<T> &
operator%=(p<T> &lhs, const p<Y> &rhs)
{
lhs.get_rw() %= rhs.get_ro();
return lhs;
}
template <typename T, typename Y>
p<T> &
operator%=(p<T> &lhs, const Y &rhs)
{
lhs.get_rw() %= rhs;
return lhs;
}
template <typename T, typename Y>
p<T> &
operator&=(p<T> &lhs, const p<Y> &rhs)
{
lhs.get_rw() &= rhs.get_ro();
return lhs;
}
template <typename T, typename Y>
p<T> &
operator&=(p<T> &lhs, const Y &rhs)
{
lhs.get_rw() &= rhs;
return lhs;
}
template <typename T, typename Y>
p<T> &
operator|=(p<T> &lhs, const p<Y> &rhs)
{
lhs.get_rw() |= rhs.get_ro();
return lhs;
}
template <typename T, typename Y>
p<T> &
operator|=(p<T> &lhs, const Y &rhs)
{
lhs.get_rw() |= rhs;
return lhs;
}
template <typename T, typename Y>
p<T> &
operator^=(p<T> &lhs, const p<Y> &rhs)
{
lhs.get_rw() ^= rhs.get_ro();
return lhs;
}
template <typename T, typename Y>
p<T> &
operator^=(p<T> &lhs, const Y &rhs)
{
lhs.get_rw() ^= rhs;
return lhs;
}
template <typename T, typename Y>
p<T> &
operator<<=(p<T> &lhs, const p<Y> &rhs)
{
lhs.get_rw() = lhs.get_ro() << rhs.get_ro();
return lhs;
}
template <typename T, typename Y>
p<T> &
operator<<=(p<T> &lhs, const Y &rhs)
{
lhs.get_rw() = lhs.get_ro() << rhs;
return lhs;
}
template <typename T, typename Y>
p<T> &
operator>>=(p<T> &lhs, const p<Y> &rhs)
{
lhs.get_rw() = lhs.get_ro() >> rhs.get_ro();
return lhs;
}
template <typename T, typename Y>
p<T> &
operator>>=(p<T> &lhs, const Y &rhs)
{
lhs.get_rw() = lhs.get_ro() >> rhs;
return lhs;
}
}
}
namespace std
{
template <typename T>
struct numeric_limits<pmem::obj::p<T>> : public numeric_limits<T> {
static constexpr bool is_specialized = true;
};
}
#endif