Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing include in baldr/admin.h #4766

Merged
merged 3 commits into from
Jun 14, 2024
Merged

Conversation

chrstnbwnkl
Copy link
Contributor

@chrstnbwnkl chrstnbwnkl commented Jun 14, 2024

Issue

I've been starting to get compilation errors recently due the use of std::find() in baldr/admin.cc, apparently caused by a missing include:

[build] /home/chris/dev/github/valhalla/src/baldr/admin.cc: In member function ‘std::string valhalla::baldr::Admin::state_iso() const’:
[build] /home/chris/dev/github/valhalla/src/baldr/admin.cc:109:57: error: no matching function for call to ‘find(std::array<char, 3>::const_iterator, std::array<char, 3>::const_iterator, char)’
[build]   109 |              : std::string(state_iso_.begin(), std::find(state_iso_.begin(), state_iso_.end(), '\0'));
[build]       |                                                ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Not sure what's the root cause, but seems like Valhalla was just relying on it being included elsewhere?

Tasklist

@kevinkreiser
Copy link
Member

youre exactly right. what happens is compilers come with their own implementations of the standard library. what then happens is you use one of the headers, lets say vector, and in your compilers version of the standard library they happened to also include algorithm because one of the vector functions needed it or it was convenient. you throw in a call to std::find and it works because you were inadvertantly relying on that include you didnt know about. time passes and a new compiler release happens or you take your code to another platform with a different compiler and now your code doesnt work because vector on that platform isnt also giving access to algorithm.

what we should do but havent done is strictly follow the "include what you use" idiom. itd be a nice cleanup to run some toolign to detect this stuff but it might be a bit of a long and winding road. anyway easily fixed as you noticed.

@@ -1,6 +1,7 @@
#ifndef VALHALLA_BALDR_ADMIN_H_
#define VALHALLA_BALDR_ADMIN_H_

#include <algorithm>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we only need access to this in admin.cc then put the include there. better to keep our headers as slim as possible so that people using our headers dont get more stuff than they need (not that it bloats their binaries but just because we should advertize only what we need to, ie only what is used directly in this header file)

@chrstnbwnkl
Copy link
Contributor Author

aw no, does that failing filesystem test ring a bell @kevinkreiser ? Seems unrelated, but I can't seem to be able to trigger a rerun since it's on circleCI

@nilsnolde
Copy link
Member

wtf haha never seen this. must be a glitch on the circleci machine. not sure how circleci works these days. back when I registered, I did so through github and it was "just working" bcs I think it checked my permissions to this repo (were the same as yours today). when you sign up with circleci, does it ask for your github access? I know they're being google'y-evil about it requesting wayyy too much info, but 🤷

@kevinkreiser kevinkreiser merged commit 950b4c4 into master Jun 14, 2024
6 of 7 checks passed
@kevinkreiser kevinkreiser deleted the cb-missing-algorithm-header branch June 14, 2024 14:12
@kevinkreiser
Copy link
Member

meh who cares about stupid CI messing with us

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants