ORNL / cpp-proposals-pub

Collaborating on papers for the ISO C++ committee - public repo
26 stars 27 forks source link

P0009 LayoutStride Wording #31

Closed crtrott closed 6 years ago

crtrott commented 6 years ago
struct layout_stride {
  template <typename Extents>
  class mapping {
  public:
    constexpr mapping() noexcept;
    constexpr mapping(mapping const& other) noexcept;
    constexpr mapping(mapping&& other) noexcept;
    constexpr mapping(Extents e, array<ptrdiff_t, Extents::rank()> s) noexcept;
    template<class OtherExtents>
      constexpr mapping(const mapping<OtherExtents>& other);

    mapping& operator=() noexcept = default;
    mapping& operator=(mapping const& other) noexcept = default;
    template<class OtherExtents>
      constexpr mapping& operator=(const mapping<OtherExtents>& other);

    Extents get_extents() const noexcept;
    array<ptrdiff_t, Extents::rank()> get_strides() const noexcept;

    constexpr typename Extents::index_type required_span_size() const noexcept;

    template <class... Indices>
      typename Extents::index_type operator()(Indices... is) const;

    static constexpr bool is_always_unique() noexcept;
    static constexpr bool is_always_contiguous() noexcept;
    static constexpr bool is_always_strided() noexcept;

    constexpr bool is_unique() const noexcept;
    constexpr bool is_contiguous() const noexcept;
    constexpr bool is_strided() const noexcept;

    ptrdiff_t stride(size_t rank) const noexcept;

  private:
    Extents extents_; // exposition only
    //TODO: should this be extents<dynamic_extent,...,dynamic_extent> ?
    array<ptrdiff_t, Extents::rank()> strides_; // exposition only
  };
};

26.7.�.3.1 layout_right::mapping constructors [mdspan.layout.right.cons]

constexpr mapping() noexcept;
constexpr mapping(mapping const& other) noexcept;
constexpr mapping(mapping&& other) noexcept;
constexpr mapping(Extents e, array<ptrdiff_t, Extents::rank()> s) noexcept;
template<class OtherExtents>
  constexpr mapping(const mapping<OtherExtents>& other);

26.7.�.3.2 layout_right::mapping operations [mdspan.layout.right.ops]

Extents get_extents() const noexcept;
Extents get_strides() const noexcept;
typename Extents::index_type required_span_size() const noexcept;
template <class... Indices>
  typename Extents::index_type operator()(Indices... i) const noexcept;
static constexpr bool is_always_unique() noexcept;
static constexpr bool is_always_strided() noexcept;
constexpr bool is_unique() const noexcept;
constexpr bool is_strided() const noexcept;

TODO: should this be always unique?

static constexpr bool is_always_contiguous() noexcept;
constexpr bool is_contiguous() const noexcept;
index_type stride(int r) const noexcept;
constexpr bool operator==(const mapping& other) const noexcept;
constexpr bool operator!=(const mapping& other) const noexcept;
dhollman commented 6 years ago
  • Postconditions: get_extents() == Extents() and get_strides() == array<ptrdiff_t, Extents::rank()>()

I'm pretty sure this would make get_strides() into uninitialized memory. I think what you'd actually want is get_strides() == array<ptrdiff_t, Extents::rank()>{}, though I'm not positive about this.

26.7.�.3.1 layout_right::mapping constructors

This should be layout_stride (also a few other places)

  • Effects: Initializes extents with move(other.extents).

Two things:

(Also need to make the analogous changes to the copy constructor.)

Remove noexcept here; it has a requires clause so it can't be noexcept.

more to come...

crtrott commented 6 years ago

I think this is resolved