mirror of
https://github.com/gcc-mirror/gcc.git
synced 2025-08-15 22:56:43 +00:00

The second bug report in PR121061 is that the conversion of custom OtherIndexType to IndexType is incorrectly not done via r-value references. This commit fixes the forwarding issue, adds a custom IndexType called RValueInt, which only allows conversion to int via r-value reference. PR libstdc++/121061 libstdc++-v3/ChangeLog: * include/std/mdspan (extents::extents): Perform conversion to index_type of an r-value reference. (layout_left::mapping::operator()): Ditto. (layout_right::mapping::operator()): Ditto. (layout_stride::mapping::operator()): Ditto. * testsuite/23_containers/mdspan/extents/custom_integer.cc: Add tests for RValueInt and MutatingInt. * testsuite/23_containers/mdspan/int_like.h (RValueInt): Add. * testsuite/23_containers/mdspan/layouts/mapping.cc: Test with RValueInt. * testsuite/23_containers/mdspan/mdspan.cc: Ditto. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
64 lines
1.3 KiB
C++
64 lines
1.3 KiB
C++
#ifndef TEST_MDSPAN_INT_LIKE_H
|
|
#define TEST_MDSPAN_INT_LIKE_H
|
|
|
|
enum class CustomIndexKind
|
|
{
|
|
Const,
|
|
Throwing,
|
|
Mutating,
|
|
RValue,
|
|
};
|
|
|
|
template<CustomIndexKind Kind>
|
|
class CustomIndexType
|
|
{
|
|
public:
|
|
explicit
|
|
CustomIndexType(int i)
|
|
: _M_i(i)
|
|
{ }
|
|
|
|
CustomIndexType() = delete;
|
|
CustomIndexType(const CustomIndexType&) = delete;
|
|
CustomIndexType(CustomIndexType&&) = delete;
|
|
|
|
const CustomIndexType&
|
|
operator=(const CustomIndexType&) = delete;
|
|
|
|
const CustomIndexType&
|
|
operator=(CustomIndexType&&) = delete;
|
|
|
|
constexpr
|
|
operator int() const noexcept
|
|
requires (Kind == CustomIndexKind::Const)
|
|
{ return _M_i; }
|
|
|
|
constexpr
|
|
operator int() const
|
|
requires (Kind == CustomIndexKind::Throwing)
|
|
{ return _M_i; }
|
|
|
|
constexpr
|
|
operator int() noexcept
|
|
requires (Kind == CustomIndexKind::Mutating)
|
|
{ return _M_i; }
|
|
|
|
constexpr
|
|
operator int() && noexcept
|
|
requires (Kind == CustomIndexKind::RValue)
|
|
{ return _M_i; }
|
|
|
|
private:
|
|
int _M_i;
|
|
};
|
|
|
|
using IntLike = CustomIndexType<CustomIndexKind::Const>;
|
|
using ThrowingInt = CustomIndexType<CustomIndexKind::Throwing>;
|
|
using MutatingInt = CustomIndexType<CustomIndexKind::Mutating>;
|
|
using RValueInt = CustomIndexType<CustomIndexKind::RValue>;
|
|
|
|
struct NotIntLike
|
|
{ };
|
|
|
|
#endif // TEST_MDSPAN_INT_LIKE_H
|