Skip to content

Commit 988f155

Browse files
committed
Rework of forbidden rvalue methods.
1 parent 10d494e commit 988f155

17 files changed

+191
-507
lines changed

RELEASE_NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Version vxx.yy.zz -- Release date 20yy-mm-dd
1212
* Fixed indexing bug that produced a compilation error with GCC 10.
1313
* Fixed a memory leak in `CRSMatrix::assimilate`.
1414
* Fixed a memory leak in `ArrayOfArraysView::free` with non-trivially destructable values.
15+
* Fixed a compilation error with GCC 9.
1516

1617
Version v0.1.0 -- Release date 2020-10-13
1718
=========================================

src/Array.hpp

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -194,66 +194,70 @@ class Array : public ArrayView< T,
194194
using ParentClass::toView;
195195

196196
/**
197-
* @brief Overload for rvalues that raises a compilation error when used.
198-
* @return A null ArrayView.
197+
* @brief Overload for rvalues that is deleted.
198+
* @return None.
199199
* @note This cannot be called on a rvalue since the @c ArrayView would
200200
* contain the buffer of the current @c Array that is about to be destroyed.
201201
* This overload prevents that from happening.
202202
*/
203203
inline LVARRAY_HOST_DEVICE constexpr
204-
ArrayView< T, NDIM, USD, INDEX_TYPE, BUFFER_TYPE > toView() const &&
205-
{
206-
static_assert( !typeManipulation::always_true< T >, "Cannot call toView on a rvalue." );
207-
return ArrayView< T, NDIM, USD, INDEX_TYPE, BUFFER_TYPE >();
208-
}
204+
ArrayView< T, NDIM, USD, INDEX_TYPE, BUFFER_TYPE > toView() const && = delete;
209205

210206
using ParentClass::toViewConst;
211207

212208
/**
213-
* @brief Overload for rvalues that raises a compilation error when used.
214-
* @return A null ArrayView.
209+
* @brief Overload for rvalues that is deleted.
210+
* @return None.
215211
* @note This cannot be called on a rvalue since the @c ArrayView would
216212
* contain the buffer of the current @c Array that is about to be destroyed.
217213
* This overload prevents that from happening.
218214
*/
219215
inline LVARRAY_HOST_DEVICE constexpr
220-
ArrayView< T const, NDIM, USD, INDEX_TYPE, BUFFER_TYPE > toViewConst() const &&
221-
{
222-
static_assert( !typeManipulation::always_true< T >, "Cannot call toViewConst on a rvalue." );
223-
return ArrayView< T const, NDIM, USD, INDEX_TYPE, BUFFER_TYPE >();
224-
}
216+
ArrayView< T const, NDIM, USD, INDEX_TYPE, BUFFER_TYPE > toViewConst() const && = delete;
225217

226218
using ParentClass::toNestedView;
227219

228220
/**
229-
* @brief Overload for rvalues that raises a compilation error when used.
230-
* @return A null ArrayView.
221+
* @brief Overload for rvalues that is deleted.
222+
* @return None.
231223
* @note This cannot be called on a rvalue since the @c ArrayView would
232224
* contain the buffer of the current @c Array that is about to be destroyed.
233225
* This overload prevents that from happening.
234226
*/
235227
inline LVARRAY_HOST_DEVICE constexpr
236-
NestedViewType toNestedView() const &&
237-
{
238-
static_assert( !typeManipulation::always_true< T >, "Cannot call toViewNested on a rvalue." );
239-
return NestedViewType();
240-
}
228+
NestedViewType toNestedView() const && = delete;
241229

242230
using ParentClass::toNestedViewConst;
243231

244232
/**
245-
* @brief Overload for rvalues that raises a compilation error when used.
246-
* @return A null ArrayView.
233+
* @brief Overload for rvalues that is deleted.
234+
* @return None.
247235
* @note This cannot be called on a rvalue since the @c ArrayView would
248236
* contain the buffer of the current @c Array that is about to be destroyed.
249237
* This overload prevents that from happening.
250238
*/
251239
inline LVARRAY_HOST_DEVICE constexpr
252-
NestedViewTypeConst toNestedViewConst() const &&
253-
{
254-
static_assert( !typeManipulation::always_true< T >, "Cannot call toViewNestedConst on a rvalue." );
255-
return NestedViewTypeConst();
256-
}
240+
NestedViewTypeConst toNestedViewConst() const && = delete;
241+
242+
/**
243+
* @brief A user defined conversion operator (UDC) to an ArrayView< T const, ... >.
244+
* @return A new ArrayView where @c T is @c const.
245+
*/
246+
inline LVARRAY_HOST_DEVICE constexpr
247+
operator ArrayView< T const, NDIM, USD, INDEX_TYPE, BUFFER_TYPE >() const & noexcept
248+
{ return toViewConst(); }
249+
250+
/**
251+
* @brief Overload for rvalues that is deleted.
252+
* @return None.
253+
* @note This cannot be called on a rvalue since the @c ArrayView would
254+
* contain the buffer of the current @c Array that is about to be destroyed.
255+
* This overload prevents that from happening.
256+
*/
257+
template< typename _T=T >
258+
inline LVARRAY_HOST_DEVICE constexpr
259+
operator std::enable_if_t< !std::is_const< _T >::value,
260+
ArrayView< T const, NDIM, USD, INDEX_TYPE, BUFFER_TYPE > >() const && noexcept = delete;
257261

258262
///@}
259263

src/ArrayOfArrays.hpp

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,15 @@ class ArrayOfArrays : protected ArrayOfArraysView< T, INDEX_TYPE, false, BUFFER_
9999
{ return ParentClass::toView(); }
100100

101101
/**
102-
* @brief Overload for rvalues that raises a compilation error when used.
102+
* @brief Overload for rvalues that is deleted.
103103
* @return A null ArrayOfArraysView.
104104
* @note This cannot be called on a rvalue since the @c ArrayOfArraysView would
105105
* contain the buffer of the current @c ArrayOfArrays that is about to be destroyed.
106106
* This overload prevents that from happening.
107107
*/
108108
constexpr inline
109109
ArrayOfArraysView< T, INDEX_TYPE const, false, BUFFER_TYPE >
110-
toView() const &&
111-
{
112-
static_assert( !typeManipulation::always_true< T >, "Cannot call toView on a rvalue." );
113-
return ParentClass::toView();
114-
}
110+
toView() const && = delete;
115111

116112
/**
117113
* @copydoc ParentClass::toViewConstSizes
@@ -125,19 +121,15 @@ class ArrayOfArrays : protected ArrayOfArraysView< T, INDEX_TYPE, false, BUFFER_
125121
{ return ParentClass::toViewConstSizes(); }
126122

127123
/**
128-
* @brief Overload for rvalues that raises a compilation error when used.
124+
* @brief Overload for rvalues that is deleted.
129125
* @return A null ArrayOfArraysView.
130126
* @note This cannot be called on a rvalue since the @c ArrayOfArraysView would
131127
* contain the buffer of the current @c ArrayOfArrays that is about to be destroyed.
132128
* This overload prevents that from happening.
133129
*/
134130
constexpr inline
135131
ArrayOfArraysView< T, INDEX_TYPE const, true, BUFFER_TYPE >
136-
toViewConstSizes() const &&
137-
{
138-
static_assert( !typeManipulation::always_true< T >, "Cannot call toViewConstSizes on a rvalue." );
139-
return ParentClass::toViewConstSizes();
140-
}
132+
toViewConstSizes() const && = delete;
141133

142134
/**
143135
* @copydoc ParentClass::toViewConst
@@ -151,19 +143,15 @@ class ArrayOfArrays : protected ArrayOfArraysView< T, INDEX_TYPE, false, BUFFER_
151143
{ return ParentClass::toViewConst(); }
152144

153145
/**
154-
* @brief Overload for rvalues that raises a compilation error when used.
146+
* @brief Overload for rvalues that is deleted.
155147
* @return A null ArrayOfArraysView.
156148
* @note This cannot be called on a rvalue since the @c ArrayOfArraysView would
157149
* contain the buffer of the current @c ArrayOfArrays that is about to be destroyed.
158150
* This overload prevents that from happening.
159151
*/
160152
constexpr inline
161153
ArrayOfArraysView< T const, INDEX_TYPE const, true, BUFFER_TYPE >
162-
toViewConst() const &&
163-
{
164-
static_assert( !typeManipulation::always_true< T >, "Cannot call toViewConst on a rvalue." );
165-
return ParentClass::toViewConst();
166-
}
154+
toViewConst() const && = delete;
167155

168156
///@}
169157

src/ArrayOfSets.hpp

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -193,19 +193,15 @@ class ArrayOfSets : protected ArrayOfSetsView< T, INDEX_TYPE, BUFFER_TYPE >
193193
{ return ParentClass::toView(); }
194194

195195
/**
196-
* @brief Overload for rvalues that raises a compilation error when used.
196+
* @brief Overload for rvalues that is deleted.
197197
* @return A null ArrayOfSetsView.
198198
* @note This cannot be called on a rvalue since the @c ArrayOfSetsView would
199199
* contain the buffers of the current @c ArrayOfSets that is about to be destroyed.
200200
* This overload prevents that from happening.
201201
*/
202202
constexpr inline
203203
ArrayOfSetsView< T, INDEX_TYPE const, BUFFER_TYPE >
204-
toView() const &&
205-
{
206-
static_assert( !typeManipulation::always_true< T >, "Cannot call toView on a rvalue." );
207-
return ParentClass::toView();
208-
}
204+
toView() const && = delete;
209205

210206
/**
211207
* @copydoc ParentClass::toViewConst
@@ -219,19 +215,15 @@ class ArrayOfSets : protected ArrayOfSetsView< T, INDEX_TYPE, BUFFER_TYPE >
219215
{ return ParentClass::toViewConst(); }
220216

221217
/**
222-
* @brief Overload for rvalues that raises a compilation error when used.
218+
* @brief Overload for rvalues that is deleted.
223219
* @return A null ArrayOfSetsView.
224220
* @note This cannot be called on a rvalue since the @c ArrayOfSetsView would
225221
* contain the buffers of the current @c ArrayOfSets that is about to be destroyed.
226222
* This overload prevents that from happening.
227223
*/
228224
constexpr inline
229225
ArrayOfSetsView< T const, INDEX_TYPE const, BUFFER_TYPE >
230-
toViewConst() const &&
231-
{
232-
static_assert( !typeManipulation::always_true< T >, "Cannot call toViewConst on a rvalue." );
233-
return ParentClass::toViewConst();
234-
}
226+
toViewConst() const && = delete;
235227

236228
/**
237229
* @copydoc ParentClass::toArrayOfArraysView
@@ -245,19 +237,15 @@ class ArrayOfSets : protected ArrayOfSetsView< T, INDEX_TYPE, BUFFER_TYPE >
245237
{ return ParentClass::toArrayOfArraysView(); }
246238

247239
/**
248-
* @brief Overload for rvalues that raises a compilation error when used.
240+
* @brief Overload for rvalues that is deleted.
249241
* @return A null ArrayOfSetsView.
250242
* @note This cannot be called on a rvalue since the @c ArrayOfArraysView would
251243
* contain the buffers of the current @c ArrayOfSets that is about to be destroyed.
252244
* This overload prevents that from happening.
253245
*/
254246
constexpr inline
255247
ArrayOfArraysView< T const, INDEX_TYPE const, true, BUFFER_TYPE >
256-
toArrayOfArraysView() const &&
257-
{
258-
static_assert( !typeManipulation::always_true< T >, "Cannot call toArrayOfArraysView on a rvalue." );
259-
return ParentClass::toArrayOfArraysView();
260-
}
248+
toArrayOfArraysView() const && = delete;
261249

