From 602ba5b258e5eae2cbb1cc6ae51d8f5d2e131bbe Mon Sep 17 00:00:00 2001 From: Denis Yaroshevskiy Date: Thu, 18 Jul 2024 06:03:13 -0700 Subject: [PATCH] folly concepts #1 (#2249) Summary: Pull Request resolved: https://github.com/facebook/folly/pull/2249 We have a need for some common concepts that are used in many places. This is a proposal, please let me know what you think. Differential Revision: D59396081 --- folly/Portability.h | 6 ++++++ folly/Traits.h | 33 ++++++++++++++++++++++++++++++++ folly/test/PortabilityTest.cpp | 8 ++++++-- folly/test/TraitsTest.cpp | 35 ++++++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 2 deletions(-) diff --git a/folly/Portability.h b/folly/Portability.h index 8334e2e99ab..8a99b035782 100644 --- a/folly/Portability.h +++ b/folly/Portability.h @@ -606,3 +606,9 @@ constexpr auto kCpplibVer = 0; #else #define FOLLY_CONSTEVAL constexpr #endif + +#if FOLLY_CPLUSPLUS >= 202002L && __has_include() && defined(__cpp_concepts) +#define FOLLY_HAS_CONCEPTS 1 +#else +#define FOLLY_HAS_CONCEPTS 0 +#endif diff --git a/folly/Traits.h b/folly/Traits.h index c79b0fae61d..b8eeaf07e4d 100644 --- a/folly/Traits.h +++ b/folly/Traits.h @@ -25,6 +25,10 @@ #include +#if FOLLY_HAS_CONCEPTS +#include +#endif + namespace folly { #if defined(__cpp_lib_type_identity) && __cpp_lib_type_identity >= 201806L @@ -168,6 +172,8 @@ namespace detail { /// Note that this only works with type template parameters. It does not work /// with non-type template parameters, template template parameters, or alias /// templates. +/// +/// NOTE: there is also `instantiation_of` concept template