Skip to content

Remove #include <vector> usages#996

Closed
Lestropie wants to merge 1 commit intomasterfrom
no_include_stl_vector
Closed

Remove #include <vector> usages#996
Lestropie wants to merge 1 commit intomasterfrom
no_include_stl_vector

Conversation

@Lestropie
Copy link
Copy Markdown
Member

Seeing da512aa pop up made me think to check for this.

No idea if it'll have any effect, but maybe there's an outside chance that if nothing has #include <vector> in it, trying to use a std::vector will cause a compiler error; or maybe one will be able to use vector rather than having to resort to MR::vector.

This header should no longer be included directly, since class MR::vector (defined in core/types.h) should always be used.
@jdtournier
Copy link
Copy Markdown
Member

maybe there's an outside chance that if nothing has #include in it, trying to use a std::vector will cause a compiler error;

it won't, since our MR::vector class derives from std::vector directly, so <vector> will always be included anyway...

maybe one will be able to use vector rather than having to resort to MR::vector.

You already can, these latest commits are probably overly cautious - it should work with just vector<type> already, and you'll find plenty of examples of that elsewhere in the code. As long as there is no using namespace std; anywhere, there shouldn't be any confusion possible. I might remove these MR:: prefixes if they're going to cause confusion...

@jdtournier
Copy link
Copy Markdown
Member

@Lestropie, I've merged this commit into #961 - I assume you're OK with that...

@jdtournier jdtournier closed this May 23, 2017
@jdtournier jdtournier deleted the no_include_stl_vector branch May 23, 2017 13:33
@Lestropie
Copy link
Copy Markdown
Member Author

You already can, these latest commits are probably overly cautious - it should work with just vector already, and you'll find plenty of examples of that elsewhere in the code. As long as there is no using namespace std; anywhere, there shouldn't be any confusion possible. I might remove these MR:: prefixes if they're going to cause confusion...

Cool, I had assumed that the explicit MR::vector namespace addition was necessary for whatever reason in that context. If it's just left over from bug hunting, probably removing them is the best bet.

The using namespace std; point is a good one though; check_memalign currently won't catch that (ideally it'd flag the presence of using namespace std; then check for corresponding vector<> usage rather than MR::vector<> in that file).

I assume you're OK with that...

👍

@jdtournier
Copy link
Copy Markdown
Member

The using namespace std; point is a good one though; check_memalign currently won't catch that (ideally it'd flag the presence of using namespace std; then check for corresponding vector<> usage rather than MR::vector<> in that file).

Yes, that check is really just a safeguard. To be bullet-proof would require essentially catching the fully-parsed output of the compiler... Not something we can possibly hope to achieve. We could simply catch any use of using namespace std; and fail outright though, I think it's fair to say that this is not encouraged within the codebase for basically this reason...

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.

2 participants