Prefer .at over checking size and throwing
Seems to be slightly faster and is much simpler.
This commit is contained in:
@@ -141,11 +141,7 @@ namespace Opm {
|
||||
|
||||
template< typename T >
|
||||
T GridProperty< T >::iget( size_t index ) const {
|
||||
if (index < m_data.size()) {
|
||||
return m_data[index];
|
||||
} else {
|
||||
throw std::invalid_argument("Index out of range \n");
|
||||
}
|
||||
return this->m_data.at( index );
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
@@ -156,10 +152,7 @@ namespace Opm {
|
||||
|
||||
template< typename T >
|
||||
void GridProperty< T >::iset(size_t index, T value) {
|
||||
if (index < m_data.size())
|
||||
m_data[index] = value;
|
||||
else
|
||||
throw std::invalid_argument("Index out of range \n");
|
||||
this->m_data.at( index ) = value;
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
|
||||
@@ -290,7 +290,7 @@ BOOST_AUTO_TEST_CASE(GetProperty) {
|
||||
for (size_t i=0; i < satNUM.getCartesianSize(); i++)
|
||||
BOOST_CHECK_EQUAL( 2 , satNUM.iget(i) );
|
||||
|
||||
BOOST_CHECK_THROW( satNUM.iget(100000) , std::invalid_argument);
|
||||
BOOST_CHECK_THROW( satNUM.iget(100000) , std::out_of_range );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(GetTransMult) {
|
||||
|
||||
Reference in New Issue
Block a user