-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cpp: use references for non-trivial types in accessors
The generated accessors used by-value return and parameter types even for non-trivial types. This change is intended to improve the situation by introducing usage of reference for the mentioned non-trivial types. This change: - introduces usage of const references for non-trivial types in getters defined via accessors attribute for structures when it is called on l-value - introduces usage of by-value type for non-trivial types in getters defined via accessors attribute for structures when it is called on r-value - introduces usage of const references for non-trivial types in setters - strips constness and references from type used to select a hash in 'StructHashImpl.mustache' because std::hash<T> does not accept references/constness for T - updates output of smoke tests to show, that since this commit the generated accessors use const references for non-trivial types Signed-off-by: Patryk Wrobel <[email protected]>
- Loading branch information
1 parent
51a9c4b
commit f914c76
Showing
5 changed files
with
40 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 11 additions & 1 deletion
12
.../src/test/resources/smoke/equatable/output/cpp/src/smoke/EquatableStructWithAccessors.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,43 @@ | ||
// ------------------------------------------------------------------------------------------------- | ||
// | ||
|
||
// | ||
// ------------------------------------------------------------------------------------------------- | ||
|
||
#include "smoke/EquatableStructWithAccessors.h" | ||
#include <utility> | ||
|
||
namespace smoke { | ||
|
||
EquatableStructWithAccessors::EquatableStructWithAccessors( ) | ||
: foo_field{ } | ||
{ | ||
} | ||
|
||
EquatableStructWithAccessors::EquatableStructWithAccessors( ::std::string foo_field ) | ||
: foo_field( std::move( foo_field ) ) | ||
{ | ||
} | ||
|
||
bool EquatableStructWithAccessors::operator==( const EquatableStructWithAccessors& rhs ) const | ||
{ | ||
return foo_field == rhs.foo_field; | ||
} | ||
|
||
bool EquatableStructWithAccessors::operator!=( const EquatableStructWithAccessors& rhs ) const | ||
{ | ||
return !( *this == rhs ); | ||
} | ||
|
||
|
||
} | ||
|
||
namespace gluecodium { | ||
std::size_t | ||
hash< ::smoke::EquatableStructWithAccessors >::operator( )( const ::smoke::EquatableStructWithAccessors& t ) const | ||
{ | ||
size_t hash_value = 43; | ||
hash_value = (hash_value ^ ::gluecodium::hash< decltype(std::declval<::smoke::EquatableStructWithAccessors>().get_foo_field()) >()(t.get_foo_field())) << 1; | ||
hash_value = (hash_value ^ ::gluecodium::hash< std::remove_cv_t< std::remove_reference_t< decltype(std::declval<::smoke::EquatableStructWithAccessors>().get_foo_field()) > > >()(t.get_foo_field())) << 1; | ||
return hash_value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters