std::begin ambiguous

begin.cc

#include <boost/range.hpp>
using boost::begin;
using boost::end;

int main()
{
  std::string cipher_name(“aaa");
  int num_items1 = std::count(begin(cipher_name), end(cipher_name), '-');
  return 0;
}

if we don’t use c++11, then

g++ -g begin.cc -o aa

it ok.

But if we use c++11, in the vs2015 or g++4.8

g++ -g -std=c++ begin.cc -o aa

then we will get

 error: call of overloaded 'begin(std::string&)' is ambiguous
    int num_items1 = std::count(begin(cipher_name), end(cipher_name), '-');
    

it is nonsense, we had used namespace boost::begin in the header, why it also use std::begin。 we write this code to compatible boost and std; and this code is very simple ,we don’t use extra things.

so we should read the api document. In the std::being, we notes that

In addition to being included in <iterator>, std::begin is guaranteed to become available 
if any of the following headers are included: <array>, <deque>, <forward_list>, <list>, 
<map>, <regex>, <set>, <string>, <unordered_map>, <unordered_set>, and <vector>.

so if we use std::string, c++11 use std::begin implicitly. How can we solve this problem. we can use __cplusplus to solve this problem.

#if __cplusplus >= 199711L
#include <iterator>
using std::begin;
using std::end;
#else
#include <boost/range.hpp>
using boost::begin;
using boost::end;
#endif

you can use __cplusplus to distinguish c++11.