Skip to content

Conversation

@cjbacchus
Copy link

No description provided.

**[F]** `using` directives are nevertheless always thoroughly
**forbidden** in global scope of header files.
Instead, importing specific symbols at local scope should be preferred
You may import specific symbols at local scope (i.e. within the body of your `class`) if absolutely necessary for readability
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
Instead, importing specific symbols at local scope should be preferred
You may import specific symbols at local scope (i.e. within the body of your `class`) if absolutely necessary for readability
You may import specific symbols at local scope (i.e. within the body of your `class`)
if absolutely necessary for readability (`using Iterator_t = std::vector<std::vector<std::pair<int, int>>>::const_iterator;`) or for functionality

(the using std::begin; example makes the difference in template code like:

template <typename Coll>
auto const& firstElement(Coll const& coll) {
  using std::empty, std::begin;
  return empty(coll)? typename Coll::value_type{}: *(begin(coll));
}

Copy link
Author

@cjbacchus cjbacchus Sep 23, 2021

Choose a reason for hiding this comment

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

I'm not sure I understand the example. Does return std::empty(coll) ? typename Coll::value_type{} : *std::begin(coll); not work?

Copy link
Owner

Choose a reason for hiding this comment

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

If you are using a Coll that does not have a begin() method (e.g. because it's a C data structure or as it was in the past TCollection from ROOT, or maybe it's like std::filesystem::directory_iterator), the portal to STL is to have a free function begin(Coll const&) (and friends), ideally in the same namespace as Coll (alternatively, at global scope). So, we may implement begin(linked_list*) and begin(TCollection const&) ourselves and welcome there in STL world.
std::begin() would not find that function, but it covers the cases where that function is not available.

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