Prefer .at over checking size and throwing

Seems to be slightly faster and is much simpler.
This commit is contained in:
Jørgen Kvalsvik
2016-08-05 15:57:44 +02:00
parent 0650996655
commit 9966e3fbfd
2 changed files with 3 additions and 10 deletions

View File

@@ -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 >

View File

@@ -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) {