[webkit-dev] [webkit-changes] [264332] trunk/Source

Darin Adler darin at apple.com
Tue Jul 14 15:05:56 PDT 2020

> On Jul 14, 2020, at 2:38 PM, Simon Fraser <simon.fraser at 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20200714/c471bc42/attachment.htm>

More information about the webkit-dev mailing list