1

Since C++20, it seems that std::ranges:: is capable of almost everything std:: can do (looking at range algorithms).

Is it a good practice to just write namespace ranges = std::ranges; in the topmost header of one's project ?

For example, a namespace alias is already done for views:

namespace std {
    namespace views = ranges::views;
}

EDIT @StoryTeller - Unslander Monica: one single question

Barry
  • 286,269
  • 29
  • 621
  • 977
Cevik
  • 313
  • 1
  • 4
  • 17
  • Please only ask one question per-question. #3 is answered [here](https://stackoverflow.com/q/64518019/817643). #2 is because **all** the C++ standard library is in namespace std. The only exceptions are C legacy and macros. – StoryTeller - Unslander Monica Feb 17 '21 at 09:10

1 Answers1

1

We don't want to pollute the global space with a second namespace.

  1. When developing a library, you can do this inside your MyLib namespace so that there is no pollution => it is convenient because you can simply use ranges:: inside the MyLib scope, whatever the header or the source file.
  2. When developing a simple project, you can do this in a "define.hpp" file because it is up to you to decide what ranges:: means (the standard protects your right to alias it or not following if you already have a ranges class for example).

So yes, it is OK as long as you don't pollute one's people global scope with your API.

Cevik
  • 313
  • 1
  • 4
  • 17