Commit ca91b0ed authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Move FOLLY_DEFINE_CPO to folly/lang/CustomizationPoint.h

Summary:
[Folly] Move `FOLLY_DEFINE_CPO` to `folly/lang/CustomizationPoint.h`.

And move `StaticConst` to top-level `folly` namespace and into `folly/lang/`.

And Americanize the spellings of words in the comments.

Reviewed By: ericniebler, lewissbaker

Differential Revision: D14402315

fbshipit-source-id: e13dbc9d471ee73ba0a289d375c235734334b920
parent 4008ab21
......@@ -457,31 +457,6 @@ constexpr auto kCpplibVer = 0;
#define FOLLY_STORAGE_CONSTEXPR constexpr
#endif
// Helpers for portably defining customisation-point objects (CPOs).
//
// The customisation-point object must be placed in a nested namespace to
// avoid potential conflicts with customisations defined as friend-functions
// of types defined in the same namespace as the CPO.
//
// In C++17 and later we can define the object using 'inline constexpr' to
// avoid ODR issues. However, prior to that we need to use the StaticConst<T>
// helper to ensure that there is only a single instance of the CPO created
// and then we need to put a named reference to this object in an anonymous
// namespace to avoid duplicate symbol definitions.
#if __cpp_inline_variables >= 201606L
#define FOLLY_DEFINE_CPO(Type, Name) \
namespace __hidden { \
inline constexpr Type Name{}; \
} \
using namespace __hidden;
#else
#include <folly/detail/StaticConst.h>
#define FOLLY_DEFINE_CPO(Type, Name) \
namespace { \
constexpr auto& Name = ::folly::detail::StaticConst<Type>::value; \
}
#endif
#if __cpp_coroutines >= 201703L && __has_include(<experimental/coroutine>)
#define FOLLY_HAS_COROUTINES 1
#elif _MSC_VER && _RESUMABLE_FUNCTIONS_SUPPORTED
......
......@@ -25,10 +25,10 @@
#include <folly/Traits.h>
#include <folly/Utility.h>
#include <folly/detail/StaticConst.h>
#include <folly/detail/TypeList.h>
#include <folly/functional/Invoke.h>
#include <folly/lang/Exception.h>
#include <folly/lang/StaticConst.h>
#include <folly/PolyException.h>
......
......@@ -22,6 +22,7 @@
#include <folly/Traits.h>
#include <folly/experimental/coro/Traits.h>
#include <folly/io/async/Request.h>
#include <folly/lang/CustomizationPoint.h>
#include <glog/logging.h>
......
/*
* Copyright 2019-present Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <folly/lang/StaticConst.h>
// FOLLY_DEFINE_CPO
//
// Helper for portably defining customization-point objects (CPOs).
//
// The customization-point object must be placed in a nested namespace to avoid
// potential conflicts with customizations defined as friend-functions of types
// defined in the same namespace as the CPO.
//
// In C++17 and later the object may be defined using 'inline constexpr' to
// avoid ODR issues. However, prior to that a helper template is required to
// ensure that there is only a single instance of the CPO created and then a
// named reference in an anonymous namespace is required to avoid duplicate
// symbol definitions.
#if __cpp_inline_variables >= 201606L
#define FOLLY_DEFINE_CPO(Type, Name) \
namespace folly_cpo__ { \
inline constexpr Type Name{}; \
} \
using namespace folly_cpo__;
#else
#define FOLLY_DEFINE_CPO(Type, Name) \
namespace { \
constexpr auto& Name = ::folly::StaticConst<Type>::value; \
}
#endif
......@@ -17,14 +17,11 @@
#pragma once
namespace folly {
namespace detail {
// The StaticConst<T> class is a helper for defining constexpr objects at
// namespace scope in an ODR-safe and initialisation-order fiasco-safe way
// in C++ versions earlier than C++17.
// StaticConst
//
// For example, see the FOLLY_DEFINE_CPO() macro in folly/Portability.h for
// usage in defining customisation-point objects (CPOs).
// A template for defining ODR-usable constexpr instances. Safe from ODR
// violations and initialization-order problems.
template <typename T>
struct StaticConst {
......@@ -34,5 +31,4 @@ struct StaticConst {
template <typename T>
constexpr T StaticConst<T>::value;
} // namespace detail
} // namespace folly
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment