With the concepts of the C ++ 11 and C ++ 14 library, a valid implementation of the standard C ++ library creates a specialized version of a function created on the basis of the concept to take advantage of the additional functionality of the child concept for optimization that would not be possible with a basic concept, for example, with an InputIterator std::vector constructor and iterators that satisfy the requirements of RandomAccessIterator ?
// specified by standard vector(InputIt begin, InputIt end, const Allocator& alloc = Allocator()); // is this specialization allowed in an implementation if it provides the same functionality? vector(RandomAccessIt begin, RandomAccessIt end, const Allocator& alloc = Allocator());
Here, InputIt is a type that meets the requirements of the InputIterator concept, and RandomAccessIt fulfills the requirements of RandomAccessIterator . It is noteworthy that in this concept there is no requirement to find the difference between the two iterators, while the concept of her great-grandmother RandomAccessIterator requires
It a,b; It::difference_type c = a - b;
. Finding the difference between the two iterators would be useful for the InputIterator constructor for std::vector in cases where RandomAccessIterator also a concept performed by the provided iterators, since this would allow the implementation to pre-allocate the necessary space by the final vector, instead of changing it a little times during construction.
I see that this is true, due to the standard random use of as-if rules, for example, with covariant return types for virtual functions in inheritance hierarchies. However, there are fairly clear differences between the situations, so I can also see that the logic of the covariant return types may not necessarily carry over into this situation.
To repeat: can a valid implementation of the C ++ standard library create a specialized version of a function created on the basis of the concept in order to take advantage of the additional functionality of the child concept for optimization that would not be possible only with the basic concept?
Note: I did not mention this question of C ++ concepts , because, as far as I can tell, this tag is for Concepts-Lite and Concepts TS, and this question concerns library concepts in C ++ 11 and C ++ 14
c ++ language-lawyer c ++ 11 c ++ 14
jaggedSpire
source share