Skip to content

Commit

Permalink
Clang-format lambdas better
Browse files Browse the repository at this point in the history
  • Loading branch information
mikir committed Sep 3, 2024
1 parent ffbf608 commit 3e768cf
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ AllowShortEnumsOnASingleLine: false
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortLambdasOnASingleLine: All
AllowShortLambdasOnASingleLine: false
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
Expand Down
14 changes: 7 additions & 7 deletions runtime/src/zserio/HashCodeUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@ inline typename std::enable_if<std::is_enum<ENUM_TYPE>::value, uint32_t>::type c
}

/**
* Calculates hash code of the given Zserio object (structure, choice, ...) using the given seed value.
*
* \param seedValue Seed value (current hash code).
* \param object Object for which to calculate the hash code.
*
* \return Calculated hash code.
*/
* Calculates hash code of the given Zserio object (structure, choice, ...) using the given seed value.
*
* \param seedValue Seed value (current hash code).
* \param object Object for which to calculate the hash code.
*
* \return Calculated hash code.
*/
template <typename OBJECT>
inline typename std::enable_if<!std::is_enum<OBJECT>::value && !std::is_integral<OBJECT>::value, uint32_t>::type
calcHashCode(uint32_t seedValue, const OBJECT& object)
Expand Down
8 changes: 3 additions & 5 deletions runtime/src/zserio/Variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -688,11 +688,9 @@ uint32_t calcHashCode(uint32_t seed, const BasicVariant<ALLOC, INDEX, T...>& var
{
uint32_t result = seed;
result = zserio::calcHashCode(result, static_cast<size_t>(var.index()));
var.visit(
[&result](const auto& value)
{
result = zserio::calcHashCode(result, value);
});
var.visit([&result](const auto& value) {
result = zserio::calcHashCode(result, value);
});
return result;
}

Expand Down
34 changes: 15 additions & 19 deletions runtime/test/zserio/VariantTest.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include <algorithm>
#include <utility>

#include "gtest/gtest.h"
#include "zserio/HashCodeUtil.h"
#include "zserio/TrackingAllocator.h"
#include "zserio/Variant.h"
#include <utility>

// helper type for the visitor
template <class... Ts>
Expand Down Expand Up @@ -225,28 +225,23 @@ TYPED_TEST(VariantTest, visit)
Variant1 var;
var.emplace<Idx1::B>("something");

var.visit(
[](auto&& val)
{
using T = std::decay_t<decltype(val)>;
ASSERT_TRUE((std::is_same_v<T, std::string>));
});
var.visit([](auto&& val) {
using T = std::decay_t<decltype(val)>;
ASSERT_TRUE((std::is_same_v<T, std::string>));
});

var.visit(overloaded{[](std::string& i)
{
SUCCEED();
},
[](auto&&)
{
var.visit(overloaded{[](std::string& i) {
SUCCEED();
},
[](auto&&) {
FAIL();
}});

int ret = var.visit(overloaded{[](std::string& i)
{
int ret = var.visit(overloaded{
[](std::string& i) {
return 1;
},
[](auto&&)
{
[](auto&&) {
return 0;
}});
ASSERT_EQ(ret, 1);
Expand Down Expand Up @@ -302,9 +297,10 @@ namespace std
template <>
struct hash<zserio::BigObj>
{
size_t operator()(const zserio::BigObj& ) const {
size_t operator()(const zserio::BigObj&) const
{
return 0;
}
};

}
} // namespace std

0 comments on commit 3e768cf

Please sign in to comment.