mirror of
https://github.com/boostorg/histogram.git
synced 2025-05-11 21:24:14 +00:00
return copy instead of reference for scalar types (#218)
This commit is contained in:
parent
d0a1c027ee
commit
c5c251fdbf
@ -128,7 +128,8 @@ public:
|
|||||||
|
|
||||||
/// Return value for index argument.
|
/// Return value for index argument.
|
||||||
/// Throws `std::out_of_range` if the index is out of bounds.
|
/// Throws `std::out_of_range` if the index is out of bounds.
|
||||||
decltype(auto) value(index_type idx) const {
|
std::conditional_t<std::is_scalar<value_type>::value, value_type, const value_type&>
|
||||||
|
value(index_type idx) const {
|
||||||
if (idx < 0 || idx >= size())
|
if (idx < 0 || idx >= size())
|
||||||
BOOST_THROW_EXCEPTION(std::out_of_range("category index out of range"));
|
BOOST_THROW_EXCEPTION(std::out_of_range("category index out of range"));
|
||||||
return vec_meta_.first()[idx];
|
return vec_meta_.first()[idx];
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
// or copy at http://www.boost.org/LICENSE_1_0.txt)
|
// or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
#include <boost/core/lightweight_test.hpp>
|
#include <boost/core/lightweight_test.hpp>
|
||||||
|
#include <boost/core/lightweight_test_trait.hpp>
|
||||||
#include <boost/histogram/axis/category.hpp>
|
#include <boost/histogram/axis/category.hpp>
|
||||||
#include <boost/histogram/axis/ostream.hpp>
|
#include <boost/histogram/axis/ostream.hpp>
|
||||||
#include <boost/histogram/detail/cat.hpp>
|
#include <boost/histogram/detail/cat.hpp>
|
||||||
@ -64,6 +65,15 @@ int main() {
|
|||||||
BOOST_TEST_NE(c, d);
|
BOOST_TEST_NE(c, d);
|
||||||
d = std::move(c);
|
d = std::move(c);
|
||||||
BOOST_TEST_EQ(d, a);
|
BOOST_TEST_EQ(d, a);
|
||||||
|
|
||||||
|
enum class Foo { foo };
|
||||||
|
|
||||||
|
BOOST_TEST_TRAIT_SAME(decltype(std::declval<axis::category<std::string>>().value(0)),
|
||||||
|
const std::string&);
|
||||||
|
BOOST_TEST_TRAIT_SAME(decltype(std::declval<axis::category<const char*>>().value(0)),
|
||||||
|
const char*);
|
||||||
|
BOOST_TEST_TRAIT_SAME(decltype(std::declval<axis::category<Foo>>().value(0)), Foo);
|
||||||
|
BOOST_TEST_TRAIT_SAME(decltype(std::declval<axis::category<int>>().value(0)), int);
|
||||||
}
|
}
|
||||||
|
|
||||||
// axis::category with growth
|
// axis::category with growth
|
||||||
|
Loading…
x
Reference in New Issue
Block a user