• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

    最終更新日時(UTC):
    が更新

    履歴 編集

    function
    <mdspan>

    std::layout_left::mapping::コンストラクタ

    constexpr mapping() noexcept = default;  // (1)
    
    constexpr mapping(const mapping&) noexcept = default;  // (2)
    
    constexpr mapping(const extents_type& e) noexcept;  // (3)
    
    template<class OtherExtents>
    constexpr explicit(!is_convertible_v<OtherExtents, extents_type>)
      mapping(const mapping<OtherExtents>& other) noexcept;  // (4)
    
    template<class OtherExtents>
    constexpr explicit(!is_convertible_v<OtherExtents, extents_type>)
      mapping(const layout_right::mapping<OtherExtents>& other) noexcept;  // (5)
    
    template<class LayoutLeftPaddedMapping>
    constexpr explicit(!is_convertible_v<typename LayoutLeftPaddedMapping::extents_type, extents_type>)
      mapping(const LayoutLeftPaddedMapping& other) noexcept;  // (7) C++26
    
    template<class OtherExtents>
    constexpr explicit(extents_type::rank() > 0)
      mapping(const layout_stride::mapping<OtherExtents>& other) noexcept;  // (6)
    

    概要

    テンプレートパラメータ制約

    適格要件

    事前条件

    効果

    例外

    投げない

    explicitになる条件

    #include <cassert>
    #include <array>
    #include <mdspan>
    
    using Ext3x4 = std::extents<size_t, 3, 4>;
    using Ext3xN = std::extents<size_t, 3, std::dynamic_extent>;
    
    int main()
    {
      // (1) : デフォルトコンストラクタ
      {
        std::layout_left::mapping<Ext3x4> map1_3x4;
        std::layout_left::mapping<Ext3xN> map1_3xN;
        assert(map1_3x4.required_span_size() == 12);
        assert(map1_3xN.required_span_size() == 0);
      }
      // (2) : コピーコンストラクタ
      {
        std::layout_left::mapping<Ext3xN> map2_a;
        std::layout_left::mapping<Ext3xN> map2_b = map2_a;
        assert(map2_a == map2_b);
      }
      // (3) : extentsから構築
      {
        Ext3xN ext{4};
        std::layout_left::mapping<Ext3xN> map3 = ext;
        assert(map3.extents() == ext);
      }
      // (4) : layout_left::mappingからの変換コンストラクタ
      {
        std::layout_left::mapping<Ext3x4> map4_3x4;
        std::layout_left::mapping<Ext3xN> map4_3xN = map4_3x4;
        assert(map4_3x4 == map4_3xN);
      }
      // (5) : layout_right::mappingからの変換コンストラクタ
      {
        using Ext1D = std::dextents<size_t, 1>;
        std::layout_right::mapping<Ext1D> src5{Ext1D{5}};
        std::layout_left::mapping<Ext1D>  dst5 = src5;
      }
      // (6) : layout_stride::mappingからの変換コンストラクタ
      {
        std::array strides{1, 3};
        std::layout_stride::mapping<Ext3x4> src6{{}, strides};
        std::layout_left::mapping<Ext3x4>   dst6{src6};  // (explicit)
      }
    }
    

    出力

    バージョン

    言語

    • C++23

    処理系

    関連項目

    参照