Skip to content

Commit 8e4e00a

Browse files
authored
Merge pull request #276 from LLNL/feature/nselliott/constexpr-updates
Add constexpr to some simple types
2 parents c888a99 + fcf82ab commit 8e4e00a

18 files changed

+257
-397
lines changed

.gitlab/jobs/tioga.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ release_resources:
4040
####
4141
# Build and test jobs for specific compilers, extends generic tioga build and
4242
# test job
43-
cce_16_0_0_rocm_5_6_0:
43+
amdclang_rocm_6.0.2:
4444
variables:
45-
COMPILER: "cce-16.0.0-rocm-5.6.0"
45+
COMPILER: "amdclang-rocm-6.0.2-gfx90a"
4646
extends: .job_on_tioga

source/SAMRAI/hier/BlockId.cpp

Lines changed: 2 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -16,61 +16,9 @@
1616
namespace SAMRAI {
1717
namespace hier {
1818

19-
const BlockId
20-
BlockId::s_invalid_id(
21-
tbox::MathUtilities<int>::getMax());
22-
const BlockId BlockId::s_zero_id(0);
19+
const BlockId BlockId::s_invalid_id(s_invalid_val);
20+
const BlockId BlockId::s_zero_id(s_zero_val);
2321

24-
/*
25-
*******************************************************************************
26-
*******************************************************************************
27-
*/
28-
BlockId::BlockId():
29-
d_value(invalidId().d_value)
30-
{
31-
}
32-
33-
/*
34-
*******************************************************************************
35-
*******************************************************************************
36-
*/
37-
BlockId::BlockId(
38-
const BlockId& other):
39-
d_value(other.d_value)
40-
{
41-
}
42-
43-
/*
44-
*******************************************************************************
45-
*******************************************************************************
46-
*/
47-
BlockId::BlockId(
48-
const unsigned int& value):
49-
d_value(value)
50-
{
51-
}
52-
53-
/*
54-
*******************************************************************************
55-
*******************************************************************************
56-
*/
57-
BlockId::BlockId(
58-
const int& value):
59-
d_value(static_cast<unsigned int>(value))
60-
{
61-
TBOX_ASSERT(value >=0);
62-
}
63-
64-
/*
65-
*******************************************************************************
66-
*******************************************************************************
67-
*/
68-
BlockId::~BlockId()
69-
{
70-
#ifdef DEBUG_CHECK_ASSERTIONS
71-
d_value = s_invalid_id.d_value;
72-
#endif
73-
}
7422

7523
}
7624
}

source/SAMRAI/hier/BlockId.h

Lines changed: 43 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#define included_hier_BlockId
1313

1414
#include "SAMRAI/SAMRAI_config.h"
15+
#include "SAMRAI/tbox/MathUtilities.h"
1516
#include "SAMRAI/tbox/Utilities.h"
1617

1718
#include <iostream>
@@ -36,21 +37,27 @@ class BlockId
3637
/*!
3738
* @brief Default constructor sets the value to invalid.
3839
*/
39-
BlockId();
40+
constexpr BlockId() :
41+
d_value(s_invalid_val)
42+
{
43+
}
4044

4145
/*!
4246
* @brief Copy constructor.
4347
*/
44-
BlockId(
45-
const BlockId& other);
48+
constexpr BlockId(
49+
const BlockId& other) = default;
4650

4751
/*!
4852
* @brief Construct from an unsigned int.
4953
*
5054
* This method is explicit to prevent automatic conversion.
5155
*/
52-
explicit BlockId(
53-
const unsigned int& value);
56+
constexpr explicit BlockId(
57+
const unsigned int& value) :
58+
d_value(value)
59+
{
60+
}
5461

5562
/*!
5663
* @brief Construct from a signed int.
@@ -59,13 +66,17 @@ class BlockId
5966
*
6067
* @pre value >= 0
6168
*/
62-
explicit BlockId(
63-
const int& value);
69+
constexpr explicit BlockId(
70+
const int& value) :
71+
d_value(static_cast<unsigned int>(value))
72+
{
73+
TBOX_CONSTEXPR_ASSERT(value >=0);
74+
}
6475

6576
/*!
6677
* @brief Default constructor.
6778
*/
68-
~BlockId();
79+
~BlockId() = default;
6980

7081
/*!
7182
* @brief Assignment operator.
@@ -74,28 +85,24 @@ class BlockId
7485
*
7586
* @return @c *this
7687
*/
77-
BlockId&
88+
constexpr BlockId&
7889
operator = (
79-
const BlockId& rhs)
80-
{
81-
d_value = rhs.d_value;
82-
return *this;
83-
}
90+
const BlockId& rhs) = default;
8491

8592
/*!
8693
* @brief Set to an int value.
8794
*
8895
* @param[in] rhs
8996
*/
90-
void
97+
constexpr void
9198
setId(
9299
const int& rhs)
93100
{
94-
TBOX_ASSERT(rhs >= 0);
101+
TBOX_CONSTEXPR_ASSERT(rhs >= 0);
95102
d_value = static_cast<block_t>(rhs);
96103
}
97104

98-
void
105+
constexpr void
99106
setId(
100107
const unsigned int& rhs)
101108
{
@@ -105,16 +112,16 @@ class BlockId
105112
/*!
106113
* @brief Whether the value is valid.
107114
*/
108-
bool
115+
constexpr bool
109116
isValid() const
110117
{
111-
return d_value != s_invalid_id.d_value;
118+
return d_value != s_invalid_val;
112119
}
113120

114121
/*!
115122
* @brief Access the numerical value.
116123
*/
117-
const block_t&
124+
constexpr const block_t&
118125
getBlockValue() const
119126
{
120127
return d_value;
@@ -149,7 +156,7 @@ class BlockId
149156
*
150157
* @param[in] rhs
151158
*/
152-
bool
159+
constexpr bool
153160
operator == (
154161
const BlockId& rhs) const
155162
{
@@ -163,7 +170,7 @@ class BlockId
163170
*
164171
* @param[in] rhs
165172
*/
166-
bool
173+
constexpr bool
167174
operator != (
168175
const BlockId& rhs) const
169176
{
@@ -177,7 +184,7 @@ class BlockId
177184
*
178185
* @param[in] rhs
179186
*/
180-
bool
187+
constexpr bool
181188
operator < (
182189
const BlockId& rhs) const
183190
{
@@ -191,7 +198,7 @@ class BlockId
191198
*
192199
* @param[in] rhs
193200
*/
194-
bool
201+
constexpr bool
195202
operator > (
196203
const BlockId& rhs) const
197204
{
@@ -205,7 +212,7 @@ class BlockId
205212
*
206213
* @param[in] rhs
207214
*/
208-
bool
215+
constexpr bool
209216
operator <= (
210217
const BlockId& rhs) const
211218
{
@@ -219,7 +226,7 @@ class BlockId
219226
*
220227
* @param[in] rhs
221228
*/
222-
bool
229+
constexpr bool
223230
operator >= (
224231
const BlockId& rhs) const
225232
{
@@ -239,7 +246,7 @@ class BlockId
239246
*
240247
* @param[in] rhs
241248
*/
242-
bool
249+
constexpr bool
243250
operator == (
244251
const block_t& rhs) const
245252
{
@@ -253,7 +260,7 @@ class BlockId
253260
*
254261
* @param[in] rhs
255262
*/
256-
bool
263+
constexpr bool
257264
operator != (
258265
const block_t& rhs) const
259266
{
@@ -267,7 +274,7 @@ class BlockId
267274
*
268275
* @param[in] rhs
269276
*/
270-
bool
277+
constexpr bool
271278
operator < (
272279
const block_t& rhs) const
273280
{
@@ -281,7 +288,7 @@ class BlockId
281288
*
282289
* @param[in] rhs
283290
*/
284-
bool
291+
constexpr bool
285292
operator > (
286293
const block_t& rhs) const
287294
{
@@ -295,7 +302,7 @@ class BlockId
295302
*
296303
* @param[in] rhs
297304
*/
298-
bool
305+
constexpr bool
299306
operator <= (
300307
const block_t& rhs) const
301308
{
@@ -309,7 +316,7 @@ class BlockId
309316
*
310317
* @param[in] rhs
311318
*/
312-
bool
319+
constexpr bool
313320
operator >= (
314321
const block_t& rhs) const
315322
{
@@ -336,6 +343,10 @@ class BlockId
336343
*/
337344
unsigned int d_value;
338345

346+
static constexpr unsigned int s_zero_val = 0;
347+
static constexpr unsigned int s_invalid_val =
348+
tbox::MathUtilities<int>::getMax();
349+
339350
/*!
340351
* @brief BlockId with a numerical value of zero.
341352
*/

source/SAMRAI/hier/BoxId.cpp

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -14,53 +14,6 @@
1414
namespace SAMRAI {
1515
namespace hier {
1616

17-
/*
18-
************************************************************************
19-
* Constructors
20-
************************************************************************
21-
*/
22-
BoxId::BoxId():
23-
d_global_id(),
24-
d_periodic_id()
25-
{
26-
}
27-
28-
BoxId::BoxId(
29-
const GlobalId& id,
30-
const PeriodicId& periodic_id):
31-
d_global_id(id),
32-
d_periodic_id(periodic_id)
33-
{
34-
TBOX_ASSERT(periodic_id.isValid());
35-
}
36-
37-
BoxId::BoxId(
38-
const LocalId& local_id,
39-
const int owner,
40-
const PeriodicId& periodic_id):
41-
d_global_id(local_id, owner),
42-
d_periodic_id(periodic_id)
43-
{
44-
TBOX_ASSERT(periodic_id.isValid());
45-
}
46-
47-
BoxId::BoxId(
48-
const BoxId& r):
49-
d_global_id(r.d_global_id),
50-
d_periodic_id(r.d_periodic_id)
51-
{
52-
TBOX_ASSERT(r.d_periodic_id.isValid());
53-
}
54-
55-
/*
56-
************************************************************************
57-
* Destructor
58-
************************************************************************
59-
*/
60-
BoxId::~BoxId()
61-
{
62-
}
63-
6417
/*
6518
******************************************************************************
6619
* Stream-insert operator.

0 commit comments

Comments
 (0)