Skip to content
Snippets Groups Projects
Commit b1cbee37 authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Add some inline, constexpr and noexcept attributes

parent 0684b39e
No related branches found
No related tags found
No related merge requests found
#ifndef ITEM_ID_HPP
#define ITEM_ID_HPP
#include <PastisMacros.hpp>
#include <ItemType.hpp>
template <ItemType item_type>
......@@ -13,39 +14,53 @@ class ItemIdT
base_type m_id;
public:
operator const base_type&() const
PASTIS_INLINE
constexpr operator const base_type&() const
{
return m_id;
}
ItemIdT operator++(int)
PASTIS_INLINE
constexpr ItemIdT operator++(int)
{
ItemIdT item_id(m_id);
++m_id;
return std::move(item_id);
}
ItemIdT& operator++()
PASTIS_INLINE
constexpr ItemIdT& operator++()
{
++m_id;
return *this;
}
ItemIdT& operator=(const base_type& id)
PASTIS_INLINE
constexpr ItemIdT& operator=(const base_type& id)
{
m_id = id;
return *this;
}
ItemIdT& operator=(const ItemIdT&) = default;
ItemIdT& operator=(ItemIdT&&) = default;
PASTIS_INLINE
constexpr ItemIdT& operator=(const ItemIdT&) = default;
ItemIdT(const base_type& id) : m_id{id}{}
PASTIS_INLINE
constexpr ItemIdT& operator=(ItemIdT&&) = default;
ItemIdT(const ItemIdT&) = default;
PASTIS_INLINE
constexpr ItemIdT(const base_type& id) : m_id{id}{}
ItemIdT(ItemIdT&&) = default;
ItemIdT() = default;
PASTIS_INLINE
constexpr ItemIdT(const ItemIdT&) = default;
PASTIS_INLINE
constexpr ItemIdT(ItemIdT&&) = default;
PASTIS_INLINE
constexpr ItemIdT() = default;
PASTIS_INLINE
~ItemIdT() = default;
// forbidden rules
......@@ -70,7 +85,6 @@ class ItemIdT
static_assert(other_item_type == item_type,
"wrong type of item");
}
};
using NodeId = ItemIdT<ItemType::node>;
......
......@@ -47,14 +47,14 @@ class ItemValue
// Following Kokkos logic, these classes are view and const view does allow
// changes in data
PASTIS_FORCEINLINE
DataType& operator[](const ItemId& i) const
DataType& operator[](const ItemId& i) const noexcept(NO_ASSERT)
{
Assert(m_is_built);
return m_values[i];
}
template <typename IndexType>
DataType& operator[](const IndexType& i) const
DataType& operator[](const IndexType& i) const noexcept(NO_ASSERT)
{
static_assert(std::is_same<IndexType,ItemId>(),
"ItemValue must be indexed by ItemId");
......
......@@ -179,7 +179,7 @@ class MeshData
const auto& face_nodes = face_to_node_matrix[l];
#warning should this lambda be replaced by a precomputed correspondance?
std::function local_node_number_in_cell
auto local_node_number_in_cell
= [&](const NodeId& node_number) {
for (size_t i_node=0; i_node<cell_nodes.size(); ++i_node) {
if (node_number == cell_nodes[i_node]) {
......
......@@ -58,14 +58,14 @@ class SubItemValuePerItem<DataType,
public:
PASTIS_INLINE
const DataType& operator[](const size_t& i) const
const DataType& operator[](const size_t& i) const noexcept(NO_ASSERT)
{
Assert(i<m_size);
return m_sub_values[i];
}
PASTIS_FORCEINLINE
DataType& operator[](const size_t& i)
DataType& operator[](const size_t& i) noexcept(NO_ASSERT)
{
Assert(i<m_size);
return m_sub_values[i];
......@@ -85,7 +85,7 @@ class SubItemValuePerItem<DataType,
PASTIS_INLINE
SubView(const Array<DataType>& values,
const size_t& begin,
const size_t& end)
const size_t& end) noexcept(NO_ASSERT)
: m_sub_values(&(values[begin])),
m_size(end-begin)
{
......@@ -103,7 +103,7 @@ class SubItemValuePerItem<DataType,
// Following Kokkos logic, these classes are view and const view does allow
// changes in data
PASTIS_FORCEINLINE
DataType& operator()(const ItemId& j, const size_t& r) const
DataType& operator()(const ItemId& j, const size_t& r) const noexcept(NO_ASSERT)
{
Assert(m_is_built);
return m_values[m_host_row_map(size_t{j})+r];
......@@ -111,7 +111,7 @@ class SubItemValuePerItem<DataType,
template <typename IndexType>
PASTIS_FORCEINLINE
DataType& operator()(const IndexType& j, const size_t& r) const
DataType& operator()(const IndexType& j, const size_t& r) const noexcept(NO_ASSERT)
{
static_assert(std::is_same<IndexType, size_t>(),
"SubItemValuePerItem indexed by ItemId");
......@@ -119,7 +119,7 @@ class SubItemValuePerItem<DataType,
}
PASTIS_INLINE
size_t numberOfValues() const
size_t numberOfValues() const noexcept(NO_ASSERT)
{
Assert(m_is_built);
return m_values.size();
......@@ -128,14 +128,14 @@ class SubItemValuePerItem<DataType,
// Following Kokkos logic, these classes are view and const view does allow
// changes in data
PASTIS_FORCEINLINE
DataType& operator[](const size_t& i) const
DataType& operator[](const size_t& i) const noexcept(NO_ASSERT)
{
Assert(m_is_built);
return m_values[i];
}
template <typename IndexType>
DataType& operator[](const IndexType& i) const
DataType& operator[](const IndexType& i) const noexcept(NO_ASSERT)
{
static_assert(std::is_same<IndexType, size_t>(),
"Access to SubItemValuePerItem's array must be indexed by size_t");
......@@ -143,7 +143,7 @@ class SubItemValuePerItem<DataType,
}
PASTIS_INLINE
size_t numberOfItems() const
size_t numberOfItems() const noexcept(NO_ASSERT)
{
Assert(m_is_built);
Assert(m_host_row_map.extent(0) != 0);
......@@ -151,14 +151,14 @@ class SubItemValuePerItem<DataType,
}
PASTIS_INLINE
size_t numberOfSubValues(const size_t& i_cell) const
size_t numberOfSubValues(const size_t& i_cell) const noexcept(NO_ASSERT)
{
Assert(m_is_built);
return m_host_row_map(i_cell+1)-m_host_row_map(i_cell);
}
PASTIS_INLINE
SubView itemValues(const size_t& i_cell)
SubView itemValues(const size_t& i_cell) noexcept(NO_ASSERT)
{
Assert(m_is_built);
const auto& cell_begin = m_host_row_map(i_cell);
......@@ -169,7 +169,7 @@ class SubItemValuePerItem<DataType,
// Following Kokkos logic, these classes are view and const view does allow
// changes in data
PASTIS_INLINE
SubView itemValues(const size_t& i_cell) const
SubView itemValues(const size_t& i_cell) const noexcept(NO_ASSERT)
{
Assert(m_is_built);
const auto& cell_begin = m_host_row_map(i_cell);
......
......@@ -21,13 +21,13 @@ class Array
public:
PASTIS_INLINE
size_t size() const
size_t size() const noexcept
{
return m_values.extent(0);
}
PASTIS_INLINE
DataType& operator[](const index_type& i) const
DataType& operator[](const index_type& i) const noexcept(NO_ASSERT)
{
Assert(i<m_values.extent(0));
return m_values[i];
......@@ -43,7 +43,7 @@ class Array
template <typename DataType2>
PASTIS_INLINE
Array& operator=(const Array<DataType2>& array)
Array& operator=(const Array<DataType2>& array) noexcept
{
// ensures that DataType is the same as source DataType2
static_assert(std::is_same<std::remove_const_t<DataType>, std::remove_const_t<DataType2>>(),
......@@ -67,7 +67,7 @@ class Array
template <typename DataType2>
PASTIS_INLINE
Array(const Array<DataType2>& array)
Array(const Array<DataType2>& array) noexcept
{
this->operator=(array);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment