I'm creating a class that contains an unordered_set with its own hash and predicate as follows:
//SetHolder.h
#include <unordered_set>
struct SetHolder
{
SetHolder(); //Defined in SetHolder.cpp
~SetHolder(); //Defined in SetHolder.cpp
struct ArtifactImpl; //Defined in SetHolder.cpp
struct ArtifactSetKeyOps
{
std::size_t operator()(
const ArtifactImpl& artifact) const noexcept;
bool operator()(
const ArtifactImpl& lhs, const ArtifactImpl& rhs) const;
};
std::unordered_set<ArtifactImpl,
ArtifactSetKeyOps,ArtifactSetKeyOps> artifactSet_;
};
I'm using the gcc 4.8.2 compiler under ubuntu linux (stdlibc++), and I've observed that it compiles when only declaring ArtifactImpl if I only use unordered_set from the cpp file. Yet, I need to provide the definition of ArtifactSetKeyOps (why, I don't understand).
- What requirements does the standard impose on the Value type of
unordered_setin terms of definition visibility at the time of declaringunordered_set? - Is this code supposed to work on all platforms? Also, if so, why does the Hash and the Predicate need to be visible during the declaration of
unordered_set?
Aucun commentaire:
Enregistrer un commentaire