Are std::fill, std::copy specialized for std::vector<bool>?
STD is headers only library and it is shipped with your compiler. You can look into those headers yourself. For GCC's vector<bool>
impelemtation is in stl_bvector.h
. It probably will be the same file for other compilers too. And yes, there is specialized fill
(look near __fill_bvector
).
Optimizations are nowhere mandated in the standard. It is assumed to be a "quality of implementation" issue if an optimization could applied. The asymptotic complexity of most algorithms is, however, restricted.
Optimizations are allowed as long as a correct program behaves according to what the standard mandates. The examples you ask about, i.e., optimizations involving standard algorithms using iterators on std::vector<bool>
, can achieve their objective pretty much in any way the implementation sees fit because there is no way to monitor how they are implemented. This said, I doubt very much that there is any standard library implementation optimizing operations on std::vector<bool>
. Most people seem to think that this specialization is an abomination in the first place and that it should go away.
A user is only allowed to create specializations of library types if the specialization involves at least one user defined type. I don't think a user is allowed to provide any function in namespace std
at all: There isn't any needs because all such functions would involve a user defined type and would, thus, be found in the user's namespace. Formulated differently: I think you are out of luck with respect to getting algoritms optimized for std::vector<bool>
for the time being. You might consider contributing optimized versions to the open source implementations (e.g., libstdc++
and libc++
), however.