mirror of
https://github.com/boostorg/histogram.git
synced 2025-05-11 13:14:06 +00:00
fully enable move semantics
This commit is contained in:
parent
4720450aa2
commit
ad7f981635
@ -7,10 +7,10 @@
|
||||
#include <boost/serialization/array.hpp>
|
||||
#include <boost/cstdint.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/move/move.hpp>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <limits>
|
||||
#include <stdexcept>
|
||||
#include <vector>
|
||||
#include <new> // for bad:alloc
|
||||
|
||||
@ -19,15 +19,22 @@ namespace histogram {
|
||||
namespace detail {
|
||||
|
||||
class nstore {
|
||||
BOOST_COPYABLE_AND_MOVABLE(nstore)
|
||||
public:
|
||||
typedef uintptr_t size_type;
|
||||
|
||||
nstore();
|
||||
nstore(const nstore&);
|
||||
nstore(size_type, unsigned d = sizeof(uint8_t));
|
||||
~nstore() { destroy(); }
|
||||
|
||||
nstore& operator=(const nstore&);
|
||||
// copy semantics
|
||||
nstore(const nstore&);
|
||||
nstore& operator=(BOOST_COPY_ASSIGN_REF(nstore));
|
||||
|
||||
// move semantics
|
||||
nstore(BOOST_RV_REF(nstore));
|
||||
nstore& operator=(BOOST_RV_REF(nstore));
|
||||
|
||||
nstore& operator+=(const nstore&);
|
||||
bool operator==(const nstore&) const;
|
||||
|
||||
|
@ -11,21 +11,31 @@
|
||||
#include <boost/type_traits.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/move/move.hpp>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace boost {
|
||||
namespace histogram {
|
||||
|
||||
class histogram : public basic_histogram {
|
||||
BOOST_COPYABLE_AND_MOVABLE(histogram)
|
||||
public:
|
||||
histogram() {}
|
||||
histogram(const histogram& o);
|
||||
|
||||
// copy semantics
|
||||
histogram(const histogram&);
|
||||
histogram& operator=(BOOST_COPY_ASSIGN_REF(histogram));
|
||||
|
||||
// move semantics
|
||||
histogram(BOOST_RV_REF(histogram));
|
||||
histogram& operator=(BOOST_RV_REF(histogram));
|
||||
|
||||
explicit histogram(const axes_type& axes);
|
||||
|
||||
#define BOOST_HISTOGRAM_CTOR(z, n, unused) \
|
||||
histogram( BOOST_PP_ENUM_PARAMS_Z(z, n, const axis_type& a) ) : \
|
||||
basic_histogram( BOOST_PP_ENUM_PARAMS_Z(z, n, a) ), \
|
||||
data_(field_count()) \
|
||||
#define BOOST_HISTOGRAM_CTOR(z, n, unused) \
|
||||
explicit histogram( BOOST_PP_ENUM_PARAMS_Z(z, n, const axis_type& a) ) : \
|
||||
basic_histogram( BOOST_PP_ENUM_PARAMS_Z(z, n, a) ), \
|
||||
data_(field_count()) \
|
||||
{}
|
||||
|
||||
// generates constructors taking 1 to AXIS_LIMIT arguments
|
||||
|
@ -9,6 +9,29 @@ histogram::histogram(const histogram& o) :
|
||||
data_(o.data_)
|
||||
{}
|
||||
|
||||
histogram& histogram::operator=(BOOST_COPY_ASSIGN_REF(histogram) o)
|
||||
{
|
||||
if (this != &o) {
|
||||
basic_histogram::operator=(static_cast<const basic_histogram&>(o));
|
||||
data_ = o.data_;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
histogram::histogram(BOOST_RV_REF(histogram) o) :
|
||||
basic_histogram(::boost::move(static_cast<basic_histogram&>(o))),
|
||||
data_(::boost::move(o.data_))
|
||||
{}
|
||||
|
||||
histogram& histogram::operator=(BOOST_RV_REF(histogram) o)
|
||||
{
|
||||
if (this != &o) {
|
||||
basic_histogram::operator=(::boost::move(static_cast<basic_histogram&>(o)));
|
||||
data_ = ::boost::move(o.data_);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
histogram::histogram(const axes_type& axes) :
|
||||
basic_histogram(axes),
|
||||
data_(field_count())
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include <boost/histogram/detail/nstore.hpp>
|
||||
#include <boost/cstdint.hpp>
|
||||
#include <stdexcept>
|
||||
#include <new> // for std::bad_alloc
|
||||
|
||||
@ -13,14 +12,6 @@ nstore::nstore() :
|
||||
buffer_(0)
|
||||
{}
|
||||
|
||||
nstore::nstore(const nstore& o) :
|
||||
size_(o.size_),
|
||||
depth_(o.depth_)
|
||||
{
|
||||
create();
|
||||
std::memcpy(buffer_, o.buffer_, size_ * depth_);
|
||||
}
|
||||
|
||||
nstore::nstore(size_type n, unsigned d) :
|
||||
size_(n),
|
||||
depth_(d)
|
||||
@ -34,16 +25,46 @@ nstore::nstore(size_type n, unsigned d) :
|
||||
if (d > 0) create();
|
||||
}
|
||||
|
||||
nstore&
|
||||
nstore::operator=(const nstore& o)
|
||||
nstore::nstore(const nstore& o) :
|
||||
size_(o.size_),
|
||||
depth_(o.depth_)
|
||||
{
|
||||
if (size_ != o.size_ || depth_ != o.depth_) {
|
||||
create();
|
||||
std::memcpy(buffer_, o.buffer_, size_ * depth_);
|
||||
}
|
||||
|
||||
nstore&
|
||||
nstore::operator=(BOOST_COPY_ASSIGN_REF(nstore) o)
|
||||
{
|
||||
if (this != &o) {
|
||||
if (size_ != o.size_ || depth_ != o.depth_) {
|
||||
destroy();
|
||||
size_ = o.size_;
|
||||
depth_ = o.depth_;
|
||||
create();
|
||||
}
|
||||
std::memcpy(buffer_, o.buffer_, size_ * depth_);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
nstore::nstore(BOOST_RV_REF(nstore) o) :
|
||||
size_(o.size_),
|
||||
depth_(o.depth_),
|
||||
buffer_(0)
|
||||
{
|
||||
std::swap(buffer_, o.buffer_);
|
||||
}
|
||||
|
||||
nstore&
|
||||
nstore::operator=(BOOST_RV_REF(nstore) o)
|
||||
{
|
||||
if (this != &o) {
|
||||
destroy();
|
||||
size_ = o.size_;
|
||||
depth_ = o.depth_;
|
||||
create();
|
||||
std::swap(buffer_, o.buffer_);
|
||||
}
|
||||
std::memcpy(buffer_, o.buffer_, size_ * depth_);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user