Reputation: 19236
According to cppreference.com:
Notes
The specialization
std::vector<bool>
did not haveemplace()
member until C++14.
What does it mean? Can template specialization omit member? Does mean that member function is not present at all? Or is it just not specialized?
Following code seems to work on gcc 7.1.0:
#include <iostream>
#include <vector>
using namespace std;
int main()
{
std::vector<bool> v;
v.emplace_back(true);
v.emplace_back(false);
for (const auto &b : v) {
std::cout << b << std::endl;
}
}
http://coliru.stacked-crooked.com/a/07c8c0fc6050968f
Upvotes: 0
Views: 1089
Reputation: 5589
A template specialization can be completely different from the generic template. So in theory, you cannot know whether the classes A<int>
and A<bool>
have any common members:
template <typename T>
class A
{
public:
void foo()
{}
};
template <>
class A<bool>
{
public:
void bar()
{}
};
int main()
{
A<int> a;
a.foo();
A<bool> b;
b.bar();
b.foo(); // error: 'class A<bool>' has no member named 'foo'
}
The class std::vector<bool>
is a specialized template. Your quote from the standard says that the emplace()
method was missing in that specialization until C++14.
In practice, concrete standard libraries such as libstdc++ may have provided the emplace()
method for std::vector<bool>
even before C++14, but it was not required in the standard.
Upvotes: 3