添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

std::begin and std::end usage without specifying std namespace #2359

@themarpe

Description

What is the issue you have?

Name clash with "end" symbol

Working with an existing code base, where an extern int end; is declared in one of header files causes ambiguity.

Please describe the steps to reproduce the issue.

int end;
#include <nlohmann/json.hpp>
int main() { return 0; }

What is the expected behavior?

That library uses std::begin/std::end and avoids the ambiguity with other symbols from global namespace.

The issue seem to only appear in line 5094 (json.hpp, single header):

auto input_adapter(const ContainerType& container) -> decltype(input_adapter(begin(container), end(container)))

Following change seems to fix the issue:

auto input_adapter(const ContainerType& container) -> decltype(input_adapter(std::begin(container), std::end(container)))

Which compiler and operating system are you using?

  • Compiler: g++ (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
  • Operating system: Ubuntu 18.04
  • Which version of the library did you use?

  • latest release version 3.9.1
  •