|
| 1 | +.. _blocked_nd_range_ctad: |
| 2 | + |
| 3 | +Deduction Guides for ``blocked_nd_range`` |
| 4 | +========================================= |
| 5 | + |
| 6 | +.. note:: |
| 7 | + To enable this feature, define the ``TBB_PREVIEW_BLOCKED_ND_RANGE_DEDUCTION_GUIDES`` macro to 1. |
| 8 | + |
| 9 | +.. contents:: |
| 10 | + :local: |
| 11 | + :depth: 1 |
| 12 | + |
| 13 | +Description |
| 14 | +*********** |
| 15 | + |
| 16 | +The ``blocked_nd_range`` class represents a recursively divisible N-dimensional half-open interval for the oneTBB |
| 17 | +parallel algorithms. This feature extends ``blocked_nd_range`` to support Class Template Argument |
| 18 | +Deduction (starting from C++17). With that, you do not need to specify template arguments explicitly |
| 19 | +while creating a ``blocked_nd_range`` object if they can be inferred from the constructor arguments: |
| 20 | + |
| 21 | +.. literalinclude:: ./examples/blocked_nd_range_ctad_example.cpp |
| 22 | + :language: c++ |
| 23 | + :start-after: /*begin_blocked_nd_range_ctad_example_1*/ |
| 24 | + :end-before: /*end_blocked_nd_range_ctad_example_1*/ |
| 25 | + |
| 26 | +.. note:: |
| 27 | + For more detailed description of the implementation of this feature or to leave comments or feedback on the API, please |
| 28 | + refer to the [corresponding RFC](https://github.com/uxlfoundation/oneTBB/tree/master/rfcs/experimental/blocked_nd_range_ctad). |
| 29 | + |
| 30 | +API |
| 31 | +*** |
| 32 | + |
| 33 | +Header |
| 34 | +------ |
| 35 | + |
| 36 | +.. code:: cpp |
| 37 | + |
| 38 | + #include <oneapi/tbb/blocked_nd_range.h> |
| 39 | +
|
| 40 | +Synopsis |
| 41 | +-------- |
| 42 | + |
| 43 | +.. code:: cpp |
| 44 | +
|
| 45 | + namespace oneapi { |
| 46 | + namespace tbb { |
| 47 | +
|
| 48 | + template <typename Value, unsigned int N> |
| 49 | + class blocked_nd_range { |
| 50 | + public: |
| 51 | + // Member types and constructors defined as part of oneTBB specification |
| 52 | + using value_type = Value; |
| 53 | + using dim_range_type = blocked_range<value_type>; |
| 54 | + using size_type = typename dim_range_type::size_type; |
| 55 | +
|
| 56 | + blocked_nd_range(const dim_range_type& dim0, /*exactly N arguments of type const dim_range_type&*/); // [1] |
| 57 | + blocked_nd_range(const value_type (&dim_size)[N], size_type grainsize = 1); // [2] |
| 58 | + blocked_nd_range(blocked_nd_range& r, split); // [3] |
| 59 | + blocked_nd_range(blocked_nd_range& r, proportional_split); // [4] |
| 60 | + }; // class blocked_nd_range |
| 61 | +
|
| 62 | + // Explicit deduction guides |
| 63 | + template <typename Value, typename... Values> |
| 64 | + blocked_nd_range(blocked_range<Value>, blocked_range<Values>...) |
| 65 | + -> blocked_nd_range<Value, 1 + sizeof...(Values)>; |
| 66 | +
|
| 67 | + template <typename Value, unsigned int... Ns> |
| 68 | + blocked_nd_range(const Value (&...)[Ns]) |
| 69 | + -> blocked_nd_range<Value, sizeof...(Ns)>; |
| 70 | +
|
| 71 | + template <typename Value, unsigned int N> |
| 72 | + blocked_nd_range(const Value (&)[N], typename blocked_nd_range<Value, N>::size_type = 1) |
| 73 | + -> blocked_nd_range<Value, N>; |
| 74 | +
|
| 75 | + template <typename Value, unsigned int N> |
| 76 | + blocked_nd_range(blocked_nd_range<Value, N>, split) |
| 77 | + -> blocked_nd_range<Value, N>; |
| 78 | +
|
| 79 | + template <typename Value, unsigned int N> |
| 80 | + blocked_nd_range(blocked_nd_range<Value, N>, proportional_split) |
| 81 | + -> blocked_nd_range<Value, N>; |
| 82 | + } // namespace tbb |
| 83 | + } // namespace oneapi |
| 84 | +
|
| 85 | +Deduction Guides |
| 86 | +---------------- |
| 87 | + |
| 88 | +The copy and move constructors of ``blocked_nd_range`` provide implicitly generated deduction guides. |
| 89 | +In addition, the following explicit deduction guides are provided: |
| 90 | + |
| 91 | +.. code:: cpp |
| 92 | +
|
| 93 | + template <typename Value, typename... Values> |
| 94 | + blocked_nd_range(blocked_range<Value>, blocked_range<Values>...) |
| 95 | + -> blocked_nd_range<Value, 1 + sizeof...(Values)>; |
| 96 | +
|
| 97 | +**Effects**: Enables deduction when a set of ``blocked_range`` objects is passed to the ``blocked_nd_range`` constructor ``[1]``. |
| 98 | + |
| 99 | +**Constraints**: Participates in overload resolution only if all of the types in `Values` are same as `Value`. |
| 100 | + |
| 101 | +.. code:: cpp |
| 102 | +
|
| 103 | + template <typename Value, unsigned int... Ns> |
| 104 | + blocked_nd_range(const Value (&...)[Ns]) |
| 105 | + -> blocked_nd_range<Value, sizeof...(Ns)>; |
| 106 | +
|
| 107 | +**Effects**: Enables deduction when a set of ``blocked_range`` objects is provided as braced-init-lists |
| 108 | +to the ``blocked_nd_range`` constructor ``[1]``. |
| 109 | + |
| 110 | +**Constraints**: Participates in overload resolution only if ``sizeof...(Ns) >= 2``, and each integer ``Ni`` in ``Ns`` |
| 111 | +is either ``2`` or ``3``, corresponding to ``blocked_range`` constructors with 2 and 3 arguments, respectively. |
| 112 | + |
| 113 | +.. note:: |
| 114 | + The guide allows a deduction only from braced-init-lists containing objects of the same type. |
| 115 | + For ranges with non-integral ``value_type``, setting an explicit grainsize argument |
| 116 | + is not supported by the deduction guides and requires specifying explicit template arguments. |
| 117 | + |
| 118 | +.. code:: cpp |
| 119 | +
|
| 120 | + template <typename Value, unsigned int N> |
| 121 | + blocked_nd_range(const Value (&)[N], typename blocked_nd_range<Value, N>::size_type = 1) |
| 122 | + -> blocked_nd_range<Value, N>; |
| 123 | +
|
| 124 | +**Effects**: Allows deduction from a single C array object indicating a set of dimension sizes to constructor |
| 125 | +``2`` of ``blocked_nd_range``. |
| 126 | + |
| 127 | +.. code:: cpp |
| 128 | +
|
| 129 | + template <typename Value, unsigned int N> |
| 130 | + blocked_nd_range(blocked_nd_range<Value, N>, split) |
| 131 | + -> blocked_nd_range<Value, N>; |
| 132 | +
|
| 133 | +**Effects**: Allows deduction while using the splitting constructor ``3`` of ``blocked_nd_range``. |
| 134 | + |
| 135 | +.. code:: cpp |
| 136 | +
|
| 137 | + template <typename Value, unsigned int N> |
| 138 | + blocked_nd_range(blocked_nd_range<Value, N>, proportional_split) |
| 139 | + -> blocked_nd_range<Value, N>; |
| 140 | +
|
| 141 | +**Effects**: Allows deduction while using the proportional splitting constructor ``4`` of ``blocked_nd_range``. |
| 142 | + |
| 143 | +Example |
| 144 | +------- |
| 145 | + |
| 146 | +.. literalinclude:: ./examples/blocked_nd_range_ctad_example.cpp |
| 147 | + :language: c++ |
| 148 | + :start-after: /*begin_blocked_nd_range_ctad_example_2*/ |
| 149 | + :end-before: /*end_blocked_nd_range_ctad_example_2*/ |
0 commit comments