262250
///@}
263251

src/ArrayView.hpp

Lines changed: 11 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -270,19 +270,15 @@ class ArrayView
270270
{ return ArraySlice< T, NDIM, USD, INDEX_TYPE >( data(), m_dims.data, m_strides.data ); }
271271

272272
/**
273-
* @brief Overload for rvalues that raises a compilation error when used.
273+
* @brief Overload for rvalues that is deleted.
274274
* @return A null ArraySlice.
275275
* @note This cannot be called on a rvalue since the @c ArraySlice would
276276
* contain pointers to the dims and strides of the current @c ArrayView that is
277277
* about to be destroyed. This overload prevents that from happening.
278278
*/
279279
inline LVARRAY_HOST_DEVICE constexpr
280280
ArraySlice< T, NDIM, USD, INDEX_TYPE >
281-
toSlice() const && noexcept
282-
{
283-
static_assert( !typeManipulation::always_true< T >, "Cannot call toSlice on a rvalue." );
284-
return ArraySlice< T, NDIM, USD, INDEX_TYPE >( nullptr, nullptr, nullptr );
285-
}
281+
toSlice() const && noexcept = delete;
286282

287283
/**
288284
* @return Return an immutable ArraySlice representing this ArrayView.
@@ -293,19 +289,15 @@ class ArrayView
293289
{ return ArraySlice< T const, NDIM, USD, INDEX_TYPE >( data(), m_dims.data, m_strides.data ); }
294290

295291
/**
296-
* @brief Overload for rvalues that raises a compilation error when used.
292+
* @brief Overload for rvalues that is deleted.
297293
* @return A null ArraySlice.
298294
* @brief This cannot be called on a rvalue since the @c ArraySlice would
299295
* contain pointers to the dims and strides of the current @c ArrayView that is
300296
* about to be destroyed. This overload prevents that from happening.
301297
*/
302298
inline LVARRAY_HOST_DEVICE constexpr
303299
ArraySlice< T const, NDIM, USD, INDEX_TYPE >
304-
toSliceConst() const && noexcept
305-
{
306-
static_assert( !typeManipulation::always_true< T >, "Cannot call toSliceConst on a rvalue." );
307-
return ArraySlice< T const, NDIM, USD, INDEX_TYPE >( nullptr, nullptr, nullptr );
308-
}
300+
toSliceConst() const && noexcept = delete;
309301

310302
/**
311303
* @brief A user defined conversion operator (UDC) to an ArrayView< T const, ... >.
@@ -314,26 +306,9 @@ class ArrayView
314306
template< typename _T=T >
315307
inline LVARRAY_HOST_DEVICE constexpr
316308
operator std::enable_if_t< !std::is_const< _T >::value,
317-
ArrayView< T const, NDIM, USD, INDEX_TYPE, BUFFER_TYPE > >() const & noexcept
309+
ArrayView< T const, NDIM, USD, INDEX_TYPE, BUFFER_TYPE > >() const noexcept
318310
{ return toViewConst(); }
319311

320-
/**
321-
* @brief Overload for rvalues that raises a compilation error when used.
322-
* @return A null ArrayView.
323-
* @brief This is valid when this is an @c ArrayView but invalid when this is an @c Array.
324-
* I have been unable to allow the @c ArrayView conversion while not allowing the @c Array.
325-
* Therefore the @c ArrayView conversion is not allowed, instead simply call @c toViewConst.
326-
*/
327-
template< typename _T=T >
328-
inline LVARRAY_HOST_DEVICE constexpr
329-
operator std::enable_if_t< !std::is_const< _T >::value,
330-
ArrayView< T const, NDIM, USD, INDEX_TYPE, BUFFER_TYPE > >() const && noexcept
331-
{
332-
static_assert( !typeManipulation::always_true< T >,
333-
"Cannot call toViewConst on a rvalue. If called from ArrayView please use toViewConst()." );
334-
return toViewConst();
335-
}
336-
337312
/**
338313
* @return Return an ArraySlice representing this ArrayView.
339314
*/
@@ -342,18 +317,14 @@ class ArrayView
342317
{ return toSlice(); }
343318

344319
/**
345-
* @brief Overload for rvalues that raises a compilation error when used.
320+
* @brief Overload for rvalues that is deleted.
346321
* @return A null ArraySlice.
347322
* @brief This conversion cannot be called on a rvalue since the @c ArraySlice would
348323
* contain pointers to the dims and strides of the current @c ArrayView that is
349324
* about to be destroyed. This overload prevents that from happening.
350325
*/
351326
inline LVARRAY_HOST_DEVICE constexpr
352-
operator ArraySlice< T, NDIM, USD, INDEX_TYPE >() const && noexcept
353-
{
354-
static_assert( !typeManipulation::always_true< T >, "Cannot use conversion to an ArraySlice< T, ... > on a rvalue." );
355-
return ArraySlice< T, NDIM, USD, INDEX_TYPE >( nullptr, nullptr, nullptr );
356-
}
327+
operator ArraySlice< T, NDIM, USD, INDEX_TYPE >() const && noexcept = delete;
357328

358329
/**
359330
* @return Return an immutable ArraySlice representing this ArrayView.
@@ -365,7 +336,7 @@ class ArrayView
365336
{ return toSliceConst(); }
366337

367338
/**
368-
* @brief Overload for rvalues that raises a compilation error when used.
339+
* @brief Overload for rvalues that is deleted.
369340
* @return A null ArraySlice.
370341
* @brief This conversion cannot be called on a rvalue since the @c ArraySlice would
371342
* contain pointers to the dims and strides of the current @c ArrayView that is
@@ -374,11 +345,7 @@ class ArrayView
374345
template< typename _T=T >
375346
inline LVARRAY_HOST_DEVICE constexpr
376347
operator std::enable_if_t< !std::is_const< _T >::value,
377-
ArraySlice< T const, NDIM, USD, INDEX_TYPE > const >() const && noexcept
378-
{
379-
static_assert( !typeManipulation::always_true< T >, "Cannot use conversion to an ArraySlice< T const, ... > on a rvalue." );
380-
return ArraySlice< T const, NDIM, USD, INDEX_TYPE >( nullptr, nullptr, nullptr );
381-
}
348+
ArraySlice< T const, NDIM, USD, INDEX_TYPE > const >() const && noexcept = delete;
382349

383350
///@}
384351

@@ -495,7 +462,7 @@ class ArrayView
495462
}
496463

497464
/**
498-
* @brief Overload for rvalues that raises a compilation error when used.
465+
* @brief Overload for rvalues that is deleted.
499466
* @param index Not used.
500467
* @return A null ArraySlice.
501468
* @brief The multidimensional operator[] cannot be called on a rvalue since the @c ArraySlice
@@ -505,12 +472,7 @@ class ArrayView
505472
template< int _NDIM=NDIM >
506473
LVARRAY_HOST_DEVICE inline CONSTEXPR_WITHOUT_BOUNDS_CHECK
507474
std::enable_if_t< (_NDIM > 1), ArraySlice< T, NDIM - 1, USD - 1, INDEX_TYPE > >
508-
operator[]( INDEX_TYPE const index ) const && noexcept
509-
{
510-
LVARRAY_UNUSED_VARIABLE( index );
511-
static_assert( !typeManipulation::always_true< T >, "Cannot call multidimensional operator[] on an rvalue." );
512-
return ArraySlice< T, NDIM-1, USD-1, INDEX_TYPE >( nullptr, nullptr, nullptr );
513-
}
475+
operator[]( INDEX_TYPE const index ) const && noexcept = delete;
514476

515477
/**
516478
* @return Return a reference to the value at the given index.

0 commit comments

Comments
 (0)