switching back to container::vector, fixed bug in use of AXIS_LIMIT

This commit is contained in:
Hans Dembinski 2016-06-23 10:47:41 -04:00
parent 4e1d0791a0
commit 6cf51f2088
4 changed files with 16 additions and 27 deletions

View File

@ -11,7 +11,7 @@
#include <boost/histogram/visitors.hpp>
#include <boost/cstdint.hpp>
#include <boost/preprocessor.hpp>
#include <boost/container/static_vector.hpp>
#include <boost/container/vector.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/utility/enable_if.hpp>
#include <boost/move/move.hpp>
@ -29,7 +29,7 @@ namespace histogram {
class basic_histogram {
BOOST_COPYABLE_AND_MOVABLE(basic_histogram)
public:
typedef container::static_vector<axis_type, BOOST_HISTOGRAM_AXIS_LIMIT> axes_type;
typedef container::vector<axis_type> axes_type;
typedef uintptr_t size_type;
~basic_histogram() {}
@ -96,7 +96,7 @@ protected:
}
// generates constructors taking 1 to AXIS_LIMIT arguments
BOOST_PP_REPEAT_FROM_TO(1, BOOST_HISTOGRAM_AXIS_LIMIT, BOOST_HISTOGRAM_BASE_CTOR, nil)
BOOST_PP_REPEAT_FROM_TO(1, BOOST_PP_INC(BOOST_HISTOGRAM_AXIS_LIMIT), BOOST_HISTOGRAM_BASE_CTOR, nil)
bool operator==(const basic_histogram&) const;

View File

@ -51,7 +51,7 @@ public:
{}
// generates constructors taking 1 to AXIS_LIMIT arguments
BOOST_PP_REPEAT_FROM_TO(1, BOOST_HISTOGRAM_AXIS_LIMIT, BOOST_HISTOGRAM_CTOR, nil)
BOOST_PP_REPEAT_FROM_TO(1, BOOST_PP_INC(BOOST_HISTOGRAM_AXIS_LIMIT), BOOST_HISTOGRAM_CTOR, nil)
#if defined(BOOST_HISTOGRAM_DOXYGEN)
/**Constructors for a variable number of axis types, each defining the binning

View File

@ -14,7 +14,7 @@ namespace histogram {
basic_histogram::basic_histogram(const axes_type& axes) :
axes_(axes)
{
if (axes_.size() >= BOOST_HISTOGRAM_AXIS_LIMIT)
if (axes_.size() > BOOST_HISTOGRAM_AXIS_LIMIT)
throw std::invalid_argument("too many axes");
}

View File

@ -10,6 +10,7 @@
#include <boost/test/test_tools.hpp>
#include <boost/assign/std/vector.hpp>
#include <boost/move/move.hpp>
#include <boost/preprocessor.hpp>
#include <limits>
using namespace boost::assign;
using namespace boost::histogram;
@ -58,35 +59,23 @@ BOOST_AUTO_TEST_CASE(init_5)
category_axis("A;B;C"));
}
BOOST_AUTO_TEST_CASE(init_15)
BOOST_AUTO_TEST_CASE(init_max)
{
histogram(regular_axis(1, -1, 1),
regular_axis(1, -1, 1),
regular_axis(1, -1, 1),
regular_axis(1, -1, 1),
regular_axis(1, -1, 1),
#define ARG(z, n, data) regular_axis(1, -1, 1)
histogram( BOOST_PP_ENUM( BOOST_HISTOGRAM_AXIS_LIMIT, ARG, nil ) );
regular_axis(1, -1, 1),
regular_axis(1, -1, 1),
regular_axis(1, -1, 1),
regular_axis(1, -1, 1),
regular_axis(1, -1, 1),
regular_axis(1, -1, 1),
regular_axis(1, -1, 1),
regular_axis(1, -1, 1),
regular_axis(1, -1, 1),
regular_axis(1, -1, 1));
histogram(histogram::axes_type(15,
regular_axis(1, -1, 1)));
histogram(
histogram::axes_type( BOOST_HISTOGRAM_AXIS_LIMIT,
regular_axis(1, -1, 1) )
);
}
BOOST_AUTO_TEST_CASE(too_many_axes)
{
BOOST_CHECK_THROW(
histogram(
histogram::axes_type(16, regular_axis(1, -1, 1))
histogram::axes_type( BOOST_PP_INC(BOOST_HISTOGRAM_AXIS_LIMIT),
regular_axis(1, -1, 1) )
),
std::logic_error
);
@ -95,7 +84,7 @@ BOOST_AUTO_TEST_CASE(too_many_axes)
BOOST_AUTO_TEST_CASE(bad_alloc)
{
BOOST_CHECK_THROW(
histogram(histogram::axes_type(15,
histogram(histogram::axes_type( BOOST_HISTOGRAM_AXIS_LIMIT,
regular_axis(std::numeric_limits<int>::max(), 0, 1))),
std::bad_alloc
);