Skip to content

Instantly share code, notes, and snippets.

@roshanr95
Created October 9, 2019 04:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roshanr95/d73b15566e2da1702c21258fc2f0ac10 to your computer and use it in GitHub Desktop.
Save roshanr95/d73b15566e2da1702c21258fc2f0ac10 to your computer and use it in GitHub Desktop.
A small snippet with cppcheck FP
template<class... Args>
std::pair<TransportType *, bool> get_or_create(
SocketAddress const &addr,
Args&&... args
) {
auto [iter, res] = transport_map.try_emplace(
addr,
std::forward<Args>(args)...
);
return std::make_pair(&iter->second, res);
}
@roshanr95
Copy link
Author

Here's the diagnostic from cppcheck:

File.hpp:32:20: style: Variable 'transport_map.try_emplace' is reassigned a value before the old one has been used. [redundantAssignment]
  auto [iter, res] = transport_map.try_emplace(
                   ^
File.hpp:32:20: note: Variable 'transport_map.try_emplace' is reassigned a value before the old one has been used.
  auto [iter, res] = transport_map.try_emplace(
                   ^
File.hpp:32:20: note: Variable 'transport_map.try_emplace' is reassigned a value before the old one has been used.
  auto [iter, res] = transport_map.try_emplace(
                   ^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment