mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 03:15:11 +00:00
Bug 1097861 - make CycleCollectionNoteChild more easily forward-declarable; r=mccr8
Forward declaring functions with default arguments is difficult. If you try to say: template<typename T> inline void CycleCollectionNoteChild(nsCycleCollectionTraversalCallback& aCallback, T* aChild, const char* aName, uint32_t aFlags); and then later have: template<typename T> inline void CycleCollectionNoteChild(nsCycleCollectionTraversalCallback& aCallback, T* aChild, const char* aName, uint32_t aFlags = 0); { ... } the compiler complains that default arguments cannot be added to a function template that has already been declared. If you attempt to mollify the compiler by declaring instead: template<typename T> inline void CycleCollectionNoteChild(nsCycleCollectionTraversalCallback& aCallback, T* aChild, const char* aName, uint32_t aFlags = 0); the compiler then complains about redefining the default argument (!) when an actual definition is found. To circumvent this, manually implement "default" arguments by providing a three-argument form of CycleCollectionNoteChild, which simply forwards to the four-argument version.
This commit is contained in:
parent
b2fec0fb4a
commit
e07aa30b4b
@ -78,13 +78,24 @@ struct CycleCollectionNoteChildImpl<T, false>
|
||||
}
|
||||
};
|
||||
|
||||
// We declare CycleCollectionNoteChild in 3-argument and 4-argument variants,
|
||||
// rather than using default arguments, so that forward declarations work
|
||||
// regardless of header inclusion order.
|
||||
template<typename T>
|
||||
inline void
|
||||
CycleCollectionNoteChild(nsCycleCollectionTraversalCallback& aCallback,
|
||||
T* aChild, const char* aName, uint32_t aFlags = 0)
|
||||
T* aChild, const char* aName, uint32_t aFlags)
|
||||
{
|
||||
CycleCollectionNoteEdgeName(aCallback, aName, aFlags);
|
||||
CycleCollectionNoteChildImpl<T>::Run(aCallback, aChild);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void
|
||||
CycleCollectionNoteChild(nsCycleCollectionTraversalCallback& aCallback,
|
||||
T* aChild, const char* aName)
|
||||
{
|
||||
CycleCollectionNoteChild(aCallback, aChild, aName, 0);
|
||||
}
|
||||
|
||||
#endif // nsCycleCollectionNoteChild_h__
|
||||
|
Loading…
Reference in New Issue
Block a user