Skip to content

Commit

Permalink
Potentially remove temporaries with std::optional
Browse files Browse the repository at this point in the history
  • Loading branch information
d-frey committed May 21, 2024
1 parent 65ad951 commit fd790c9
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions include/tao/pq/connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <functional>
#include <map>
#include <memory>
#include <optional>
#include <set>
#include <string>
#include <string_view>
Expand Down
2 changes: 1 addition & 1 deletion include/tao/pq/result.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ namespace tao::pq
if( empty() ) {
return std::nullopt;
}
return as< T >();
return std::optional< T >( as< T >() );
}

template< typename T, typename U >
Expand Down
4 changes: 2 additions & 2 deletions include/tao/pq/result_traits_optional.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ struct tao::pq::result_traits< std::optional< T > >

[[nodiscard]] static auto from( const char* value ) -> std::optional< T >
{
return result_traits< T >::from( value );
return std::optional< T >( result_traits< T >::from( value ) );
}

template< typename Row >
[[nodiscard]] static auto from( const Row& row ) -> std::optional< T >
{
for( std::size_t column = 0; column < row.columns(); ++column ) {
if( !row.is_null( column ) ) {
return result_traits< T >::from( row );
return std::optional< T >( result_traits< T >::from( row ) );
}
}
return null();
Expand Down

0 comments on commit fd790c9

Please sign in to comment.