Skip to content

Commit

Permalink
Merge branch 'implement-mbegin' into 'master'
Browse files Browse the repository at this point in the history
add ctad warning

See merge request correaa/boost-multi!1233
  • Loading branch information
correaa committed Sep 14, 2024
2 parents 077384d + e61ccd5 commit 4495d51
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
11 changes: 9 additions & 2 deletions include/boost/multi/array_ref.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1889,7 +1889,7 @@ class subarray : public const_subarray<T, D, ElementPtr, Layout> {
>
constexpr auto operator=(Range const& rng) & // check that you LHS is not read-only
-> subarray& { // lints(cppcoreguidelines-c-copy-assignment-signature,misc-unconventional-assign-operator)
assert(this->size() == rng.size()); // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay,hicpp-no-array-decay) : normal in a constexpr function
assert( this->size() == rng.size() ); // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay,hicpp-no-array-decay) : normal in a constexpr function
// MULTI_MARK_SCOPE(std::string{"multi::operator= D="}+std::to_string(D)+" from range to "+typeid(T).name() );
// adl_copy_n(adl_begin(r), this->size(), begin());
adl_copy(adl_begin(rng), adl_end(rng), this->begin());
Expand Down Expand Up @@ -1925,6 +1925,13 @@ class subarray : public const_subarray<T, D, ElementPtr, Layout> {
return *this;
}

// template<class TT, class... As>
// constexpr
// auto operator=(array<TT, D, As...>&& other) & -> subarray& {
// operator=(static_cast<move_subarray<TT, D, As...>&&>(std::move(other)));
// other.clear(); // TODO(correaa) is this a good idea?
// return *this;
// }

constexpr auto operator=(const_subarray<T, D, ElementPtr, Layout> const& other) const&& -> subarray&; // for std::indirectly_writable
// {
Expand Down Expand Up @@ -2238,7 +2245,7 @@ struct array_iterator<Element, 1, Ptr, IsConst, IsMove> // NOLINT(fuchsia-multi
constexpr explicit operator bool() const {return static_cast<bool>(this->ptr_);}

BOOST_MULTI_HD constexpr auto operator[](typename array_iterator::difference_type n) const -> decltype(auto) {
return static_cast<reference>(*((*this) + n));
return *((*this) + n);
}

constexpr auto operator->() const {return static_cast<pointer>(ptr_);}
Expand Down
3 changes: 2 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ else()
-Wconditionally-supported
-Wconversion -Wconversion-null
-Wcoverage-mismatch -Wcpp
# -Wctad-maybe-unsupported # (gcc 12, not in 9)
$<$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,12>:-Wctad-maybe-unsupported>
-Wctor-dtor-privacy
-Wdangling-else
# -Wdangling-pointer # (gcc 12, not in 11)
Expand Down Expand Up @@ -354,6 +354,7 @@ else()
-Wcovered-switch-default
-Wcpp
-Wcstring-format-directive
$<$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,18>:-Wctad-maybe-unsupported>
-Wctor-dtor-privacy
# -Wctu # (not in clang 7)
-Wcuda-compat
Expand Down
10 changes: 10 additions & 0 deletions test/move.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ namespace multi = boost::multi;
namespace {

void move_element_1d_array() {
{
std::vector<multi::array<int, 1> > varr(3, multi::array<int, 1>({5}, 99), {});
multi::array<int, 2> marr({3, 5}, 99);
marr[0] = std::move(varr[0]);
marr[1] = std::move(varr[1]);
marr[2] = std::move(varr[2]);

BOOST_TEST( marr[0][0] == 99 );
BOOST_TEST( !varr[0].empty() );
}
{
multi::array<std::vector<double>, 1> arr(10, std::vector<double>(5, {}, {}));
multi::array<std::vector<double>, 1> brr(10, {}, {});
Expand Down

0 comments on commit 4495d51

Please sign in to comment.