> On Jul 14, 2020, at 2:38 PM, Simon Fraser <simon.fra...@apple.com> wrote:
> 
> Could someone educate me about <wtf/Forward.h>? When should I use this 
> instead of individual wtf headers?

Forward.h is analogous to forward-declaring a class ('class IntPoint;' instead 
of ‘#include “IntPoint.h”'), but it works for many often-used classes and class 
templates in the WTF namespace, including class templates that would be 
difficult to correctly forward-declare due to their many arguments, such as 
WTF::Vector. And it includes “using WTF::String” and the like, as well, to 
import WTF namespace things into the global namespace.

We can use it any time we need a forward-declaration, not an entire definition, 
of one of the items. For example, to compile a header that just takes and 
returns String objects, we only need a forward declaration of String. The 
easiest way to correctly do that is to include <wtf/Forward.h>. Including 
<wtf/WTFString.h> pulls in a lot more. For the specific case of String, I think 
you might be able to go further and write this instead:

    namespace WTF {
    class String;
    }
    using WTF::String;

But I have never tried it, and there might be some problem with that.

— Darin
_______________________________________________
webkit-dev mailing list
webkit-dev@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-dev

Reply via email to