Skip to content
Snippets Groups Projects
Commit 3fded4c2 authored by Jan Trávníček's avatar Jan Trávníček
Browse files

clang-tidy: simplify code to fix possible unintended move of lvalue reference

methods ext::Variant < ... >::set are joined + refactored to fix the std::move
vs std::forward issue
parent de9f5f7e
No related branches found
No related tags found
1 merge request!172Clang tidy fixes merge
......@@ -226,22 +226,10 @@ public:
*
* \param value the new value to assign to the variant
*/
template < ext::Included < Ts ... > T >
template < typename T >
requires ( ext::Included < std::decay_t < T >, Ts ... > )
void set ( T && value ) {
* this = std::move ( value );
}
/**
* \brief
* Allows to assign a value to the variant.
*
* \tparam T the type of the value to assign
*
* \param value the new value to assign to the variant
*/
template < ext::Included < Ts ... > T >
void set ( const T & value ) {
* this = value;
* this = std::forward < T > ( value );
}
 
/**
......
......@@ -118,11 +118,11 @@ TEST_CASE ( "Variant", "[unit][std][container]" ) {
CHECK_EXCLUSIVE_OR( d < std::string("a"), d > std::string("a") );
 
std::string str = "abcde";
d.set<std::string>(str);
d.set(str);
CHECK( d.is<std::string>() );
CHECK( d.get<std::string>() == str );
 
d.set<test>(test());
d.set(test());
*(d.get<test>().holder) = 42;
 
test tmp;
......@@ -229,10 +229,10 @@ TEST_CASE ( "Variant", "[unit][std][container]" ) {
ext::variant < int, int, char > v1 ( 1 );
CHECK ( v1.get < int > ( ) == 1 );
 
v1.set < char > ( 'a' );
v1.set ( 'a' );
CHECK ( v1.get < char > ( ) == 'a' );
 
v1.set < int > ( 'a' );
v1.set ( (int) 'a' );
CHECK ( v1.is < int > ( ) );
 
std::cout << v1 << std::endl;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment