Skip to content

Commit b94e1ee

Browse files
Merge pull request #1178 from arcaneframework/dev/gg-add-constructor-for-memoryview
Add constructor to 'ConstMemoryView' from 'ArrayView'
2 parents b192966 + 7bb5c19 commit b94e1ee

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

arcane/src/arcane/utils/MemoryView.h

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
22
//-----------------------------------------------------------------------------
3-
// Copyright 2000-2022 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
3+
// Copyright 2000-2024 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
44
// See the top-level COPYRIGHT file for details.
55
// SPDX-License-Identifier: Apache-2.0
66
//-----------------------------------------------------------------------------
77
/*---------------------------------------------------------------------------*/
8-
/* MemoryView.h (C) 2000-2023 */
8+
/* MemoryView.h (C) 2000-2024 */
99
/* */
1010
/* Vues constantes ou modifiables sur une zone mémoire. */
1111
/*---------------------------------------------------------------------------*/
@@ -61,9 +61,15 @@ class ARCANE_UTILS_EXPORT ConstMemoryView
6161
template <typename DataType> explicit constexpr ConstMemoryView(ConstArrayView<DataType> v)
6262
: ConstMemoryView(Span<const DataType>(v), 1)
6363
{}
64+
template <typename DataType> explicit constexpr ConstMemoryView(ArrayView<DataType> v)
65+
: ConstMemoryView(Span<const DataType>(v), 1)
66+
{}
6467
template <typename DataType> constexpr ConstMemoryView(ConstArrayView<DataType> v, Int32 nb_component)
6568
: ConstMemoryView(Span<const DataType>(v), nb_component)
6669
{}
70+
template <typename DataType> constexpr ConstMemoryView(ArrayView<DataType> v, Int32 nb_component)
71+
: ConstMemoryView(Span<const DataType>(v), nb_component)
72+
{}
6773
template <typename DataType> constexpr ConstMemoryView(Span<DataType> v, Int32 nb_component)
6874
: ConstMemoryView(Span<const DataType>(v), nb_component)
6975
{

arcane/src/arcane/utils/tests/TestMemory.cc

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
22
//-----------------------------------------------------------------------------
3-
// Copyright 2000-2023 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
3+
// Copyright 2000-2024 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
44
// See the top-level COPYRIGHT file for details.
55
// SPDX-License-Identifier: Apache-2.0
66
//-----------------------------------------------------------------------------
@@ -124,6 +124,10 @@ class MemoryTester
124124
ConstMemoryView from(array1.span());
125125
to.copyFromIndexesHost(from, copy_indexes);
126126
ASSERT_EQ(array2, array3);
127+
ConstMemoryView view2(array1.view());
128+
ASSERT_EQ(view2.bytes(),asBytes(array1));
129+
ConstMemoryView view3(array1.view(),1);
130+
ASSERT_EQ(view3.bytes(),asBytes(array1));
127131
}
128132

129133
// Teste MutableMemoryView::copyToIndexesHost()

0 commit comments

Comments
 (0)