constexpr
mdspan()
requires (rank_dynamic() > 0)
- && is_default_constructible_v<data_handle_type>
+ && is_default_constructible_v<data_handle_type>
&& is_default_constructible_v<mapping_type>
- && is_default_constructible_v<accessor_type>
- : _M_accessor(), _M_mapping(), _M_handle()
- { }
+ && is_default_constructible_v<accessor_type> = default;
constexpr
mdspan(const mdspan& __other) = default;
stride(rank_type __r) const { return _M_mapping.stride(__r); }
private:
- [[no_unique_address]] accessor_type _M_accessor;
- [[no_unique_address]] mapping_type _M_mapping;
- [[no_unique_address]] data_handle_type _M_handle;
+ [[no_unique_address]] accessor_type _M_accessor = accessor_type();
+ [[no_unique_address]] mapping_type _M_mapping = mapping_type();
+ [[no_unique_address]] data_handle_type _M_handle = data_handle_type();
};
template<typename _CArray>
#include <testsuite_hooks.h>
#include "int_like.h"
#include "layout_like.h"
+#include <stdexcept>
constexpr auto dyn = std::dynamic_extent;
return true;
}
+template<typename T>
+ class ThrowingDefaultAccessor
+ {
+ public:
+ using element_type = T;
+ using reference = element_type&;
+ using data_handle_type = element_type*;
+ using offset_policy = ThrowingDefaultAccessor;
+
+ ThrowingDefaultAccessor() noexcept(false)
+ { }
+
+ reference
+ access(data_handle_type p, size_t i) const
+ { return p[i]; }
+
+ typename offset_policy::data_handle_type
+ offset(data_handle_type p, size_t i) const
+ { return p + i; }
+ };
+
constexpr bool
test_default_ctor()
{
return true;
}
+template<template<typename T> typename Accessor, bool Expected>
+ constexpr void
+ test_nothrow_default_ctor()
+ {
+ using Extents = std::extents<int, dyn>;
+ using Layout = std::layout_left;
+ using MDSpan = std::mdspan<double, Extents, Layout, Accessor<double>>;
+
+ static_assert(std::is_default_constructible_v<MDSpan>);
+ static_assert(std::is_nothrow_default_constructible_v<MDSpan> == Expected);
+ }
+
constexpr bool
test_from_other()
{
test_default_ctor();
static_assert(test_default_ctor());
+ test_nothrow_default_ctor<std::default_accessor, true>();
+ test_nothrow_default_ctor<ThrowingDefaultAccessor, false>();
+
test_from_other();
static_assert(test_from_other());