Are pointers primitive types in C ++?

I was interested to know about the last constructor for the one std::stringmentioned here . It says:

template<class InputIterator> string (InputIterator begin, InputIterator end);

If it InputIteratoris an integral type, it behaves like the sixteenth version of the constructor (the one that is above this), by inputting and starting inputting the type:

string(static_cast<size_t>(begin),static_cast<char>(end));

In any other case, the parameters are taken as iterators, and the content is initialized with the values ​​of the elements that come from the element specified by the iterator, begin with the element immediately before the one indicated at the end of the iterator.

So what does this mean if InputIteratoris char *?

EDIT: Good, my bad. I just realized that in the documentation it contains an integral type, not a primitive type, so the question does not apply to this example. But still, are pointer primitives?

+5
source share
3 answers

C ++ has no concept of "primitive" types; integers are fundamental types, and pointers are composite types.

In this case, char*it cannot be converted to size_tor char, therefore, it will be accepted as a template parameter InputIterator.

+9
source
char * str = "Some string";
std::string s(str, str+6); // s = "Some s";
0
source

C ++ pointers implement the concept of InputIterator well (after all, STL iterators are a generalization of C ++ pointers). Thus, two arguments are considered as pointers to an array of char, denoting the first and one "one end", necessary to initialize the string.

0
source

All Articles