/* * Copyright (c) 2015-present, Facebook, Inc. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. */ #pragma once #include #include namespace facebook { // Class that lets you declare a global but does not add a static constructor // to the binary. Eventually I'd like to have this auto-initialize in a // multithreaded environment but for now it's easiest just to use manual // initialization. template class StaticInitialized { public: constexpr StaticInitialized() : m_instance(nullptr) {} template void initialize(Args&&... arguments) { FBASSERT(!m_instance); m_instance = new T(std::forward(arguments)...); } T* operator->() const { return m_instance; } private: T* m_instance; }; }